diff options
Diffstat (limited to 'pkg/lang/compiler/compiler_test.go')
| -rw-r--r-- | pkg/lang/compiler/compiler_test.go | 27 |
1 files changed, 27 insertions, 0 deletions
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() |
