diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-04-22 15:57:24 -0400 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-04-22 15:57:24 -0400 |
commit | 4062e5c965bc04ec9654d82526e5e785f7f45d03 (patch) | |
tree | e12b1af103ba8e7218c4adcff4c718ab236523d1 /std | |
parent | 2df588fb6ebc77d067e390e5c70c5da0298a47b2 (diff) |
used for loops
Diffstat (limited to 'std')
-rw-r--r-- | std/io.toc | 16 |
1 files changed, 12 insertions, 4 deletions
@@ -2,16 +2,19 @@ putchar ::= #foreign("putchar", "libc.so.6") fn(#C int) #C int; toc_putchar ::= fn(x: char) { putchar(x as #C int); } +printf ::= #foreign("printf", "libc.so.6") fn(#C &"char const", #C ..) #C int; +writes ::= fn(x: []char) { + printf_strfmt := "%s\0"; + printf(&printf_strfmt[0], &x[0]); +} puts ::= fn(x: []char) { - for c := x { - toc_putchar(c); - } + writes(x); toc_putchar('\n'); } -puti ::= fn(x: int) { +writei ::= fn(x: int) { if x < 0 { toc_putchar('-'); // NOTE: don't do x = -x; here to make sure I64_MIN works @@ -31,5 +34,10 @@ puti ::= fn(x: int) { scan_digit /= 10; } } +} + +puti ::= fn(x: int) { + writei(x); toc_putchar('\n'); } + |