Print debug chunk if tracing is enabled
This commit is contained in:
parent
252190f5e6
commit
bc99cbfc3b
@ -54,7 +54,7 @@ pub const Chunk = struct {
|
||||
}
|
||||
|
||||
/// Prints the value of a single instruction
|
||||
fn dissasemble_instruction(self: *Chunk, offset: usize) usize {
|
||||
pub fn dissasemble_instruction(self: *Chunk, offset: usize) usize {
|
||||
// Print the instruction offset
|
||||
print("{d:0>4} ", .{offset});
|
||||
|
||||
|
@ -4,6 +4,8 @@ const Chunk = chunk_mod.Chunk;
|
||||
const OpCode = chunk_mod.OpCode;
|
||||
const print = std.debug.print;
|
||||
|
||||
const tracing = @import("config").tracing;
|
||||
|
||||
const InterpretResult = enum {
|
||||
Ok,
|
||||
CompileError,
|
||||
@ -28,6 +30,12 @@ pub const VM = struct {
|
||||
// Executes the instructions in the bytecode
|
||||
pub fn run(self: *VM) InterpretResult {
|
||||
while (true) {
|
||||
if (tracing) {
|
||||
// dissasemble & print the current instruction
|
||||
const offset: usize = @intFromPtr(self.ip) - @intFromPtr(self.chunk.code.ptr);
|
||||
_ = self.chunk.dissasemble_instruction(offset);
|
||||
}
|
||||
|
||||
const next = self.ip[0];
|
||||
self.ip += 1;
|
||||
switch (next) {
|
||||
|
Loading…
Reference in New Issue
Block a user