add basic support for tuples

This commit is contained in:
Neemek 2026-07-11 12:37:15 +02:00
parent 7bb277045c
commit e03d18c7db
Signed by: neemek
GPG key ID: 84FFE4D7D40AB25E
7 changed files with 339 additions and 18 deletions

View file

@ -132,6 +132,10 @@ const (
// InstructionConcatLists concatenate lists, producing a new list with the values of both lists. Pops two lists.
InstructionConcatLists
// InstructionFormTuple pop n+1 (u16) items from the stack, and create a new tuple with the items. The top value
// on the stack is the last value in the tuple.
InstructionFormTuple
// InstructionBreakpoint for debugging purposes
InstructionBreakpoint
)
@ -992,6 +996,18 @@ func (vm *VM) Next() bool {
append(l.Items, r.Items...),
})
case InstructionFormTuple:
n := int(vm.NextU16())
items := make([]Value, n)
for i := n - 1; i >= 0; i-- {
items[i] = vm.Stack.Pop()
}
vm.Stack.Push(&TupleValue{
items,
})
case InstructionDescend:
vm.descend()