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-07-19 02:27:19 +0200
committerMel <einebeere@gmail.com>2022-07-19 02:27:19 +0200
commitb6fa4bc82398b09307f2e6b75e27422d1d1ecb33 (patch)
treee5b7aec7eb7f72f1c2f55e4b2a78d331bd81485e /pkg/lang/compiler/compiler_test.go
parente06aeb7fa2fcb9046b8861ed3c23417555e823f5 (diff)
downloadjinx-b6fa4bc82398b09307f2e6b75e27422d1d1ecb33.tar.zst
jinx-b6fa4bc82398b09307f2e6b75e27422d1d1ecb33.zip
Implement stack hygiene
Diffstat (limited to 'pkg/lang/compiler/compiler_test.go')
-rw-r--r--pkg/lang/compiler/compiler_test.go20
1 files changed, 17 insertions, 3 deletions
diff --git a/pkg/lang/compiler/compiler_test.go b/pkg/lang/compiler/compiler_test.go
index 7741ca9..b8a6264 100644
--- a/pkg/lang/compiler/compiler_test.go
+++ b/pkg/lang/compiler/compiler_test.go
@@ -21,6 +21,7 @@ func TestSimpleAddExpr(t *testing.T) {
 	push_int 1
 	push_int 2
 	add
+	drop 1
 	halt
 	`
 
@@ -44,6 +45,7 @@ func TestOperationOrder(t *testing.T) {
 	sub
 	push_int 4
 	add
+	drop 1
 	halt
 	`
 
@@ -78,6 +80,8 @@ func TestNestedExpr(t *testing.T) {
 	add
 	sub
 
+	drop 1
+
 	halt
 	`
 
@@ -141,15 +145,12 @@ func TestArrayLit(t *testing.T) {
 
 func TestIf(t *testing.T) {
 	src := `
-	":("
 	if 1 <= 5 {
 		"hello " + "world"
 	}
 	`
 
 	expected := `
-	push_string ":("
-
 	push_int 1
 	push_int 5
 	lte
@@ -160,6 +161,8 @@ func TestIf(t *testing.T) {
 	push_string "world"
 	add
 
+	drop 1
+
 	@end:
 	halt
 	`
@@ -183,16 +186,19 @@ func TestIfElifElse(t *testing.T) {
 	jf @elif
 
 	push_int 1
+	drop 1
 	jmp @end
 
 	@elif:
 	push_true
 	jf @else
 	push_int 2
+	drop 1
 	jmp @end
 
 	@else:
 	push_int 3
+	drop 1
 
 	@end:
 	halt
@@ -215,12 +221,14 @@ func TestIfNoElse(t *testing.T) {
 	jf @elif
 
 	push_int 1
+	drop 1
 	jmp @end
 
 	@elif:
 	push_true
 	jf @end
 	push_int 2
+	drop 1
 
 	@end:
 	halt
@@ -248,10 +256,12 @@ func TestNestedIfs(t *testing.T) {
 	jf @else
 
 	push_int 1
+	drop 1
 	jmp @end
 
 	@else:
 	push_int 2
+	drop 1
 	
 	@end:
 	halt
@@ -279,6 +289,7 @@ func TestForCond(t *testing.T) {
 	jf @inner_end
 
 	push_int 1
+	drop 1
 	jmp @inner_start
 
 	@inner_end:
@@ -410,9 +421,11 @@ func TestForIn(t *testing.T) {
 	push_string "say"
 	get_local 2
 	call 1
+	drop 1
 
 	jmp @check
 	@end:
+	drop 3
 	halt
 	`
 
@@ -456,6 +469,7 @@ func TestFunctionArgs(t *testing.T) {
 	push_int 4
 	push_int 5
 	call 2
+	drop 1
 	halt
 
 	@add: