This commit is contained in:
Andre Wagner
2026-05-05 09:54:42 -05:00
parent 8614f978ea
commit 60c55304b2
2 changed files with 6 additions and 1 deletions

View File

@@ -123,6 +123,7 @@ end
do
local vm = VM:new()
vm.debug = true
local bytecode = assemble [[
.func 0
pushi 2

View File

@@ -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