From 3ecbe5ca9d6612f3ec05b885afd095b079ca909d Mon Sep 17 00:00:00 2001 From: Patrick MARIE Date: Sun, 1 Sep 2024 13:39:15 +0200 Subject: [PATCH] improve disassemble --- src/chunk.zig | 6 +++--- src/compile.zig | 8 +++++++- src/vm.zig | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/chunk.zig b/src/chunk.zig index 476b63f..f744cfc 100644 --- a/src/chunk.zig +++ b/src/chunk.zig @@ -73,18 +73,18 @@ pub const Chunk = struct { debug.print("== end of chunk dump \n\n", .{}); } - pub fn dissassemble(self: Chunk, name: []const u8) void { + pub fn disassemble(self: Chunk, name: []const u8) void { debug.print("== {s} ==\n", .{name}); var offset: usize = 0; while (offset < self.count) { - offset = self.dissassemble_instruction(offset); + offset = self.disassemble_instruction(offset); } debug.print("== end of {s} ==\n\n", .{name}); } - pub fn dissassemble_instruction(self: Chunk, offset: usize) usize { + pub fn disassemble_instruction(self: Chunk, offset: usize) usize { var current_offset = offset; debug.print("{d:0>4} ", .{offset}); diff --git a/src/compile.zig b/src/compile.zig index fdece35..3be1f1f 100644 --- a/src/compile.zig +++ b/src/compile.zig @@ -158,8 +158,14 @@ pub const Parser = struct { fn end_parser(self: *Parser) !*Obj.Function { try self.emit_return(); + const compiler_function = self.compiler.function; + if (!self.had_error and constants.DEBUG_PRINT_CODE) { - self.current_chunk().dissassemble("code"); + var label: []const u8 = "