summaryrefslogtreecommitdiff
path: root/std/base.toc
blob: 950f817d15b225b2378289d93df072396ef15815 (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
33
34
35
36
37
38
39
PLATFORM_OTHER ::= 0;
PLATFORM_LINUX ::= 1;
PLATFORM_WINDOWS ::= 2;
PLATFORM_OSX ::= 3;
PLATFORM_FREEBSD ::= 4;
PLATFORM_OPENBSD ::= 5;
PLATFORM_MISC_UNIX ::= 6;

PLATFORM ::= #builtin("platform");
#if PLATFORM == PLATFORM_LINUX {
	libc ::= "libc.so.6";
} elif PLATFORM == PLATFORM_WINDOWS {
	libc ::= "msvcrt.dll";
} elif PLATFORM == PLATFORM_OSX {
	libc ::= "libc.dylib";
} elif PLATFORM == PLATFORM_FREEBSD || PLATFORM == PLATFORM_OPENBSD {
	libc ::= "libc.so";
} else {
	/* maybe it's non-linux gnu? */
	libc ::= "libc.so.6";
}

PLATFORM_IS_UNIX :: bool = PLATFORM == PLATFORM_LINUX || PLATFORM == PLATFORM_OSX || PLATFORM == PLATFORM_FREEBSD
	|| PLATFORM == PLATFORM_OPENBSD || PLATFORM == PLATFORM_MISC_UNIX;

fwrite ::= #foreign("fwrite", libc) fn(#C &"const void", #C size_t, #C size_t, &void) #C size_t;
stderr_write ::= fn(s: []char) {
	fwrite(&s[0], 1, s.len as #C size_t, #builtin("stderr"));
}

exit ::= #foreign("exit", libc) fn(#C int);

error ::= fn(s: []char) {
	stderr_write("Fatal error: ");
	stderr_write(s);
	// @TODO: backtrace
	stderr_write("\nExiting.\n");
	exit(1);
}