summaryrefslogtreecommitdiff
path: root/vm1/vm.go
diff options
context:
space:
mode:
authorMarc Vertes <mvertes@free.fr>2023-08-29 18:22:13 +0200
committerMarc Vertes <mvertes@free.fr>2023-08-29 18:22:13 +0200
commit0f4bfe6e70263fbeb580014b62632f403b29b414 (patch)
treede750b60a6c0027b36accf9f0596c3e651309cda /vm1/vm.go
parenta3ab9ef5be74cb54a87674aa48abb0c46f9c58f6 (diff)
gint: add an interactive REPL
Diffstat (limited to 'vm1/vm.go')
-rw-r--r--vm1/vm.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/vm1/vm.go b/vm1/vm.go
index f7113f2..c2f4882 100644
--- a/vm1/vm.go
+++ b/vm1/vm.go
@@ -6,7 +6,7 @@ import (
"strconv" // for tracing only
)
-const debug = false
+const debug = true
// Byte-code instruction set.
const (
@@ -155,7 +155,7 @@ func (m *Machine) Run() (err error) {
}
}
-func (m *Machine) PushCode(code [][]int64) (p int) {
+func (m *Machine) PushCode(code ...[]int64) (p int) {
p = len(m.code)
m.code = append(m.code, code...)
return p
@@ -165,6 +165,12 @@ func (m *Machine) SetIP(ip int) { m.ip = ip }
func (m *Machine) Push(v ...any) (l int) { l = len(m.mem); m.mem = append(m.mem, v...); return }
func (m *Machine) Pop() (v any) { l := len(m.mem) - 1; v = m.mem[l]; m.mem = m.mem[:l]; return }
+func (m *Machine) PopExit() {
+ if l := len(m.code); l > 0 && m.code[l-1][1] == Exit {
+ m.code = m.code[:l-1]
+ }
+}
+
// Disassemble returns the code as a readable string.
func Disassemble(code [][]int64) (asm string) {
for _, op := range code {