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); }