summaryrefslogtreecommitdiff
path: root/vm
diff options
context:
space:
mode:
authorMarc Vertes <mvertes@free.fr>2026-01-27 16:37:02 +0100
committerMarc Vertes <mvertes@free.fr>2026-01-27 16:37:02 +0100
commit60f6ebc8d8369721e105d826145af2b8856ac67e (patch)
tree002073b75edc68aba95399db89f50b24ebb6935f /vm
parentaa5861917ac2543f85bf4cfefbb69cf501d4de41 (diff)
fix: improve multiple define
The VM Vassign instruction now takes an argument to indicates the number of assignations to perform on the stack. Definitions with a function returning multiple values now work. There is still some simplifications, and also to apply the same strategy to var declarations with assign.
Diffstat (limited to 'vm')
-rw-r--r--vm/vm.go9
1 files changed, 7 insertions, 2 deletions
diff --git a/vm/vm.go b/vm/vm.go
index f5bb78e..96d61eb 100644
--- a/vm/vm.go
+++ b/vm/vm.go
@@ -311,8 +311,13 @@ func (m *Machine) Run() (err error) {
mem[sp-3].SetMapIndex(mem[sp-2].Value, mem[sp-1].Value)
mem = mem[:sp-2]
case Vassign:
- mem[sp-2].Set(mem[sp-1].Value)
- mem = mem[:sp-2]
+ n := c.Arg[0]
+ for i := 0; i < n; i++ {
+ mem[sp-n-i-1].Set(mem[sp-n+i].Value)
+ }
+ mem = mem[:sp-n-1]
+ // mem[sp-2].Set(mem[sp-1].Value)
+ // mem = mem[:sp-2]
}
ip++
}