diff options
author | Mathias Magnusson <mathias@magnusson.space> | 2025-06-04 01:12:01 +0200 |
---|---|---|
committer | Mathias Magnusson <mathias@magnusson.space> | 2025-06-04 01:12:01 +0200 |
commit | 55f45123f21e63e883d0afe16d97dcb5dafdd296 (patch) | |
tree | 657052d329915f76e4bf302b8c4c44a781582a41 /src/main.zig | |
parent | 8a9d15683101ab1ea8584f3d5595e5319d7b9a24 (diff) | |
download | huginn-55f45123f21e63e883d0afe16d97dcb5dafdd296.tar.gz |
begin implementing if expressions
registers are used over block boundaries though, which doesn't work very
well so i turned off register freeing to make it look like it works
(unless you create more than 12 values total)
Diffstat (limited to 'src/main.zig')
-rw-r--r-- | src/main.zig | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/src/main.zig b/src/main.zig index 7af0885..48637c2 100644 --- a/src/main.zig +++ b/src/main.zig @@ -38,11 +38,13 @@ pub fn main() !void { const source = \\{ - \\ let x = 69 - \\ { - \\ # let x = read_int(0) - \\ print(18446744073709551615) - \\ print(x + x) + \\ let x = 10 + \\ if x { + \\ let x = read_int(0) + \\ # print(18446744073709551615) + \\ # print(x + x) + \\ } else { + \\ print(10) \\ } \\ print(x) \\} @@ -60,13 +62,16 @@ pub fn main() !void { if (lexer.peek().type != .eof) { std.debug.print("Unexpected token {}, expected end of file\n", .{lexer.next()}); } - const block = try compile.compile(allocator, source, ast); + const procedure = try compile.compile(allocator, source, ast); std.debug.print("Bytecode instructions:\n", .{}); - for (block.instrs) |instr| { - std.debug.print(" {}\n", .{instr}); + for (procedure.blocks, 0..) |block, i| { + std.debug.print(" ${}:\n", .{i}); + for (block.instrs.items) |instr| { + std.debug.print(" {}\n", .{instr}); + } } - std.debug.print("Last use of each virtual register: {}\n", .{fmtHashMap(block.vreg_last_use)}); - const elf = try codegen.create_elf(allocator, block); + // std.debug.print("Last use of each virtual register: {}\n", .{fmtHashMap(block.vreg_last_use)}); + const elf = try codegen.create_elf(allocator, procedure); try output.writeAll(elf); std.debug.print("Run output:\n", .{}); if (run) { |