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#

builtin append(list_or_buffer, value)

append(list_or_buffer, value) returns a new list or buffer with value appended.

args#

builtin args()

args() returns the process argument list.

buf#

builtin buf(size)

buf(size) allocates a mutable byte buffer of the given size.

chan#

builtin chan(capacity)

chan(capacity) creates a channel with the given buffer capacity.

chr#

builtin chr(codepoint)

chr(codepoint) converts a Unicode codepoint to a string character.

del#

builtin del(collection, index_or_key)

del(collection, index_or_key) removes a list element, buffer byte, or map entry.

dlcall#

builtin dlcall(fn, args...)

dlcall(fn, args...) calls a foreign function pointer (FFI).

dlopen#

builtin dlopen(path)

dlopen(path) opens a shared library and returns a handle (FFI).

dlsym#

builtin dlsym(lib, symbol)

dlsym(lib, symbol) resolves a symbol in a shared library (FFI).

env#

builtin env()

env() returns a map of environment variables; env(key) returns a string or nil.

error#

builtin error(message)

error(message) returns an error value with the given message.

help#

builtin 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#

builtin inspect(value)

inspect(value) returns a human-readable string representation.

keys#

builtin keys(map)

keys(map) returns a list of keys in a map.

len#

builtin len(value)

len(value) returns the length of a string, list, map, or buffer.

ord#

builtin ord(char)

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#

builtin platform()

platform() returns the current target as an "os/arch" string, e.g. "linux/amd64".

poll#

builtin poll(channel, timeout_ms?)

poll(channel, timeout_ms?) receives without blocking — or waits up to timeout_ms — answering [ok, value].

pop#

builtin pop(list_or_buffer)

pop(list_or_buffer) removes and returns the last element or byte.

push#

builtin push(channel, value)

push(channel, value) sends without blocking, reporting whether there was room.

recv#

builtin recv(channel)

recv(channel) receives a value, blocking while the channel is empty.

send#

builtin send(channel, value)

send(channel, value) sends a value, blocking while the buffer is full.

str#

builtin str(value)

str(value) converts value to a string.

syscall#

builtin syscall(name_or_number, args...)

syscall(name_or_number, args...) performs a raw OS syscall.

task#

builtin task(fn)

task(fn) starts fn as a concurrent task and returns a handle to wait on.

traceback#

builtin traceback()

traceback() renders the current call stack; traceback(err) renders where err was created.

type#

builtin type(value)

type(value) returns the runtime type tag (e.g. "STRING").

wait#

builtin wait(task)

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.