diff options
| author | Mel <einebeere@gmail.com> | 2022-07-05 23:39:18 +0200 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2022-07-06 14:05:28 +0200 |
| commit | 3a31347d38ae9a4c04c52304330b50f95a54a826 (patch) | |
| tree | e5ddbe398ede58f45c4a8e79c66018c5e37b06d8 /pkg/lang/compiler/compiler_test.go | |
| parent | bb1f61f938be3cc209dacf97b0395336631319bb (diff) | |
| download | jinx-3a31347d38ae9a4c04c52304330b50f95a54a826.tar.zst jinx-3a31347d38ae9a4c04c52304330b50f95a54a826.zip | |
Implement ForIn statement compilation
Diffstat (limited to 'pkg/lang/compiler/compiler_test.go')
| -rw-r--r-- | pkg/lang/compiler/compiler_test.go | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/pkg/lang/compiler/compiler_test.go b/pkg/lang/compiler/compiler_test.go index 4fd4bac..326ad68 100644 --- a/pkg/lang/compiler/compiler_test.go +++ b/pkg/lang/compiler/compiler_test.go @@ -291,6 +291,60 @@ func TestForCond(t *testing.T) { mustCompileTo(t, src, expected) } +func TestForIn(t *testing.T) { + src := ` + for x in [1, 2, 3] { + "say"(x) + } + ` + + expected := ` + push_array + + get_local 0 + get_member "$push" + push_int 1 + call 1 + + get_local 0 + get_member "$push" + push_int 2 + call 1 + + get_local 0 + get_member "$push" + push_int 3 + call 1 + + push_int 0 + push_null + + @check: + get_local 1 + get_local 0 + get_member "$length" + call 0 + lt + + jf @end + + get_local 0 + get_local 1 + index + set_local 2 + + push_string "say" + get_local 2 + call 1 + + jmp @check + @end: + halt + ` + + mustCompileTo(t, src, expected) +} + func mustCompileTo(t *testing.T, src, expected string) { scanner := scanner.New(strings.NewReader(src)) tokens, err := scanner.Scan() |
