From d84c0f36afcde4e5af2907d70931de75957d5277 Mon Sep 17 00:00:00 2001 From: Mel Date: Tue, 16 Aug 2022 20:33:41 +0000 Subject: Implement setting values at index in an array --- pkg/lang/compiler/compiler_test.go | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'pkg/lang/compiler/compiler_test.go') diff --git a/pkg/lang/compiler/compiler_test.go b/pkg/lang/compiler/compiler_test.go index e40d98e..2e4e6e7 100644 --- a/pkg/lang/compiler/compiler_test.go +++ b/pkg/lang/compiler/compiler_test.go @@ -629,6 +629,46 @@ func TestGlobals(t *testing.T) { mustCompileTo(t, src, expected) } +func TestLvalueAssign(t *testing.T) { + src := ` + var v = 1 + var obj = null + var arr = [1] + + v = 2 + obj.x = 2 + arr[0] = 2 + ` + + expected := ` + push_int 1 + + push_null + + push_array + get_local 2 + get_member "push" + push_int 1 + call 1 + drop 1 + + push_int 2 + set_local 0 + + get_local 1 + push_int 2 + set_member "x" + + get_local 2 + push_int 0 + push_int 2 + set_at_index + halt + ` + + mustCompileTo(t, src, expected) +} + func mustCompileTo(t *testing.T, src, expected string) { scanner := scanner.New(strings.NewReader(src)) tokens, err := scanner.Scan() -- cgit 1.4.1