summaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
Diffstat (limited to 'std')
-rw-r--r--std/io.toc28
1 files changed, 25 insertions, 3 deletions
diff --git a/std/io.toc b/std/io.toc
index ab3549b..f864c3c 100644
--- a/std/io.toc
+++ b/std/io.toc
@@ -1,10 +1,32 @@
pkg "io";
-c_putchar :: fn(i32) i32 = #foreign "putchar", "libc.so.6";
+get_type_with_size ::= fn(size :: i64) Type {
+ if size == 1 { i8 }
+ elif size == 2 { i16 }
+ elif size == 4 { i32 }
+ elif size == 8 { i64 }
+ else { f32 }
+};
+
+get_utype_with_size ::= fn(size :: i64) Type {
+ if size == 1 { u8 }
+ elif size == 2 { u16 }
+ elif size == 4 { u32 }
+ elif size == 8 { u64 }
+ else { f32 }
+};
+
+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";
+toc_putchar ::= fn(x: char) {
+ c_putchar(x as c_int);
+};
#export puts ::= fn(x: []char) {
for c := x {
- c_putchar(c as i32);
+ toc_putchar(c);
};
- c_putchar('\n' as i32);
+ toc_putchar('\n');
}; \ No newline at end of file