Directives
Directives are compiler attributes that declare runtime functions. They are placed before machines.
@rt — Runtime Function
Binds a name to a built-in runtime function:
@rt(rt_write)
After this declaration, rt_write can be called directly from any branch. Unlike machine calls, runtime function calls do not spawn a new process — they execute inline.
Available Runtime Functions
| Function | Arguments | Description |
|---|---|---|
rt_write | fd data size | Write size bytes from data to file descriptor fd |
rt_exit | code | Exit the program with the given exit code |
rt_allocate | size | Allocate size bytes on the heap, returns fat pointer |
rt_store | ctx value size offset | Write value to memory at offset |
rt_load_u64 | ctx offset | Read a 64-bit value from memory at offset |
rt_mmap | addr size prot flags fd off | Raw mmap syscall |
rt_syscall | varies | Raw syscall wrapper |
Common Usage
Writing to stdout:
@rt(rt_write)
main is {
_ i64.0 -> {
rt_write(1 "hello, lake!\n" 14)
}
}
The arguments to rt_write are: file descriptor (1 = stdout), string data, and byte length.
Placement
Directives are placed at the top of the file, before any machine definitions:
@rt(rt_write)
counter is {
n i64 -> {
when 0 == n {
true -> { rt_write(1 "done\n" 5) }
false -> { self(n-1) }
}
}
}
main is {
_ i64.0 -> {
counter(5)
}
}