diff options
| author | Mel <einebeere@gmail.com> | 2022-06-26 21:54:38 +0200 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2022-06-26 21:54:38 +0200 |
| commit | 18c7ab70ded45c76abb0b35c090b942a7bfcc3b4 (patch) | |
| tree | 6505f6197bd276b4a4bfbac3707064492c5626c8 /pkg/lang/vm/vm_test.go | |
| parent | 621f624f50a7bef16eeed02113b470e79e790cd9 (diff) | |
| download | jinx-18c7ab70ded45c76abb0b35c090b942a7bfcc3b4.tar.zst jinx-18c7ab70ded45c76abb0b35c090b942a7bfcc3b4.zip | |
Change arguments order in VM to match expectation
Diffstat (limited to 'pkg/lang/vm/vm_test.go')
| -rw-r--r-- | pkg/lang/vm/vm_test.go | 95 |
1 files changed, 48 insertions, 47 deletions
diff --git a/pkg/lang/vm/vm_test.go b/pkg/lang/vm/vm_test.go index d63523f..fa43b02 100644 --- a/pkg/lang/vm/vm_test.go +++ b/pkg/lang/vm/vm_test.go @@ -12,8 +12,8 @@ import ( func TestSimpleSub(t *testing.T) { src := ` - push_int 1 push_int 2 + push_int 1 sub ` @@ -23,8 +23,8 @@ func TestSimpleSub(t *testing.T) { func TestGetLocal(t *testing.T) { src := ` push_int 404 - push_int 1 push_int 2 + push_int 1 add get_local 1 ` @@ -37,51 +37,51 @@ func TestFibonacci(t *testing.T) { # Array stored in local 0 push_array - push_int 1 get_local 0 + push_int 1 temp_arr_push - push_int 1 get_local 0 + push_int 1 temp_arr_push @fib_loop: - - push_int 1 - get_local 0 temp_arr_len + + push_int 1 # Index of the last element stored in local 1 sub + get_local 0 + get_local 0 # This is the last element get_local 1 - get_local 0 # Store the last element in local 2 index - push_int 1 + get_local 0 + get_local 1 + push_int 1 # Index of the second last element stored in local 2 sub - get_local 0 # Store the second last element in local 3 index add - get_local 0 temp_arr_push # Drop local 1, which was the length of the array, which we no longer need drop - push_int 10 - get_local 0 temp_arr_len + push_int 10 + # Jump if the array is larger than 10. lte jt @fib_loop @@ -123,8 +123,8 @@ func TestSimpleEnv(t *testing.T) { halt @test: + get_env 0 push_int 2 - get_env 0 add ret ` @@ -152,19 +152,19 @@ func TestEscapedEnv(t *testing.T) { push_array + get_local 1 get_local 0 call 0 - get_local 1 temp_arr_push + get_local 1 get_local 0 call 0 - get_local 1 temp_arr_push + get_local 1 get_local 0 call 0 - get_local 1 temp_arr_push halt @@ -176,8 +176,8 @@ func TestEscapedEnv(t *testing.T) { add_to_env 0 ret @create:anon_0: + get_env 0 push_int 1 - get_env 0 add set_env 0 get_env 0 @@ -191,16 +191,16 @@ func TestMember(t *testing.T) { src := ` push_array - push_int 1 get_local 0 + push_int 1 temp_arr_push - push_int 2 get_local 0 + push_int 2 temp_arr_push - push_int 3 get_local 0 + push_int 3 temp_arr_push get_member "length" @@ -214,12 +214,12 @@ func TestObject(t *testing.T) { src := ` push_object - push_string "Petronij" get_local 0 + push_string "Petronij" set_member "name" - push_int 10 get_local 0 + push_int 10 set_member "age" get_local 0 @@ -250,27 +250,27 @@ func TestTypeConstruct(t *testing.T) { # Create a new type Cat push_type "Cat" - push_function @Cat:$init - push_string "$init" - get_local 0 get_member "$add_method" + + push_string "$init" + push_function @Cat:$init call 2 - push_function @Cat:meow - push_string "meow" - get_local 0 get_member "$add_method" + push_string "meow" + push_function @Cat:meow + call 2 # Create a new instance of Cat - push_string "Kitty" - push_int 3 get_local 0 get_member "$init" + push_string "Kitty" + push_int 3 call 2 # Call the meow method @@ -280,24 +280,24 @@ func TestTypeConstruct(t *testing.T) { halt @Cat:$init: - get_env 0 push_object + get_env 0 anchor_type - get_local 0 get_local 2 + get_local 1 set_member "name" - get_local 1 get_local 2 + get_local 0 set_member "age" ret @Cat:meow: - push_string " says Meow!" - get_env 0 get_member "name" + + push_string " says Meow!" add ret @@ -308,7 +308,7 @@ func TestTypeConstruct(t *testing.T) { func TestPrimes(t *testing.T) { /* - var i = 0 + var i = 2 var primes = [] for i <= 10 { @@ -339,8 +339,8 @@ func TestPrimes(t *testing.T) { push_int 2 push_array @main_loop: - push_int 10 get_local 0 + push_int 10 lte jf @end @@ -348,47 +348,48 @@ func TestPrimes(t *testing.T) { push_int 1 @factor_loop: - get_local 0 get_local 3 + get_local 0 lte jf @prime_check - push_int 0 - - get_local 3 + get_local 0 + get_local 3 mod + + push_int 0 lte jf @factor_loop_inc - get_local 3 get_local 2 + get_local 3 temp_arr_push @factor_loop_inc: - push_int 1 get_local 3 + push_int 1 add set_local 3 jmp @factor_loop @prime_check: - push_int 2 get_local 2 get_member "length" call 0 + push_int 2 lte jf @main_loop_inc - get_local 0 get_local 1 + get_local 0 temp_arr_push @main_loop_inc: - push_int 1 get_local 0 + push_int 1 add set_local 0 |
