Print some arguments

This commit is contained in:
David Gonzalez Martin 2024-04-11 07:53:04 -06:00
parent 995b73ec08
commit 5473d1c5a9
4 changed files with 34 additions and 24 deletions

View File

@ -22,29 +22,6 @@ fn todo() noreturn {
} }
var my_allocator = PageAllocator{}; var my_allocator = PageAllocator{};
// pub export fn main(c_argc: c_int, c_argv: [*][*:0]c_char, c_envp: [*:null]?[*:0]c_char) callconv(.C) c_int {
// _ = c_envp; // autofix
// // const argument_count: usize = @intCast(c_argc);
// // const argument_values: [*][*:0]u8 = @ptrCast(c_argv);
// if (entry_point(arguments)) |_| {
// return 0;
// } else |err| {
// const print_stack_trace = @import("configuration").print_stack_trace;
// switch (print_stack_trace) {
// true => if (@errorReturnTrace()) |trace| {
// std.debug.dumpStackTrace(trace.*);
// },
// false => {
// const error_name: []const u8 = @errorName(err);
// Compilation.write(.panic, "Error: ") catch {};
// Compilation.write(.panic, error_name) catch {};
// Compilation.write(.panic, "\n") catch {};
// },
// }
//
// return 1;
// }
// }
pub fn main() !void { pub fn main() !void {
var arena_allocator = std.heap.ArenaAllocator.init(std.heap.page_allocator); var arena_allocator = std.heap.ArenaAllocator.init(std.heap.page_allocator);

View File

@ -515,7 +515,18 @@ fn compile_self_hosted(allocator: Allocator, args: struct {
.Unknown => error.unknown, .Unknown => error.unknown,
}; };
_ = try compilation_result;
_ = compilation_result catch |err| {
std.debug.print("Compiling the self-hosted compiler failed!\n", .{});
if (compile_run.stdout.len > 0) {
std.debug.print("{s}\n", .{compile_run.stdout});
}
if (compile_run.stderr.len > 0) {
std.debug.print("{s}\n", .{compile_run.stderr});
}
return err;
};
} }
fn run_test_suite(allocator: Allocator, args: struct { fn run_test_suite(allocator: Allocator, args: struct {

View File

@ -156,6 +156,15 @@ const copy_bytes = fn(destination: []u8, source: []const u8) void {
} }
} }
const c_len = fn (string: [&:0]const u8) usize {
var i: usize = 0;
while (string[i] != 0) {
i += 1;
}
return i;
}
const Target = struct { const Target = struct {
cpu: builtin.Cpu, cpu: builtin.Cpu,
os: builtin.Os, os: builtin.Os,

View File

@ -1,4 +1,17 @@
const std = #import("std"); const std = #import("std");
const Arena = std.Arena;
const main = fn() *!void { const main = fn() *!void {
const arena = try Arena.allocate(std.megabytes(64));
const argument_count = std.start.argument_count;
const argument_values = std.start.argument_values;
const arguments = argument_values[0..argument_count];
for (arguments) |c_argument| {
const argument_len = std.c_len(c_argument);
const argument = c_argument[0..argument_len];
std.print("Argument: ");
std.print(argument);
std.print("\n");
}
} }