From 3f4efe745a0404953266476ec52db54b182de2f8 Mon Sep 17 00:00:00 2001 From: Mel Date: Fri, 20 May 2022 21:04:37 +0200 Subject: Call and return from functions --- pkg/lang/vm/vm_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'pkg/lang/vm/vm_test.go') 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) -- cgit 1.4.1