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

Part 2: Core Intrinsics

Intrinsics are built-in operations that compile to target-specific instructions. They are called like functions but are handled specially by the compiler.

2.1 Memory Operations

These intrinsics provide direct memory access:

IntrinsicDescription
__load__(addr)Shorthand for __load_u64__(addr)
__load_u8__(addr)Load unsigned 8-bit value from addr, zero-extend to 64-bit
__load_u16__(addr)Load unsigned 16-bit value from addr, zero-extend to 64-bit
__load_u32__(addr)Load unsigned 32-bit value from addr, zero-extend to 64-bit
__load_u64__(addr)Load unsigned 64-bit value from addr
__load_i8__(addr)Load signed 8-bit value from addr, sign-extend to 64-bit
__load_i16__(addr)Load signed 16-bit value from addr, sign-extend to 64-bit
__load_i32__(addr)Load signed 32-bit value from addr, sign-extend to 64-bit
__load_i64__(addr)Load signed 64-bit value from addr
__store__(val addr)Shorthand for __store_u64__(val addr)
__store_u8__(val addr)Store low 8 bits of val to addr, return 0
__store_u16__(val addr)Store low 16 bits of val to addr, return 0
__store_u32__(val addr)Store low 32 bits of val to addr, return 0
__store_u64__(val addr)Store 64-bit val to addr, return 0
__store_i8__(val addr)Store low 8 bits of val to addr, return 0
__store_i16__(val addr)Store low 16 bits of val to addr, return 0
__store_i32__(val addr)Store low 32 bits of val to addr, return 0
__store_i64__(val addr)Store 64-bit val to addr, return 0
__alloca__(size)Allocate size bytes of temporary storage and return an 8-byte-aligned address
__static_alloca__(size)Allocate size bytes of writable static storage and return its address
__static_words__(word...)Intern one or more compile-time stable 64-bit words and return their 8-byte-aligned static address

Signed and unsigned 64-bit loads/stores are identical at runtime; both spellings exist to make programmer intent explicit. __load__/__store__ are convenience shorthands for the unsigned 64-bit forms. For stores, signedness affects only intent and documentation; the stored bit pattern is the low N bits of val.

__alloca__(size) reserves temporary storage whose lifetime lasts until the current function returns. The returned address is aligned to at least 8 bytes, and native backends may round the reserved size up further to preserve ABI stack alignment. Native backends typically implement this with function-local stack storage; the wasm backend uses a function-scoped stack region in linear memory.

__static_alloca__(size) reserves writable storage in the program's static data area. The storage is zero-initialized, has a single shared instance for the entire program, and is not tied to any function call frame. Its size argument must be a compile-time stable integer value, which may be provided directly as a number literal or indirectly through a const binding or backend-provided builtin constant.

__static_words__(word...) creates writable static storage initialized with one or more compile-time stable words. Accepted values are integer literals and stable aliases, non-extern function references, ordinary or based string pointers, and pointers returned by __static_alloca__ or another __static_words__ call. The result points directly to the first word: there is no length prefix, element type, bounds information, or array behavior.

const handlers:int = __static_words__(on_start on_update on_stop)
let handler:int = __load__(handlers + state * 8)
(@handler)(context)

Integer entries use the target's native 64-bit byte order. References use the backend's normal runtime representation: addresses on native and C targets, linear-memory addresses for WASM data, and WASM function-table indices for functions. This makes __static_words__ suitable for vtables, lookup tables, and ABI descriptors interpreted by the consumer. Use based strings instead when the bytes must be identical across targets.