This commit is contained in:
2026-05-09 11:34:51 -05:00
parent 8a26ba5351
commit 554a7b55c5
2 changed files with 27 additions and 11 deletions

View File

@@ -45,12 +45,12 @@ Function operations:
Table and array operations:
16 getkv Get table's value based on key (pull 1 value, push 1 value)
17 setkv Set table's key and value (pull 2 values from stack)
18 geta Get array's position value
19 seta Set array's position value (pull 2 values from stack)
1a appnd Add value to the end of array
1b next Push the next pair into the stack (for loops)
1c smt Set value metatable
1d mt Get value metatable
a8 c8 e8 geta Get array's position value
a9 c9 e9 seta Set array's position value
18 appnd Add value to the end of array
19 next Push the next pair into the stack (for loops)
1a smt Set value metatable
1b mt Get value metatable
Logical/arithmetic:
20 sum Sum top 2 values in stack
@@ -75,7 +75,7 @@ Logical/arithmetic:
Other value operations:
40 len Get table, array or string size
41 type Get type from value at the top of the stack
b0 cast [type] Cast type to another type
aa cast [type] Cast type to another type
42 ver Return VM version
External code:
@@ -84,9 +84,9 @@ External code:
4a load Load bytecode as function (will place function on stack)
Control flow (the destination is always a 16-bit field):
c8 bz [pc] Branch if zero
c9 bnz [pc] Branch if not zero
ca jmp [pc] Unconditional jump
ca bz [pc] Branch if zero
cb bnz [pc] Branch if not zero
cc jmp [pc] Unconditional jump
* Jumps can only happen within the same function.
Memory management:

View File

@@ -340,7 +340,23 @@ do TEST "VM: GC strings"
assert_eq(vm.heap:size(), 0)
end
-- TODO - collect string (GC)
do TEST "VM: arrays"
local vm = VM.new():set_debug(true):load(assemble [
.func 0
newa
pushi 10
seta 0
pushi 20
seta 1
pushi 30
seta 2
geta 1
]):call(0)
print(vm:debug_heap())
assert_eq(vm:to_integer(-1), 20)
assert_eq(vm:is(-2, 'array'), true)
assert_eq(vm.heap:size(), 1)
end
print('End.')