summaryrefslogtreecommitdiff
path: root/vm/vm.go
diff options
context:
space:
mode:
authorMarc Vertes <mvertes@free.fr>2023-11-10 23:00:20 +0100
committerMarc Vertes <mvertes@free.fr>2023-11-10 23:00:20 +0100
commit1977ce7c976cbbd5bd0de1d479a0abe269e62f3d (patch)
treed0252db9117692c698af53e44e6b0d3f447a0eb1 /vm/vm.go
parentbec71a19e7d7cd0847d1cfa6ef2110d7301fcdd1 (diff)
vm: add Grow instruction to increase stack
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 6f2df12..ba1f97e 100644
--- a/vm/vm.go
+++ b/vm/vm.go
@@ -25,6 +25,7 @@ const (
EqualSet // n1 n2 -- n1 cond ; cond = n1 == n2
Exit // -- ;
Greater // n1 n2 -- cond; cond = n1 > n2
+ Grow // -- ; sp += $1
Jump // -- ; ip += $1
JumpTrue // cond -- ; if cond { ip += $1 }
JumpFalse // cond -- ; if cond { ip += $1 }
@@ -54,6 +55,7 @@ var strop = [...]string{ // for VM tracing.
Fassign: "Fassign",
Fdup: "Fdup",
Greater: "Greater",
+ Grow: "Grow",
Jump: "Jump",
JumpTrue: "JumpTrue",
JumpFalse: "JumpFalse",
@@ -202,6 +204,8 @@ func (m *Machine) Run() (err error) {
mem = mem[:sp-int(op[2])]
case Push:
mem = append(mem, int(op[2]))
+ case Grow:
+ mem = append(mem, make([]any, op[2])...)
case Return:
ip = mem[fp-2].(int)
ofp := fp