Built-ins
Built-ins
The compiler provides these functions itself. Their names are reserved.
Safe
| Function | Result | Meaning |
|---|---|---|
halt(status: int) | never | Ends the program with that exit status. |
len(b: bytes) | int | The 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.
| Function | Result | Meaning |
|---|---|---|
raw_alloc(length: int) | bytes | New 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) | int | The address of the first byte of b. |
raw_peek(address: int) | int | The byte at that address, 0 to 255. |
raw_poke(address: int, value: int) | int | Writes the lowest eight bits of value at that address. Returns value. |
raw_word(address: int) | int | The 64-bit value at that address. |
raw_store(address: int, value: int) | int | Writes value as 64 bits at that address. Returns value. |
raw_copy(from: int, to: int, count: int) | int | Copies 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) | int | Makes a Linux system call with six arguments and returns the kernel’s answer. A negative answer is an error code. |
raw_args() | int | The address of the argument count the kernel left on the stack. The argument pointers follow it. |
raw_heap_mark() | int | The current end of the program’s heap. |
raw_heap_reset(mark: int) | int | Gives 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.