diff options
| author | Mel <einebeere@gmail.com> | 2022-07-05 22:29:55 +0200 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2022-07-05 22:29:55 +0200 |
| commit | 7f8cf65c6e64d28a76ac52849b707dcbcbdcd923 (patch) | |
| tree | 1337400205a52b51b97a483d48f34a9d7df3a6f7 /pkg/lang/compiler/compiler_test.go | |
| parent | b09fce67753e199d4ae0fe6138f909b5e3413208 (diff) | |
| download | jinx-7f8cf65c6e64d28a76ac52849b707dcbcbdcd923.tar.zst jinx-7f8cf65c6e64d28a76ac52849b707dcbcbdcd923.zip | |
Compile ForCond statements
Diffstat (limited to 'pkg/lang/compiler/compiler_test.go')
| -rw-r--r-- | pkg/lang/compiler/compiler_test.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/pkg/lang/compiler/compiler_test.go b/pkg/lang/compiler/compiler_test.go index 88413c7..1a759f8 100644 --- a/pkg/lang/compiler/compiler_test.go +++ b/pkg/lang/compiler/compiler_test.go @@ -234,6 +234,37 @@ func TestNestedIfs(t *testing.T) { mustCompileTo(t, src, expected) } +func TestForCond(t *testing.T) { + src := ` + for true { + for false { + 1 + } + } + ` + + expected := ` + @start: + push_true + jf @end + + @inner_start: + push_false + jf @inner_end + + push_int 1 + jmp @inner_start + + @inner_end: + jmp @start + + @end + halt + ` + + mustCompileTo(t, src, expected) +} + func mustCompileTo(t *testing.T, src, expected string) { scanner := scanner.New(strings.NewReader(src)) tokens, err := scanner.Scan() |
