builtins
host builtin internal/builtins
The host builtin table: the capabilities mu cannot express in mu.
A capability earns a place here only when it needs the kernel, raw memory, the loader, the scheduler, the runtime type tag, or a mutation mu has no other way to perform. Every entry is implemented four times over -- Go interpreter, Go native, self-hosted interpreter, self-hosted native -- so the table is kept deliberately small.
These names are always in scope. There is nothing to import.
Builtins
append#
append(list_or_buffer, value) returns a new list or buffer with value appended.
args#
args() returns the process argument list.
buf#
buf(size) allocates a mutable byte buffer of the given size.
chan#
chan(capacity) creates a channel with the given buffer capacity.
chr#
chr(codepoint) converts a Unicode codepoint to a string character.
del#
del(collection, index_or_key) removes a list element, buffer byte, or map entry.
dlcall#
dlcall(fn, args...) calls a foreign function pointer (FFI).
dlopen#
dlopen(path) opens a shared library and returns a handle (FFI).
dlsym#
dlsym(lib, symbol) resolves a symbol in a shared library (FFI).
env#
env() returns a map of environment variables; env(key) returns a string or nil.
error#
error(message) returns an error value with the given message.
help#
help() shows general Mu help. help(value) shows docstrings for modules/functions. Both VMs answer it; a native build carries no docstrings, so there it does nothing.
inspect#
inspect(value) returns a human-readable string representation.
keys#
keys(map) returns a list of keys in a map.
len#
len(value) returns the length of a string, list, map, or buffer.
ord#
ord(char) returns the code point of a one-character string: a one-byte string gives its byte value, and a 2-4 byte string is decoded as one UTF-8 sequence. chr is its inverse, so ord(chr(n)) == n.
platform#
platform() returns the current target as an "os/arch" string, e.g. "linux/amd64".
poll#
poll(channel, timeout_ms?) receives without blocking — or waits up to timeout_ms — answering [ok, value].
pop#
pop(list_or_buffer) removes and returns the last element or byte.
push#
push(channel, value) sends without blocking, reporting whether there was room.
recv#
recv(channel) receives a value, blocking while the channel is empty.
send#
send(channel, value) sends a value, blocking while the buffer is full.
str#
str(value) converts value to a string.
syscall#
syscall(name_or_number, args...) performs a raw OS syscall.
task#
task(fn) starts fn as a concurrent task and returns a handle to wait on.
traceback#
traceback() renders the current call stack; traceback(err) renders where err was created.
type#
type(value) returns the runtime type tag (e.g. "STRING").
wait#
wait(task) blocks until the task finishes and returns its result.
Internal helpers
Underscore-prefixed names are implementation detail. They are listed so the module's source reads without surprises, not as API — they may change at any time.
| __code_make(kind, fields) | __code_make(kind, fields) builds a code value from a node kind and its fields. |
| __macro_define(name, handler) | __macro_define(name, handler) registers a macro handler during expansion. |
| __mu_test_register(name) | __mu_test_register(name) records a test case while mu -test runs a file. |
| __mu_test_signal_failure(message) | __mu_test_signal_failure(message) marks the running test as failed instead of exiting. |