From 621f624f50a7bef16eeed02113b470e79e790cd9 Mon Sep 17 00:00:00 2001 From: Mel Date: Mon, 20 Jun 2022 00:37:01 +0200 Subject: Compile rudimetary variables --- pkg/lang/compiler/compiler_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 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 5f0cd2c..5347830 100644 --- a/pkg/lang/compiler/compiler_test.go +++ b/pkg/lang/compiler/compiler_test.go @@ -81,6 +81,33 @@ func TestNestedExpr(t *testing.T) { mustCompileTo(t, src, expected) } +func TestVars(t *testing.T) { + src := ` + var x = 10 + var y = 25 + x = x + 7 + + var res = x + y + ` + + expected := ` + push_int 10 + + push_int 25 + + push_int 7 + get_local 0 + add + set_local 0 + + get_local 1 + get_local 0 + add + ` + + 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