Skip to content
Built-ins

Built-ins

The compiler provides these functions itself. Their names are reserved.

Safe

FunctionResultMeaning
halt(status: int)neverEnds the program with that exit status.
len(b: bytes)intThe number of bytes in b.

Raw

The raw_ functions work on memory addresses and the operating system directly. Nothing checks their arguments. A wrong address or length ends the program without a message, or corrupts it. The last chapter of the guide explains when they are appropriate.

FunctionResultMeaning
raw_alloc(length: int)bytesNew bytes of that length, all zero. A zero byte follows the last one, so the address can be passed to the kernel as a C string.
raw_addr(b: bytes)intThe address of the first byte of b.
raw_peek(address: int)intThe byte at that address, 0 to 255.
raw_poke(address: int, value: int)intWrites the lowest eight bits of value at that address. Returns value.
raw_word(address: int)intThe 64-bit value at that address.
raw_store(address: int, value: int)intWrites value as 64 bits at that address. Returns value.
raw_copy(from: int, to: int, count: int)intCopies count bytes from one address to another. Returns 0.
raw_kernel_call(number: int, a: int, b: int, c: int, d: int, e: int, f: int)intMakes a Linux system call with six arguments and returns the kernel’s answer. A negative answer is an error code.
raw_args()intThe address of the argument count the kernel left on the stack. The argument pointers follow it.
raw_heap_mark()intThe current end of the program’s heap.
raw_heap_reset(mark: int)intGives back everything allocated since mark was taken and fills it with zeros. Returns 0.

Memory

Records, union values and bytes live on a heap that only grows. Nothing is freed while a program runs, except by raw_heap_reset.

After raw_heap_reset(mark), every value made since that mark is gone, and using one is an error the language cannot detect. Call it only from code that knows nothing made after the mark is still needed.