summaryrefslogtreecommitdiff
path: root/vm0
diff options
context:
space:
mode:
authorMarc Vertes <mvertes@free.fr>2023-08-31 17:53:54 +0200
committerMarc Vertes <mvertes@free.fr>2023-08-31 17:53:54 +0200
commit851c793da43be9e4d3319afe440d603c85834045 (patch)
treefd4b3d3812f5743213b5849858c459c8196dbf7f /vm0
parent0f4bfe6e70263fbeb580014b62632f403b29b414 (diff)
codegen: fix interpreter re-entrance
So multiple successive incremental Evals function correctly. Also improve the following: - Apply the same Eval API to vm0 and vm1 - parser: dot diagram display is now synchronous - codegen: outsource complex code generation for readability - vm1: Pop take the number of values to pop as operand
Diffstat (limited to 'vm0')
-rw-r--r--vm0/func.go2
-rw-r--r--vm0/vm.go8
-rw-r--r--vm0/vm_test.go4
3 files changed, 7 insertions, 7 deletions
diff --git a/vm0/func.go b/vm0/func.go
index 6976530..ee503bc 100644
--- a/vm0/func.go
+++ b/vm0/func.go
@@ -60,7 +60,7 @@ func (i *Interp) declareFunc(r *parser.Node, scope string) {
for _, arg := range args {
i.push(arg.Interface())
}
- if _, err := i.Run(r.Child[len(r.Child)-1], fscope); err != nil {
+ if err := i.Run(r.Child[len(r.Child)-1], fscope); err != nil {
panic(err)
}
b := len(i.stack) - len(out)
diff --git a/vm0/vm.go b/vm0/vm.go
index 8d0b49e..e26e20f 100644
--- a/vm0/vm.go
+++ b/vm0/vm.go
@@ -23,7 +23,7 @@ func New(p *parser.Parser) (i *Interp) {
return i
}
-func (i *Interp) Eval(src string) (err error) {
+func (i *Interp) Eval(src string) (res any, err error) {
n := &parser.Node{}
if n.Child, err = i.Parse(src); err != nil {
return
@@ -32,7 +32,7 @@ func (i *Interp) Eval(src string) (err error) {
n.Dot(os.Getenv("DOT"), "")
}
for _, nod := range n.Child {
- if _, err = i.Run(nod, ""); err != nil {
+ if err = i.Run(nod, ""); err != nil {
break
}
}
@@ -40,7 +40,7 @@ func (i *Interp) Eval(src string) (err error) {
}
// Run implements a stack based virtual machine which directly walks the AST.
-func (i *Interp) Run(node *parser.Node, scope string) (res []any, err error) {
+func (i *Interp) Run(node *parser.Node, scope string) (err error) {
stop := false
node.Walk2(nil, 0, func(n, a *parser.Node, k int) (ok bool) {
@@ -129,7 +129,7 @@ func (i *Interp) Run(node *parser.Node, scope string) (res []any, err error) {
}
return true
})
- return nil, nil
+ return nil
}
// getSym searches for an existing symbol starting from the deepest scope.
diff --git a/vm0/vm_test.go b/vm0/vm_test.go
index 0e8896b..dc0829b 100644
--- a/vm0/vm_test.go
+++ b/vm0/vm_test.go
@@ -20,7 +20,7 @@ func TestEval(t *testing.T) {
}
i.Adot(nodes, os.Getenv("DOT"))
for _, n := range nodes {
- v, err := i.Run(n, "")
- t.Log(v, err)
+ err := i.Run(n, "")
+ t.Log(err)
}
}