Skip to content

freestanding

Freestanding program: no GC, no std, compiled with LLVM to a tiny static binary.

Returning from _start exits the process with that value. sys holds the syscall numbers of the machine it is built for (lib/sys.x86_64.jh or lib/sys.aarch64.jh).

Terminal window
jihoo build examples/freestanding.jh -o out/hello && ./out/hello; echo $?
examples/freestanding.jh
#![freestanding]
import sys
fn write(fd: i64, buf: *u8, len: i64) -> i64 {
return syscall(sys.WRITE, fd, buf, len)
}
fn fib(n: i64) -> i64 {
if n < 2 {
return n
}
return fib(n - 1) + fib(n - 2)
}
fn _start() -> i64 {
write(1, "Hello from freestanding jihoo!\n", 31)
return fib(10)
}

View on GitHub