.
This commit is contained in:
@@ -123,6 +123,7 @@ end
|
|||||||
|
|
||||||
do
|
do
|
||||||
local vm = VM:new()
|
local vm = VM:new()
|
||||||
|
vm.debug = true
|
||||||
local bytecode = assemble [[
|
local bytecode = assemble [[
|
||||||
.func 0
|
.func 0
|
||||||
pushi 2
|
pushi 2
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ function VM.new()
|
|||||||
stack = Stack.new(),
|
stack = Stack.new(),
|
||||||
code = Code.new(),
|
code = Code.new(),
|
||||||
loc = {},
|
loc = {},
|
||||||
|
debug = false,
|
||||||
}, VM)
|
}, VM)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -200,7 +201,8 @@ end
|
|||||||
function VM:_step()
|
function VM:_step()
|
||||||
local loc = self.loc[#self.loc]
|
local loc = self.loc[#self.loc]
|
||||||
local op = self.code:next_instruction(loc.f_id, loc.pc)
|
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
|
if op.operator == 'pushi' then
|
||||||
self:push_integer(op.operand)
|
self:push_integer(op.operand)
|
||||||
@@ -215,6 +217,8 @@ function VM:_step()
|
|||||||
error("Unknown operator '" .. tostring(op.operator) .. "'")
|
error("Unknown operator '" .. tostring(op.operator) .. "'")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if self.debug then print(self.stack:debug()) end
|
||||||
|
|
||||||
loc.pc = loc.pc + op.instruction_size
|
loc.pc = loc.pc + op.instruction_size
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user