This commit is contained in:
Andre Wagner
2026-05-06 12:00:53 -05:00
parent 7ecffcfdda
commit 8f851a330e
3 changed files with 8 additions and 8 deletions

View File

@@ -5,9 +5,9 @@ Progress of the Lua port:
- [x] Logic/arithmetic expressions - [x] Logic/arithmetic expressions
- [x] Variables - [x] Variables
- [x] Local variables - [x] Local variables
- [ ] Functions - [x] Functions
- [ ] Calling functions - [x] Calling functions
- [ ] Calling functions with parameters - [x] Calling functions with parameters
- [ ] Control flow - [ ] Control flow
- [ ] Lablels in Assembly - [ ] Lablels in Assembly
- [ ] Recursion - [ ] Recursion

View File

@@ -198,7 +198,7 @@ do TEST("VM: local variables")
end end
do TEST("VM: functions") do TEST("VM: functions")
local vm = VM:new():set_debug(true):load(assemble([[ local vm = VM:new():load(assemble([[
.func 0 .func 0
pushf 1 pushf 1
pushi 2 pushi 2
@@ -208,12 +208,12 @@ do TEST("VM: functions")
.func 1 .func 1
dupv 0 dupv 0
dupv 1 dupv 1
sum sub
ret ret
]])):call(0) ]])):call(0)
assert_eq(vm:stack_sz(), 1) assert_eq(vm:stack_sz(), 1)
assert_eq(vm:to_integer(-1), 5) assert_eq(vm:to_integer(-1), -1)
end end
print('End.') print('End.')

View File

@@ -340,11 +340,11 @@ function VM:_step()
elseif op.operator == 'set' then elseif op.operator == 'set' then
assert(op.operand >= 0) assert(op.operand >= 0)
local a = self.stack:pop() local a = self.stack:pop()
self.stack[op.operand + 1] = a self.stack[op.operand] = a
elseif op.operator == 'dupv' then elseif op.operator == 'dupv' then
assert(op.operand >= 0) assert(op.operand >= 0)
local a = self.stack[op.operand + 1] local a = self.stack[op.operand]
self.stack:push(a) self.stack:push(a)
-- --