summaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-02-04 17:32:31 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2020-02-04 17:32:31 -0500
commitd2b60a4be9e6b2172a267c6a9554567f1c54211a (patch)
tree323157ab71e25fb3c20a417b8bccf570998cafa9 /std
parent75fc567dfdb4a6500990d79dc3f167d3262a96c5 (diff)
more namespaces
Diffstat (limited to 'std')
-rw-r--r--std/io.toc23
1 files changed, 21 insertions, 2 deletions
diff --git a/std/io.toc b/std/io.toc
index dab2aea..51cfd76 100644
--- a/std/io.toc
+++ b/std/io.toc
@@ -29,6 +29,25 @@ stdout_fwrite ::= fn(data: &u8, size: u64, nmemb: u64) {
};
puts ::= fn(x: []char) {
- stdout_fwrite(&x[0] as &u8, 1, x.len as u64);
- toc_putchar('\n');
+ stdout_fwrite(&x[0] as &u8, 1, x.len as u64);
+ toc_putchar('\n');
};
+
+puti ::= fn(x: int) {
+ if x < 0 {
+ 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);
+ }
+ scan_digit /= 10;
+ }
+ toc_putchar('\n');
+}; \ No newline at end of file