From c12e005630f77c608b4fdebbb5054c5f46ab4df0 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Sat, 25 Jan 2020 17:50:34 -0500 Subject: more #builtin. realized theres a problem with pkgs... --- std/io.toc | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'std') 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 -- cgit v1.2.3