about summary refs log tree commit diff
path: root/pkg/lang/vm/vm_test.go
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2022-05-20 21:04:37 +0200
committerMel <einebeere@gmail.com>2022-05-20 21:04:37 +0200
commit3f4efe745a0404953266476ec52db54b182de2f8 (patch)
tree107542d587c97b99f749c537870e84d196058210 /pkg/lang/vm/vm_test.go
parent25eb5ca1b0a8b9b35f36deedec4901bca02bf43e (diff)
downloadjinx-3f4efe745a0404953266476ec52db54b182de2f8.tar.zst
jinx-3f4efe745a0404953266476ec52db54b182de2f8.zip
Call and return from functions
Diffstat (limited to 'pkg/lang/vm/vm_test.go')
-rw-r--r--pkg/lang/vm/vm_test.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/pkg/lang/vm/vm_test.go b/pkg/lang/vm/vm_test.go
index f87182f..298cfb2 100644
--- a/pkg/lang/vm/vm_test.go
+++ b/pkg/lang/vm/vm_test.go
@@ -90,6 +90,24 @@ func TestFibonacci(t *testing.T) {
 	test(t, src, "[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]")
 }
 
+func TestFunction(t *testing.T) {
+	src := `
+	push_int 44
+	push_function @subtract_two
+	call
+	halt
+
+	@subtract_two:
+		shift 1
+		push_int 2
+		get_local 0
+		sub
+		ret
+	`
+
+	test(t, src, "42")
+}
+
 
 func test(t *testing.T, src string, expected string) {
 	bc := compile(t, src)