about summary refs log tree commit diff
path: root/pkg/lang/compiler/compiler_test.go
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2022-06-20 00:37:01 +0200
committerMel <einebeere@gmail.com>2022-06-20 00:37:01 +0200
commit621f624f50a7bef16eeed02113b470e79e790cd9 (patch)
tree058767579a4c542b173ee001cc7e89a853d79e25 /pkg/lang/compiler/compiler_test.go
parent9a847f9ec4a0030bf2194005bc9a79cd609cd48a (diff)
downloadjinx-621f624f50a7bef16eeed02113b470e79e790cd9.tar.zst
jinx-621f624f50a7bef16eeed02113b470e79e790cd9.zip
Compile rudimetary variables
Diffstat (limited to 'pkg/lang/compiler/compiler_test.go')
-rw-r--r--pkg/lang/compiler/compiler_test.go27
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()