#include "std/base.toc"; putchar ::= #foreign("putchar", libc) fn(#C int) #C int; toc_putchar ::= fn(x: char) { putchar(x as #C int); } fwrite ::= #foreign("fwrite", libc) fn(#C &"const void", #C size_t, #C size_t, #C &"FILE") #C size_t; writes ::= fn(x: []char) { fwrite(&x[0], 1, x.len as #C size_t, #builtin("stdout")); } puts ::= fn(x: []char) { writes(x); toc_putchar('\n'); } writei ::= fn(x: int) { if x < 0 { toc_putchar('-'); // NOTE: don't do x = -x; here to make sure I64_MIN works } 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; } } } puti ::= fn(x: int) { writei(x); toc_putchar('\n'); }