diff options
| author | Marc Vertes <mvertes@free.fr> | 2023-11-20 11:00:51 +0100 |
|---|---|---|
| committer | Marc Vertes <mvertes@free.fr> | 2023-11-20 11:00:51 +0100 |
| commit | 001ca51323a1a54c9b3db377f0783c330666c480 (patch) | |
| tree | 7779e6b0c453f9f38bd5a24201011475f2b1f53a /vm/vm.go | |
| parent | ee21c324ce8c41b589e5a39e5715223ffd154315 (diff) | |
parser: add support for slices and arrays, parse index expressions
Diffstat (limited to 'vm/vm.go')
| -rw-r--r-- | vm/vm.go | 5 |
1 files changed, 5 insertions, 0 deletions
@@ -28,6 +28,7 @@ const ( Field // s -- f ; f = s.FieldIndex($1, ...) Greater // n1 n2 -- cond; cond = n1 > n2 Grow // -- ; sp += $1 + Index // a i -- a[i] ; Jump // -- ; ip += $1 JumpTrue // cond -- ; if cond { ip += $1 } JumpFalse // cond -- ; if cond { ip += $1 } @@ -59,6 +60,7 @@ var strop = [...]string{ // for VM tracing. Field: "Field", Greater: "Greater", Grow: "Grow", + Index: "Index", Jump: "Jump", JumpTrue: "JumpTrue", JumpFalse: "JumpFalse", @@ -225,6 +227,9 @@ func (m *Machine) Run() (err error) { mem = mem[:sp-1] case Subi: mem[sp-1] = mem[sp-1].(int) - int(op[2]) + case Index: + mem[sp-2] = mem[sp-1].(reflect.Value).Index(mem[sp-2].(int)) + mem = mem[:sp-1] case Vassign: mem[sp-1].(reflect.Value).Set(reflect.ValueOf(mem[sp-2])) mem = mem[:sp-2] |
