summaryrefslogtreecommitdiff
path: root/tests/foreign/foreign.toc
blob: beaa8227ebb592f99868937b7b1c6f75641fc470 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
voidptr ::= &u8;

getstdout ::= fn() voidptr {
	#builtin("stdout")
};


fwrite :: fn(voidptr, u64, u64, voidptr) u64 = #foreign "fwrite", "libc.so.6";
fputc :: fn(i32, voidptr) i32 = #foreign "fputc", "libc.so.6";

writes ::= fn(x : []char) {
	 fwrite(&x[0] as voidptr, 1, x.len as u64, getstdout());
};

puts ::= fn(x : []char) {
	 writes(x);
	 fputc('\n' as i32, getstdout());
};

hw ::= fn() int {
   writes("Hello,");
   if #builtin("compiling") {
   	  writes(" compiling");
   }
   puts(" world!");
   3
};

main ::= fn() {
	 hw();
	 x ::= hw();
};