Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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

FunctionArgumentsDescription
rt_writefd data sizeWrite size bytes from data to file descriptor fd
rt_exitcodeExit the program with the given exit code
rt_allocatesizeAllocate size bytes on the heap, returns fat pointer
rt_storectx value size offsetWrite value to memory at offset
rt_load_u64ctx offsetRead a 64-bit value from memory at offset
rt_mmapaddr size prot flags fd offRaw mmap syscall
rt_syscallvariesRaw 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)
  }
}