diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-03-16 16:26:13 -0400 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-03-16 16:26:13 -0400 |
commit | b7b3e0868b9eef1018f87bd1c81c0112abaf94f4 (patch) | |
tree | e9a754e867302b9949612fec639b7722967f94fc /tests | |
parent | 35459f4ef5c9076a331acecd0c16328326c4081b (diff) |
break, continue
Diffstat (limited to 'tests')
-rw-r--r-- | tests/control_flow.toc | 31 | ||||
-rw-r--r-- | tests/control_flow_expected | 2 | ||||
-rw-r--r-- | tests/io.toc | 16 | ||||
-rwxr-xr-x | tests/test.sh | 3 |
4 files changed, 41 insertions, 11 deletions
diff --git a/tests/control_flow.toc b/tests/control_flow.toc new file mode 100644 index 0000000..923a40b --- /dev/null +++ b/tests/control_flow.toc @@ -0,0 +1,31 @@ +#include "io.toc", io; + +f ::= fn() int { + total := 0; + for i := 1..10 { + if i % 2 == 0 { continue; } + total += i; + if i == 7 { break; } + } + i := 0; + while { + i += 1; + total += i; + if i == 10 { + break; + } + } + while i < 100 { + i += 1; + if i == 100 { + return total; + } + } + 0 +} + +main ::= fn() { + x ::= f(); + io.puti(x); + io.puti(f()); +}
\ No newline at end of file diff --git a/tests/control_flow_expected b/tests/control_flow_expected new file mode 100644 index 0000000..15e58a7 --- /dev/null +++ b/tests/control_flow_expected @@ -0,0 +1,2 @@ +71 +71 diff --git a/tests/io.toc b/tests/io.toc index 9e94147..d3ce467 100644 --- a/tests/io.toc +++ b/tests/io.toc @@ -1,19 +1,15 @@ - putchar ::= #foreign("putchar", "libc.so.6") fn(#C int) #C int; toc_putchar ::= fn(x: char) { putchar(x as #C int); -}; - -fwrite ::= #foreign("fwrite", "libc.so.6") fn(#C &"void", #C size_t, #C size_t, #C &"void") #C size_t; +} -stdout_fwrite ::= fn(data: &u8, size: u64, nmemb: u64) { - fwrite(data, size as #C size_t, nmemb as #C size_t, #builtin("stdout")); -}; puts ::= fn(x: []char) { - stdout_fwrite(&x[0] as &u8, 1, x.len as u64); + for c := x { + toc_putchar(c); + } toc_putchar('\n'); -}; +} puti ::= fn(x: int) { if x < 0 { @@ -36,4 +32,4 @@ puti ::= fn(x: int) { } } toc_putchar('\n'); -}; +} diff --git a/tests/test.sh b/tests/test.sh index d30de7c..4016151 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -1,6 +1,7 @@ #!/bin/bash tests='bf +control_flow arr arr2 arr3 @@ -26,7 +27,7 @@ compile_c() { elif [ "$CC" = "tcc" ]; then EXTRA_FLAGS="-w" fi - $CC $CFLAGS $EXTRA_FLAGS -o a.out out.c || exit 1 + $CC $CFLAGS $EXTRA_FLAGS -Werror -o a.out out.c || exit 1 } do_tests() { |