summaryrefslogtreecommitdiff
path: root/vm/vm.go
diff options
context:
space:
mode:
authorMarc Vertes <mvertes@free.fr>2026-01-11 19:02:27 +0100
committerMarc Vertes <mvertes@free.fr>2026-01-11 19:02:27 +0100
commit5a04b5512a128bd1805792cca4eabacf5fd49b27 (patch)
treea9d4fa09d14bc2b1e17ea2ff14878f556ed41536 /vm/vm.go
parent7520aa4474ea30985cf26631c6bbdebf38484a0d (diff)
fix: handle assign statements on map elements
A new token MapAssign is added to implement assignements involving a map, slice or array, an index key expression and a value expression.
Diffstat (limited to 'vm/vm.go')
-rw-r--r--vm/vm.go4
1 files changed, 4 insertions, 0 deletions
diff --git a/vm/vm.go b/vm/vm.go
index 709b459..2baf384 100644
--- a/vm/vm.go
+++ b/vm/vm.go
@@ -42,6 +42,7 @@ const (
Grow // -- ; sp += $1
Index // a i -- a[i] ;
IndexSet // a i v -- a; a[i] = v
+ MapIndex // a i -- a[i]
MapSet // a i v -- a; a[i] = v
Jump // -- ; ip += $1
JumpTrue // cond -- ; if cond { ip += $1 }
@@ -267,6 +268,9 @@ func (m *Machine) Run() (err error) {
case IndexSet:
mem[sp-3].Value.Index(int(mem[sp-2].Int())).Set(mem[sp-1].Value)
mem = mem[:sp-2]
+ case MapIndex:
+ mem[sp-2].Value = mem[sp-2].MapIndex(mem[sp-1].Value)
+ mem = mem[:sp-1]
case MapSet:
mem[sp-3].SetMapIndex(mem[sp-2].Value, mem[sp-1].Value)
mem = mem[:sp-2]