improve disassemble
This commit is contained in:
		@@ -73,18 +73,18 @@ pub const Chunk = struct {
 | 
				
			|||||||
        debug.print("== end of chunk dump \n\n", .{});
 | 
					        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});
 | 
					        debug.print("== {s} ==\n", .{name});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        var offset: usize = 0;
 | 
					        var offset: usize = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        while (offset < self.count) {
 | 
					        while (offset < self.count) {
 | 
				
			||||||
            offset = self.dissassemble_instruction(offset);
 | 
					            offset = self.disassemble_instruction(offset);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        debug.print("== end of {s} ==\n\n", .{name});
 | 
					        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;
 | 
					        var current_offset = offset;
 | 
				
			||||||
        debug.print("{d:0>4} ", .{offset});
 | 
					        debug.print("{d:0>4} ", .{offset});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -158,8 +158,14 @@ pub const Parser = struct {
 | 
				
			|||||||
    fn end_parser(self: *Parser) !*Obj.Function {
 | 
					    fn end_parser(self: *Parser) !*Obj.Function {
 | 
				
			||||||
        try self.emit_return();
 | 
					        try self.emit_return();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const compiler_function = self.compiler.function;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!self.had_error and constants.DEBUG_PRINT_CODE) {
 | 
					        if (!self.had_error and constants.DEBUG_PRINT_CODE) {
 | 
				
			||||||
            self.current_chunk().dissassemble("code");
 | 
					            var label: []const u8 = "<script>";
 | 
				
			||||||
 | 
					            if (compiler_function.name != null) {
 | 
				
			||||||
 | 
					                label = compiler_function.name.?.chars;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            self.current_chunk().disassemble(label);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const function_obj = self.compiler.function;
 | 
					        const function_obj = self.compiler.function;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -156,7 +156,7 @@ pub const VM = struct {
 | 
				
			|||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    debug.print("\n", .{});
 | 
					                    debug.print("\n", .{});
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                _ = self.current_chunk().dissassemble_instruction(self.current_frame().ip);
 | 
					                _ = self.current_chunk().disassemble_instruction(self.current_frame().ip);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            const instruction = self.read_byte();
 | 
					            const instruction = self.read_byte();
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user