diff --git a/lua-temp/tests.lua b/lua-temp/tests.lua index 99b633f..130a9c0 100644 --- a/lua-temp/tests.lua +++ b/lua-temp/tests.lua @@ -123,6 +123,7 @@ end do local vm = VM:new() + vm.debug = true local bytecode = assemble [[ .func 0 pushi 2 diff --git a/lua-temp/tyche-vm.lua b/lua-temp/tyche-vm.lua index d3d6c8d..909b474 100644 --- a/lua-temp/tyche-vm.lua +++ b/lua-temp/tyche-vm.lua @@ -134,6 +134,7 @@ function VM.new() stack = Stack.new(), code = Code.new(), loc = {}, + debug = false, }, VM) end @@ -200,7 +201,8 @@ end function VM:_step() local loc = self.loc[#self.loc] local op = self.code:next_instruction(loc.f_id, loc.pc) - print(loc.f_id .. ':' .. loc.pc .. ' ' .. op.operator .. ' ' .. (op.operand and op.operand or '')) + + if self.debug then print('## ' .. loc.f_id .. ':' .. loc.pc .. ' ' .. op.operator .. ' ' .. (op.operand and op.operand or '')) end if op.operator == 'pushi' then self:push_integer(op.operand) @@ -215,6 +217,8 @@ function VM:_step() error("Unknown operator '" .. tostring(op.operator) .. "'") end + if self.debug then print(self.stack:debug()) end + loc.pc = loc.pc + op.instruction_size end