diff options
| author | Marc Vertes <mvertes@free.fr> | 2023-11-23 17:56:35 +0100 |
|---|---|---|
| committer | Marc Vertes <mvertes@free.fr> | 2023-11-24 09:12:46 +0100 |
| commit | 6a32a7bc5f6320902cd5c2910a1353a0f7039237 (patch) | |
| tree | 0fcce51e4d4f54d48d57a5dda8a896a35264f68b /parser/interpreter_test.go | |
| parent | c548093d79edece3c1cbb7e4dc03d92fe45b1cc7 (diff) | |
parser: fix allocation of local variables
A 'New' instruction is added in VM to manage initialisation
of typed variables in the stack. The instantiated type symbols
are now added to global data. Accessing and setting values by
address is now working.
Diffstat (limited to 'parser/interpreter_test.go')
| -rw-r--r-- | parser/interpreter_test.go | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/parser/interpreter_test.go b/parser/interpreter_test.go index 9555475..9110e3c 100644 --- a/parser/interpreter_test.go +++ b/parser/interpreter_test.go @@ -52,7 +52,7 @@ func run(t *testing.T, tests []etest) { func TestExpr(t *testing.T) { run(t, []etest{ - {src: "", res: "<nil>"}, + {src: "", res: "<invalid reflect.Value>"}, {src: "1+2", res: "3"}, {src: "1+", err: "block not terminated"}, {src: "a := 1 + 2; b := 0; a + 1", res: "4"}, @@ -92,7 +92,7 @@ func TestFunc(t *testing.T) { {src: "func f() int {return 2}; a := f(); a", res: "2"}, {src: "func f() int {return 2}; f()", res: "2"}, {src: "func f(a int) int {return a+2}; f(3)", res: "5"}, - {src: "func f(a int) int {if a < 4 {a = 5}; return a }; f(3)", res: "5"}, + {src: "func f(a int) int {if a < 4 {a = 5}; return a}; f(3)", res: "5"}, {src: "func f(a int) int {return a+2}; 7 - f(3)", res: "2"}, {src: "func f(a int) int {return a+2}; f(5) - f(3)", res: "2"}, {src: "func f(a int) int {return a+2}; f(3) - 2", res: "3"}, @@ -195,7 +195,8 @@ func TestArray(t *testing.T) { func TestPointer(t *testing.T) { run(t, []etest{ {src: "var a *int; a", res: "<nil>"}, - //{src: "var a int = 2; var b *int = &a; b", res: "2"}, + {src: "var a int; var b *int = &a; *b", res: "0"}, + {src: "var a int = 2; var b *int = &a; *b", res: "2"}, }) } |
