From 8f851a330eb8abf31f83c6657383ac526add36f2 Mon Sep 17 00:00:00 2001 From: Andre Wagner Date: Wed, 6 May 2026 12:00:53 -0500 Subject: [PATCH] . --- lua-temp/TODO.md | 6 +++--- lua-temp/tests.lua | 6 +++--- lua-temp/tyche-vm.lua | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lua-temp/TODO.md b/lua-temp/TODO.md index 283a45c..1fa0c36 100644 --- a/lua-temp/TODO.md +++ b/lua-temp/TODO.md @@ -5,9 +5,9 @@ Progress of the Lua port: - [x] Logic/arithmetic expressions - [x] Variables - [x] Local variables -- [ ] Functions - - [ ] Calling functions - - [ ] Calling functions with parameters +- [x] Functions + - [x] Calling functions + - [x] Calling functions with parameters - [ ] Control flow - [ ] Lablels in Assembly - [ ] Recursion diff --git a/lua-temp/tests.lua b/lua-temp/tests.lua index 7476687..0af4028 100644 --- a/lua-temp/tests.lua +++ b/lua-temp/tests.lua @@ -198,7 +198,7 @@ do TEST("VM: local variables") end do TEST("VM: functions") - local vm = VM:new():set_debug(true):load(assemble([[ + local vm = VM:new():load(assemble([[ .func 0 pushf 1 pushi 2 @@ -208,12 +208,12 @@ do TEST("VM: functions") .func 1 dupv 0 dupv 1 - sum + sub ret ]])):call(0) assert_eq(vm:stack_sz(), 1) - assert_eq(vm:to_integer(-1), 5) + assert_eq(vm:to_integer(-1), -1) end print('End.') \ No newline at end of file diff --git a/lua-temp/tyche-vm.lua b/lua-temp/tyche-vm.lua index a6a014f..aa7cebf 100644 --- a/lua-temp/tyche-vm.lua +++ b/lua-temp/tyche-vm.lua @@ -340,11 +340,11 @@ function VM:_step() elseif op.operator == 'set' then assert(op.operand >= 0) local a = self.stack:pop() - self.stack[op.operand + 1] = a + self.stack[op.operand] = a elseif op.operator == 'dupv' then assert(op.operand >= 0) - local a = self.stack[op.operand + 1] + local a = self.stack[op.operand] self.stack:push(a) --