From 851c793da43be9e4d3319afe440d603c85834045 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Thu, 31 Aug 2023 17:53:54 +0200 Subject: 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 --- codegen/compiler_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'codegen/compiler_test.go') 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", -- cgit v1.2.3