diff options
-rwxr-xr-x | pkg.sh | 2 | ||||
-rw-r--r-- | std/io.toc | 14 | ||||
-rw-r--r-- | test.toc | 46 |
3 files changed, 8 insertions, 54 deletions
@@ -15,5 +15,5 @@ for thing in $std_things; do done cd .. $VALGRIND ./toc test.toc || exit 1 -$CC out.c std/*.c || exit 1 +$CC out.c std/*.c -Wno-builtin-declaration-mismatch || exit 1 ./a.out @@ -1,14 +1,10 @@ pkg "io"; -#export puti ::= fn(x: int) { - #C("printf(\"%ld\\n\", (long)x)"); -}; - -#export putf ::= fn(x: float) { - #C("printf(\"%f\\n\", (double)x)"); -}; +c_putchar :: fn(i32) = #foreign "putchar", "libc.so.6"; #export puts ::= fn(x: []char) { - #C("fwrite(x.data, 1, x.n, stdout)"); - #C("printf(\"\\n\")"); + each c := x { + c_putchar(c as i32); + }; + c_putchar('\n' as i32); };
\ No newline at end of file @@ -1,46 +1,4 @@ -import ::= fn(x :: []char) &Package { - p ::= pkg x; - p_ptr ::= new(Package); - *p_ptr = p; - p_ptr -}; - -cputs :: fn(&char) i32 = #foreign "puts", "libc.so.6"; - -tocputs ::= fn(s: []char) i32 { - cstr := new(char, s.len + 1); - each i := 0..s.len-1 { - cstr[i] = s[i]; - } - cstr[s.len] = '\0'; - ret := cputs(&cstr[0]); - del(cstr); - ret -}; - -foo ::= fn() i32 { - tocputs("Hi"); - tocputs("Hello"); - tocputs("Hey") -}; - -malloc :: fn(u64) &u8 = #foreign "malloc", "libc.so.6"; - -sqrt :: fn(f64) f64 = #foreign "sqrt", "libm.so.6"; -cos :: fn(f64) f64 = #foreign "cos", "libm.so.6"; -sin :: fn(f64) f64 = #foreign "sin", "libm.so.6"; - -stderr :: &u8 = #foreign "stderr"; -fprintf :: fn(&u8, &char) = #foreign "fprintf"; - - +io ::= pkg "std/io"; main ::= fn() { - x ::= foo(); - // y ::= malloc(10); - sq2 ::= sqrt(2); - cospi ::= cos(3.14159); - sinpi ::= sin(3.14159); - foo(); - s := "Hello!\n\0"; - fprintf(stderr, &s[0]); + io.puts("Hello, world!"); };
\ No newline at end of file |