diff options
| author | Marc Vertes <mvertes@free.fr> | 2026-01-11 19:02:27 +0100 |
|---|---|---|
| committer | Marc Vertes <mvertes@free.fr> | 2026-01-11 19:02:27 +0100 |
| commit | 5a04b5512a128bd1805792cca4eabacf5fd49b27 (patch) | |
| tree | a9d4fa09d14bc2b1e17ea2ff14878f556ed41536 /vm | |
| parent | 7520aa4474ea30985cf26631c6bbdebf38484a0d (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')
| -rw-r--r-- | vm/op_string.go | 41 | ||||
| -rw-r--r-- | vm/vm.go | 4 |
2 files changed, 25 insertions, 20 deletions
diff --git a/vm/op_string.go b/vm/op_string.go index e5a00b6..e838628 100644 --- a/vm/op_string.go +++ b/vm/op_string.go @@ -31,29 +31,30 @@ func _() { _ = x[Grow-20] _ = x[Index-21] _ = x[IndexSet-22] - _ = x[MapSet-23] - _ = x[Jump-24] - _ = x[JumpTrue-25] - _ = x[JumpFalse-26] - _ = x[JumpSetTrue-27] - _ = x[JumpSetFalse-28] - _ = x[Lower-29] - _ = x[Loweri-30] - _ = x[Mul-31] - _ = x[New-32] - _ = x[Negate-33] - _ = x[Not-34] - _ = x[Pop-35] - _ = x[Push-36] - _ = x[Return-37] - _ = x[Sub-38] - _ = x[Subi-39] - _ = x[Swap-40] + _ = x[MapIndex-23] + _ = x[MapSet-24] + _ = x[Jump-25] + _ = x[JumpTrue-26] + _ = x[JumpFalse-27] + _ = x[JumpSetTrue-28] + _ = x[JumpSetFalse-29] + _ = x[Lower-30] + _ = x[Loweri-31] + _ = x[Mul-32] + _ = x[New-33] + _ = x[Negate-34] + _ = x[Not-35] + _ = x[Pop-36] + _ = x[Push-37] + _ = x[Return-38] + _ = x[Sub-39] + _ = x[Subi-40] + _ = x[Swap-41] } -const _Op_name = "NopAddAddrAssignFassignVassignCallCalliCallXDerefDupFdupFnewEqualEqualSetExitFieldFieldSetFieldFsetGreaterGrowIndexIndexSetMapSetJumpJumpTrueJumpFalseJumpSetTrueJumpSetFalseLowerLoweriMulNewNegateNotPopPushReturnSubSubiSwap" +const _Op_name = "NopAddAddrAssignFassignVassignCallCalliCallXDerefDupFdupFnewEqualEqualSetExitFieldFieldSetFieldFsetGreaterGrowIndexIndexSetMapIndexMapSetJumpJumpTrueJumpFalseJumpSetTrueJumpSetFalseLowerLoweriMulNewNegateNotPopPushReturnSubSubiSwap" -var _Op_index = [...]uint8{0, 3, 6, 10, 16, 23, 30, 34, 39, 44, 49, 52, 56, 60, 65, 73, 77, 82, 90, 99, 106, 110, 115, 123, 129, 133, 141, 150, 161, 173, 178, 184, 187, 190, 196, 199, 202, 206, 212, 215, 219, 223} +var _Op_index = [...]uint8{0, 3, 6, 10, 16, 23, 30, 34, 39, 44, 49, 52, 56, 60, 65, 73, 77, 82, 90, 99, 106, 110, 115, 123, 131, 137, 141, 149, 158, 169, 181, 186, 192, 195, 198, 204, 207, 210, 214, 220, 223, 227, 231} func (i Op) String() string { idx := int(i) - 0 @@ -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] |
