|
x-engine-c v0.2.13
The C engine for x-lang
|
Association list and persistent BST operations. More...
Functions | |
| x_obj_t * | x_alist_extend (x_obj_t *p_base, x_obj_t *p_args) |
| x_obj_t * | x_alist_assoc (x_obj_t *p_base, x_obj_t *p_args) |
| x_obj_t * | x_alist_bst_lookup (x_obj_t *p_base, x_obj_t *p_tree, x_obj_t *p_sym) |
| static x_obj_t * | bst_pair (x_obj_t *p_base, x_obj_t *a, x_obj_t *b) |
| x_obj_t * | x_alist_bst_insert (x_obj_t *p_base, x_obj_t *p_tree, x_obj_t *p_entry) |
Association list and persistent BST operations.
Create a SHARED pair immune to GC sweep.
BST nodes are structural – the global env tree lives for the base's lifetime and is reachable only through this tree, so its nodes must not be collected.
| p_base | x_obj_t* – Base (execution context) |
| a | x_obj_t* – First element |
| b | x_obj_t* – Rest element |
Linear alist lookup by pointer identity on the key's first field.
Walks the alist front-to-back, comparing (first (first (first entry))) against (first obj). Returns the first matching entry, or NULL.
| p_base | x_obj_t* – Base (execution context) |
| p_args | x_obj_t* – (key . (alist)) |
In-place BST insert into the global env tree.
MUTATES the tree in place; every environment whose chain reaches the root sees the new entry, which is required: a top-level (def ...) must become visible to fn closures created before it. The key is the symbol object: an entry for the SAME object replaces the old one, and an entry for a same-spelled but different object – one interned in another base – is another name and gets its own node, to the right of the first, the side lookup takes for an equal spelling that is not the same object. The returned root equals the input root except when the tree was empty (the caller must then store the returned first node).
| p_base | x_obj_t* – Base (execution context) |
| p_tree | x_obj_t* – Existing BST root, or NULL for empty |
| p_entry | x_obj_t* – (symbol . value) entry to insert |
p_tree was empty)BST lookup by symbol identity.
Searches the tree for the entry whose key IS p_sym. A hit is pointer equality and nothing else: names are found by identity, not by spelling, so a same-spelled symbol interned in another base is another name and misses. The spelling only steers the walk – smaller to the left, greater to the right, and an equal spelling that is not the same object counts as greater, which is where x_alist_bst_insert put it. Node structure: (entry . (left . right)).
| p_base | x_obj_t* – Base (execution context) |
| p_tree | x_obj_t* – BST root node, or NULL |
| p_sym | x_obj_t* – Symbol to look up |
Prepend an association to an alist.
Conses p_assoc onto the front of p_alist, returning the new list.
| p_base | x_obj_t* – Base (execution context) |
| p_args | x_obj_t* – (assoc . alist) |