Public embedding functions
These signatures are from atom.h. When a call returns AtomStatus, check it before using output slots. Status values are ATOM_OK, ATOM_SYNTAX_ERROR, ATOM_COMPILE_ERROR, ATOM_BYTECODE_ERROR, ATOM_RUNTIME_ERROR, ATOM_INTERRUPTED, ATOM_LIMIT, ATOM_NO_MEMORY and ATOM_IO_ERROR.
| Signature | Behavior |
|---|---|
AtomVM *atom_vm_new(const AtomConfig *config) |
Creates a configured VM or returns NULL on setup failure. |
void atom_vm_free(AtomVM *vm) |
Tears down the VM, cancelling and joining its workers and releasing its registered execution resources. Null is accepted. Release native handles and roots explicitly when finished. |
const AtomDiagnostic *atom_diagnostic(const AtomVM *vm) |
Returns a borrowed diagnostic with status, filename, line, column, message and trace, or NULL for a null VM. Copy fields to retain them across later VM operations. |
AtomStatus atom_error(AtomVM *vm, const char *message) |
Records and returns a runtime error for a native callback. |
void atom_interrupt(AtomVM *vm) |
Requests interruption of the active execution, including calls that poll for cancellation. May be called from another thread while the VM is live. |
void atom_collect(AtomVM *vm) |
Requests collector work for non-null VM. The collector is process-wide. |
void atom_set_heap_limit(size_t bytes) |
Sets the process-wide collector heap growth limit. Zero removes the limit. |
size_t atom_vm_heap_bytes(const AtomVM *vm) |
Reports charged bytes for the current VM budget, or zero for an unmetered/null VM. |
void atom_profile_enable(AtomVM *vm, bool enabled) |
Toggles execution counters. Enabling from disabled resets counters except JIT compilation count. |
bool atom_profile_read(const AtomVM *vm, AtomProfile *profile) |
Copies profile fields, returning false for null input or destination. See runtime.profile for the fields. |
bool atom_thread_attach(void) |
Registers a host-created thread with the collector, including already registered threads. False means the thread setup failed. |
void atom_thread_detach(void) |
Detaches a thread registered by Atom's attach call. |
AtomStatus atom_packed_bytes(AtomVM *vm, AtomValue packed, void **bytes, size_t *length) |
Borrows writable packed bytes and size. Keep the value live. Storage relocation or invalidation can invalidate the pointer. The API does not pin the span. |
AtomStatus atom_compile(AtomVM *vm, const AtomSource *source, AtomProgram **program) |
Compiles UTF-8 source to a rooted program handle. Caller frees it. |
AtomStatus atom_decode(AtomVM *vm, const void *bytes, size_t length, AtomProgram **program) |
Validates and decodes serialized bytecode to a program handle. Caller frees it. |
void atom_program_free(AtomProgram *program) |
Releases the caller's program handle. Null is accepted. |
AtomStatus atom_encode(const AtomProgram *program, AtomWrite write, void *context) |
Writes versioned bytecode through the sink. |
AtomStatus atom_disassemble(const AtomProgram *program, AtomWrite write, void *context) |
Streams a human-readable bytecode listing. |
AtomStatus atom_run(AtomVM *vm, const AtomProgram *program, AtomValue *result) |
Executes a compiled/decoded program. An explicit return gives its value, otherwise the result is an export namespace. Pass NULL to ignore result. |
AtomStatus atom_eval(AtomVM *vm, const AtomSource *source, AtomValue *result) |
Compiles and runs source, then frees the temporary program handle. |
AtomStatus atom_eval_interactive(AtomVM *vm, const AtomSource *source, AtomValue *result) |
Runs source with persistent interactive bindings and returns the interactive result. |
AtomStatus atom_format_source(AtomVM *vm, const AtomSource *source, AtomWrite write, void *context) |
Formats source and emits it through the sink. |
bool atom_source_continues(AtomVM *vm, const AtomSource *source) |
Checks whether the REPL should read additional source. |
AtomStatus atom_write_value(AtomValue value, AtomWrite write, void *context) |
Sends the display representation through a sink. |
AtomStatus atom_call(AtomVM *vm, AtomValue function, size_t argc, const AtomValue *argv, AtomValue *result) |
Calls an Atom function with positional values. Pass NULL result to discard it. |
AtomValue atom_null(void) |
Constructs null. |
AtomValue atom_bool(bool value) |
Constructs a boolean. |
AtomValue atom_int(int64_t value) |
Constructs an i64. |
AtomValue atom_uint(uint64_t value) |
Constructs a u64. |
AtomValue atom_float(double value) |
Constructs an f64. |
AtomStatus atom_char(uint32_t scalar, AtomValue *result) |
Constructs a char if the scalar is valid Unicode. |
AtomStatus atom_string(const char *bytes, size_t length, AtomValue *result) |
Validates and copies UTF-8 into an Atom string, even for one scalar. |
bool atom_string_bytes(AtomValue value, const char **bytes, size_t *length) |
Borrows a string's byte span and length. Returns false for nonstrings. Either output may be omitted. Keep the string live. |
AtomStatus atom_array(AtomValue *result) |
Creates an empty array. |
AtomStatus atom_dict(AtomValue *result) |
Creates an empty dictionary. |
AtomStatus atom_get(AtomVM *vm, AtomValue collection, AtomValue key, AtomValue *result) |
Performs the runtime's indexed access. |
AtomStatus atom_set(AtomVM *vm, AtomValue collection, AtomValue key, AtomValue value) |
Performs the runtime's indexed assignment. |
AtomStatus atom_append(AtomVM *vm, AtomValue collection, AtomValue value) |
Appends to a sequential mutable collection, including a growable packed array. |
AtomStatus atom_register(AtomVM *vm, const char *name, AtomNative call, void *context) |
Registers a native callable as a VM builtin. Keep native code and callback context valid while callable. |
AtomStatus atom_register_module(AtomVM *vm, const char *name, AtomValue exports) |
Registers a dictionary/module under a name accessible through unquoted use. |
AtomStatus atom_module_get(AtomVM *vm, AtomValue module, const char *name, AtomValue *result) |
Reads a named export, yielding null for a missing member. |
AtomRoot *atom_root_new(AtomValue value) |
Allocates a GC-visible host root, returning NULL on failure. |
AtomValue atom_root_get(const AtomRoot *root) |
Reads a root's value, or null for a null root. |
void atom_root_set(AtomRoot *root, AtomValue value) |
Replaces the reference held by a live root. |
void atom_root_free(AtomRoot *root) |
Releases a root. Free each acquired root once. |