diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-01-25 17:50:34 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-01-25 17:50:34 -0500 |
commit | c12e005630f77c608b4fdebbb5054c5f46ab4df0 (patch) | |
tree | f97706f2c0e59abccb1383f5022b5e908526a685 /std | |
parent | b359789c4625d197f5c6ea48a4ab45467985f5e9 (diff) |
more #builtin. realized theres a problem with pkgs...
Diffstat (limited to 'std')
-rw-r--r-- | std/io.toc | 28 |
1 files changed, 25 insertions, 3 deletions
@@ -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 |