|
x-engine-c v0.2.13
The C engine for x-lang
|
Primitive function infrastructure and registration. More...
Go to the source code of this file.
Data Structures | |
| struct | x_callable_entry_t |
| struct | x_prim_entry_t |
Variables | |
| static void x_obj_t * | p_args |
| static void x_obj_t int | count |
| static void x_obj_t int int | i |
| int | held = 0 |
| x_obj_t ** | p_cell = x_heap_root_slot(p_base) |
| x_spair_t | roots [2] |
Primitive function infrastructure and registration.
Declares the callable binding mechanism used to register C primitives into the x-lang environment, argument unpacking helpers, body/TCO evaluation entry points, and the per-module register functions.
| void x_callcc_init | ( | void | ) |
Initialize the call/cc subsystem.
Establish the stack base address for continuation capture.
Must be called once at interpreter startup, from a frame close to the bottom of the C call stack (typically main). The address of a local variable is recorded as the upper bound of all future stack captures.
Register arithmetic primitives (+, -, *, /, %, ~, &, |, ^, <<, >>).
Register arithmetic primitives into the environment.
Binds: +, -, *, /, %, ~, &, |, ^, <<, >>
| p_base | x_obj_t* – Base (execution context) |
| p_args | x_obj_t* – Unused |
Register the sandbox base primitives (make-base, base-eval, etc.).
Register the sandbox base primitives.
Register the buffer/tokenizer primitives.
Register the buffer and tokenizer primitives.
Register call/cc continuation primitives.
Register continuation primitives.
Binds: cc-invoke, call/cc.
| p_base | Interpreter base context. |
| p_args | Unused. |
p_base. Register core primitives (pair, first, rest, apply, eval, eval!, tail-eval, wrap, unwrap, atomic, base).
Register core primitives into the environment.
Binds: pair, first, rest, apply, eval, eval!, tail-eval, wrap, unwrap, atomic, base.
| p_base | Base (execution context). |
| p_args | Unused. |
Register all FFI primitives and platform constants.
Register FFI primitives (dlopen, dlsym, ffi-call, ptr-call, int->ptr/ptr->int, mem-*, ptr-*).
Binds: dlopen, dlsym, ffi-call, ptr-call, int->ptr, ptr->int, ptr->obj, ptr-set!, ptr-ref, ptr-ref-word, ptr-set-word!, obj->ptr, str->ptr, ptr->str, make-callable. (The obj-meta-* accessors are pure x-lang now: boot/reflect.x files reflective implementations into the catalog over tools/contract/obj-layout.x and tools/contract/base-paths.x.)
Platform constants live in X, not here: word size is probed by boot/data.x, and the O_* open flags come from the per-OS tables in x/platform/syscall.x.
| p_base | Base (execution context) to bind primitives into. |
| p_args | Unused. |
p_base. Register the GC primitives (heap-*, alloc-limit!, gc-pin!).
Register the GC primitives.
Register the state-image primitives (image save!, image rebuild!).
Register the state-image primitives.
Register I/O and heap primitives (write-str, read, read-char, clock, repl-read, heap-collect/-mark/-sweep/-count, alloc-limit!, heap-*-hook!, gc-pin!).
Register I/O primitives into the environment.
Binds: write-str, read, read-char, heap-mark, heap-sweep, heap-count, gc-pin!, repl-read. Conditionally binds clock (when X_SYS_CLOCK defined). (The printers – write, display, write-to-str, display-to-str – and error-line are pure x-lang now: boot/printer.x renders over the (io write-str) OUT door; boot/reflect.x walks the error handler.)
| p_base | Base (execution context). |
| p_args | Unused. |
Register the iterator primitives.
Apply a single-arg type handler through the prim ABI (shared by the buffer and iter primitives).
Evaluate one argument and pass it as a 1-element list to a type operation.
The argument list is built on the stack (no heap allocation), so these wrappers stay safe inside reader/tokenizer callbacks. C primitives receive unevaluated args, hence the explicit x_eargs before delegating.
| p_base | Base (execution context). |
| p_args | Unevaluated: (self obj). |
| op | The type operation to drive with the evaluated object. |
Register predicate primitives (same?, eq?, =, <, char->integer, integer->char).
Register predicate and type-conversion primitives.
Binds: same?, eq?, =, <, char->integer, integer->char.
| p_base | Interpreter base context. |
| p_args | Unused. |
p_base. Register all primitive modules into the base environment.
Register all built-in primitives into the environment.
Binds the #t and #f boolean singletons, caches them in the base object, then delegates to each primitive module's register function (core, quote, binding, closure, control, arith, pred, string, io, type, ffi, callcc).
| p_base | x_obj_t* – Base (execution context) |
| p_args | x_obj_t* – Unused |
Minimal C read-eval loop (no output, no hooks).
Minimal read-eval loop: reads and evaluates expressions until EOF.
| p_base | Base (execution context). |
| p_args | Unused. |
Register string primitives (str-append, make-str, str->symbol, symbol->str, bytes->str, str-byte-len/-ref/-sub).
Register string manipulation primitives.
Binds: str-append, str->symbol, symbol->str, bytes->str, str-byte-len, str-byte-ref, str-byte-sub.
bytes->str is the raw byte-packer (one low byte per char). The code-point-aware list->str is pure x-lang (x/type/str-utf8), UTF-8 encoding each char on top of bytes->str; boot-time callers that want bytes call bytes->str directly.| p_base | Interpreter base context. |
| p_args | Unused. |
p_base. | x_obj_t * x_prim_type_build_struct | ( | x_obj_t * | p_base, |
| x_obj_t * | p_name_atom, | ||
| x_obj_t * | p_handlers | ||
| ) |
Build a type struct from a handlers alist.
Build a type pair-tree from a name atom and handler alist (shared by make-type and base-make-type).
Iterates a table of known handler field names (call, eval, write, display, length, analyse, delimit, read, error, from, to, units, free, mark, iter), looks each up in p_handlers via alist association, and populates the corresponding x_type_t slot.
| p_base | Base (execution context) used for symbol lookup and allocation. |
| p_name_atom | Atom for the type name. |
| p_handlers | Alist mapping handler name symbols to closures. |
Register all type-system and sandboxing primitives.
Register the type/base/buffer/token/iter primitives (make-type, make-instance, type?, type-of, make-base, base-eval, token-read, buffer-*, make-iter, iter-*).
Binds: make-type, base-make-type, make-instance, make-obj, type?, type-of, buffer-token, make-token-base, make-base, base-eval, base-bind, token-read, token-read-string. ((iter new) is pure x-lang now: boot/reflect.x dispatches the type tree's iter handler over the layout contracts.) (obj-ref / obj-set! / type-name are pure x-lang now: boot/data.x + boot/reflect.x implement them reflectively over the layout contracts.) ((obj retag!) is pure x-lang too: boot/reflect.x writes the type header slot over the layout contract – retired from C by the #101 ruling.)
| p_base | Base (execution context) to bind primitives into. |
| p_args | Unused. |
p_base.