diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/arr3/io.toc | 4 | ||||
-rw-r--r-- | tests/foreign/foreign.toc | 15 | ||||
-rw-r--r-- | tests/nms/io.toc | 28 |
3 files changed, 22 insertions, 25 deletions
diff --git a/tests/arr3/io.toc b/tests/arr3/io.toc index fac4921..5a69269 100644 --- a/tests/arr3/io.toc +++ b/tests/arr3/io.toc @@ -17,12 +17,12 @@ get_utype_with_size ::= fn(size :: i64) Type { c_int ::= get_type_with_size(#builtin("sizeof int")); c_size_t ::= get_utype_with_size(#builtin("sizeof size_t")); -c_putchar :: fn(c_int) c_int = #foreign "putchar", "libc.so.6"; +c_putchar ::= #foreign("putchar", "libc.so.6") fn(#C int) #C int; toc_putchar ::= fn(x: char) { c_putchar(x as c_int); }; -c_fwrite :: fn(&u8, c_size_t, c_size_t, &u8) = #foreign "fwrite", "libc.so.6"; +c_fwrite ::= #foreign("fwrite", "libc.so.6") fn(&u8, #C size_t, #C size_t, &u8) #C size_t; stdout_fwrite ::= fn(data: &u8, size: u64, nmemb: u64) { c_fwrite(data, size as c_size_t, nmemb as c_size_t, #builtin("stdout")); diff --git a/tests/foreign/foreign.toc b/tests/foreign/foreign.toc index beaa822..d88a223 100644 --- a/tests/foreign/foreign.toc +++ b/tests/foreign/foreign.toc @@ -1,20 +1,13 @@ -voidptr ::= &u8; - -getstdout ::= fn() voidptr { - #builtin("stdout") -}; - - -fwrite :: fn(voidptr, u64, u64, voidptr) u64 = #foreign "fwrite", "libc.so.6"; -fputc :: fn(i32, voidptr) i32 = #foreign "fputc", "libc.so.6"; +fwrite ::= #foreign("fwrite", "libc.so.6") fn (#C &"void const", #C size_t, #C size_t, &u8) #C size_t; +fputc ::= #foreign("fputc", "libc.so.6") fn (#C int, &u8) #C int; writes ::= fn(x : []char) { - fwrite(&x[0] as voidptr, 1, x.len as u64, getstdout()); + fwrite(&x[0], 1, x.len as u64, #builtin("stdout")); }; puts ::= fn(x : []char) { writes(x); - fputc('\n' as i32, getstdout()); + fputc('\n' as i32, #builtin("stdout")); }; hw ::= fn() int { diff --git a/tests/nms/io.toc b/tests/nms/io.toc index 51cfd76..5a69269 100644 --- a/tests/nms/io.toc +++ b/tests/nms/io.toc @@ -17,12 +17,12 @@ get_utype_with_size ::= fn(size :: i64) Type { c_int ::= get_type_with_size(#builtin("sizeof int")); c_size_t ::= get_utype_with_size(#builtin("sizeof size_t")); -c_putchar :: fn(c_int) c_int = #foreign "putchar", "libc.so.6"; +c_putchar ::= #foreign("putchar", "libc.so.6") fn(#C int) #C int; toc_putchar ::= fn(x: char) { c_putchar(x as c_int); }; -c_fwrite :: fn(&u8, c_size_t, c_size_t, &u8) = #foreign "fwrite", "libc.so.6"; +c_fwrite ::= #foreign("fwrite", "libc.so.6") fn(&u8, #C size_t, #C size_t, &u8) #C size_t; stdout_fwrite ::= fn(data: &u8, size: u64, nmemb: u64) { c_fwrite(data, size as c_size_t, nmemb as c_size_t, #builtin("stdout")); @@ -38,16 +38,20 @@ puti ::= fn(x: int) { toc_putchar('-'); // NOTE: don't do x = -x; here to make sure I64_MIN works } - abs ::= fn(x: int) int { if x < 0 { -x } else { x } }; - scan_digit := 1000000000000000000; - started := false; - while scan_digit > 0 { - digit := abs((x / scan_digit) % 10); - if digit > 0 { started = true; } - if started { - toc_putchar((('0' as int) + digit) as char); + if x == 0 { + toc_putchar('0'); + } else { + abs ::= fn(x: int) int { if x < 0 { -x } else { x } }; + scan_digit := 1000000000000000000; + started := false; + while scan_digit > 0 { + digit := abs((x / scan_digit) % 10); + if digit > 0 { started = true; } + if started { + toc_putchar((('0' as int) + digit) as char); + } + scan_digit /= 10; } - scan_digit /= 10; } toc_putchar('\n'); -};
\ No newline at end of file +}; |