|
x-engine-c v0.2.13
The C engine for x-lang
|
Base environment object – the root context for evaluation. More...
#include "x-obj.h"Go to the source code of this file.
Data Structures | |
| struct | x_base_t |
Functions | |
Base Functions | |
| x_obj_t * | x_base_make (x_obj_t *p_base, struct x_base_t base) |
| x_obj_t * | x_base_read (x_obj_t *p_base, x_obj_t *p_args) |
| x_obj_t * | x_base_write (x_obj_t *p_base, x_obj_t *p_args) |
Base environment object – the root context for evaluation.
The base object is a nested pair tree that holds I/O descriptors, profiling counters, extensible hook functions, and heap/GC state. Field accessor macros navigate this tree without hard-coding offsets.
Every leaf field is stored as a pair – its field cell: (current-value . saved-values). Fields are initialized with (value . nil). Any field can be used as a stack via x_obj_push() / x_obj_pop() to save and restore values. ("Field cell" always means this slot; a plain "cell" is a cons cell, see x-lisp.h.) To read a field's current value, use x_firstobj(field) then extract the appropriate datum (e.g. x_atomint() for integers). To temporarily override a field (e.g. redirect I/O for a nested scope), push a new value before entering the scope and pop it on exit.
The tree has three extension points (marked below) where downstream projects can attach additional state: env+ctrl for environment bindings, type-alist for type dispatch tables, and io-state for I/O subsystem extensions. These start as nil.
., .,
{O,O}
( )
" "
| #define x_base | ( | X | ) | x_firstobj(X) |
Get the root data of the base object X.
| #define x_base_isset | ( | B | ) | ((B) != NULL && x_base((B)) != NULL) |
Test whether the base object B is initialized and has data.
Create a new base environment object.
Create a new base environment object.
Allocates and assembles the nested pair tree that holds all environment state. Every node is allocated with X_OBJ_FLAG_SHARED (via the local pair/atom macros) so the base tree is immune to garbage collection. Each leaf value is wrapped as pair(atom(value), nil) to form a one-element field stack (see x-base.h). Hook values passed as NULL produce (nil . nil) leaves (hook disabled). The tree layout matches the field accessor macros: x_base_field_filein() navigates to the filein leaf, x_base_field_hook_type_name() to the type_name hook, etc.
| p_base | Existing base for allocation context, or NULL for bootstrap. |
| base | Initialization parameters (file descriptors, hooks, etc.). |
Read data from the base's input file descriptor.
Read data from the base's input file descriptor into an atom.
Uses the filein descriptor from the base environment, or falls back to STDIN_FILENO if the base is not initialized.
| p_base | Base (execution context). |
| p_args | Pair list: (destination-atom byte-count). |
Write data to the base's output file descriptor or write buffer.
Write data from an atom to the base's output or write buffer.
Checks the write_buf field first: if it holds a non-nil pair (pointer . position), data is memcpy'd into the buffer at the current position and the position is advanced. Otherwise, writes to the fileout file descriptor, falling back to STDOUT_FILENO if the base is not initialized.
| p_base | Base (execution context). |
| p_args | Pair list: (source-atom byte-count). |