From 88e7c92e76ce771e7a1efd4824060e3905194070 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Sun, 1 Mar 2020 12:21:50 -0500 Subject: casting to #C types --- std/io.toc | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) (limited to 'std') diff --git a/std/io.toc b/std/io.toc index 5a69269..2c1fc8b 100644 --- a/std/io.toc +++ b/std/io.toc @@ -1,31 +1,14 @@ -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("#include \n"); -c_putchar ::= #foreign("putchar", "libc.so.6") fn(#C int) #C int; +putchar ::= #foreign("putchar", "libc.so.6") fn(#C int) #C int; toc_putchar ::= fn(x: char) { - c_putchar(x as c_int); + putchar(x as #C int); }; -c_fwrite ::= #foreign("fwrite", "libc.so.6") fn(&u8, #C size_t, #C size_t, &u8) #C size_t; +fwrite ::= #foreign("fwrite", "libc.so.6") fn(#C &"void", #C size_t, #C size_t, #C &"void") #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")); + fwrite(data, size as #C size_t, nmemb as #C size_t, #builtin("stdout")); }; puts ::= fn(x: []char) { -- cgit v1.2.3