summaryrefslogtreecommitdiff
path: root/codegen/compiler_test.go
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 /codegen/compiler_test.go
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 'codegen/compiler_test.go')
-rw-r--r--codegen/compiler_test.go8
1 files changed, 4 insertions, 4 deletions
diff --git a/codegen/compiler_test.go b/codegen/compiler_test.go
index 5989210..a876d52 100644
--- a/codegen/compiler_test.go
+++ b/codegen/compiler_test.go
@@ -16,7 +16,7 @@ func TestCodeGen(t *testing.T) {
test := test
t.Run("", func(t *testing.T) {
c := NewCompiler()
- c.AddSym(fmt.Println, "println", false)
+ c.AddSym(fmt.Println, "println")
n := &parser.Node{}
var err error
if n.Child, err = golang.GoParser.Parse(test.src); err != nil {
@@ -45,13 +45,13 @@ var tests = []struct {
asm: "Push 1\nPush 2\nAdd\n",
}, { // #01
src: `println("Hello")`,
- asm: "Dup 0\nDup 1\nCallX 1\n",
+ asm: "Dup 0\nDup 1\nCallX 1\nPop 2\n",
}, { // #02
src: `a := 2; println(a)`,
- asm: "Push 2\nAssign 1\nDup 0\nDup 1\nCallX 1\n",
+ asm: "Push 2\nAssign 1\nDup 0\nDup 1\nCallX 1\nPop 2\n",
}, { // #03
src: `a := 2; if a < 3 {println(a)}; println("bye")`,
- asm: "Push 2\nAssign 1\nDup 1\nPush 3\nLower\nJumpFalse 4\nDup 0\nDup 1\nCallX 1\nDup 0\nDup 2\nCallX 1\n",
+ asm: "Push 2\nAssign 1\nDup 1\nPush 3\nLower\nJumpFalse 5\nDup 0\nDup 1\nCallX 1\nPop 2\nDup 0\nDup 2\nCallX 1\nPop 2\n",
}, { // #04
src: "func add(a int, b int) int { return a + b }",
asm: "Fdup -2\nFdup -3\nAdd\nReturn 1 2\n",