summaryrefslogtreecommitdiff
path: root/tests/nms/io.toc
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-03-01 12:08:28 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2020-03-01 12:08:28 -0500
commitda748748c0239c21b9d62c77b51e269ad1d7de9f (patch)
tree2e546d3d370cb0aeea7fe24e653c9a456ec614b7 /tests/nms/io.toc
parent7cced2c313c94d1fb8736581840dff00708aabf1 (diff)
better #foreign system
Diffstat (limited to 'tests/nms/io.toc')
-rw-r--r--tests/nms/io.toc28
1 files changed, 16 insertions, 12 deletions
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
+};