diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-01-22 17:02:14 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-01-22 17:02:14 -0500 |
commit | 1184d39f79a341bfa6c1642dc1ae246113186155 (patch) | |
tree | 1080b1c50c69a98c00911464e7bea0c7ecb1ab4f | |
parent | c169e55a4bf4e278b712176ae7a9787f3db8d610 (diff) |
new std/io
-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 |