|
x-engine-c v0.2.13
The C engine for x-lang
|
Interned symbol type – BST index, make, find, and 3-step eval. More...
#include "x-type/symbol.h"#include "x-type/str.h"#include "x-alist.h"#include "x-eval.h"#include "x-env.h"#include "x-token/sexp/symbol.h"Functions | |
| x_obj_t * | x_make_symbol (x_obj_t *p_base, x_obj_flag_t flags, x_char_t *s) |
| x_obj_t * | x_type_symbol_save (x_obj_t *p_base, x_obj_t *p_args) |
| x_obj_t * | x_type_symbol_struct (x_obj_t *p_base, x_obj_t *p_obj) |
| x_obj_t * | x_type_symbol_register (x_obj_t *p_base, x_obj_t *p_args) |
| x_obj_t * | x_type_symbol_make (x_obj_t *p_base, x_obj_t *p_args) |
| x_obj_t * | x_type_symbol_find (x_obj_t *p_base, x_obj_t *p_args) |
| x_obj_t * | x_type_symbol_eval (x_obj_t *p_base, x_obj_t *p_args) |
Symbol Intern BST | |
Index for O(log n) symbol lookup by name. Node layout: | |
| #define | x_symbol_bst(T) x_restobj(x_symbol_data((T))) |
| static x_obj_t * | sym_bst_lookup (x_obj_t *p_base, x_obj_t *p_tree, x_char_t *name) |
| static x_obj_t * | sym_bst_insert (x_obj_t *p_base, x_obj_t *p_tree, x_obj_t *p_sym) |
Interned symbol type – BST index, make, find, and 3-step eval.
| #define x_symbol_bst | ( | T | ) | x_restobj(x_symbol_data((T))) |
Insert a symbol into the BST, returning the (possibly unchanged) root.
If the symbol already exists, the tree is returned unmodified.
| p_base | Base (execution context) (for allocation). |
| p_tree | Current BST root (or NULL for empty tree). |
| p_sym | Symbol object to insert. |
Search the BST for a node whose symbol matches name.
| p_base | Base (execution context). |
| p_tree | BST root node (or NULL). |
| name | Symbol name to find. |
| x_obj_t * x_make_symbol | ( | x_obj_t * | p_base, |
| x_obj_flag_t | flags, | ||
| x_char_t * | s | ||
| ) |
Allocate (or retrieve interned) SYMBOL for string s.
Packs the string and flags into stack-allocated args and delegates to x_type_symbol_make(), which handles interning.
| p_base | Base (execution context). |
| flags | Object flags (e.g. X_OBJ_FLAG_OWN). |
| s | Null-terminated symbol name. |
Evaluate a symbol: the value bound to it in the current environment or an ancestor.
The environment is a chain of (bindings . parent) pairs ending at the root, whose bindings are a tree; x_env_lookup walks it. An unbound symbol is an error naming the symbol.
| p_base | x_obj_t* – Base (execution context) |
| p_args | x_obj_t* – Eval args: (symbol . env) |
Look up an interned symbol by name using the BST index.
| p_base | Base (execution context). |
| p_args | Argument list whose first element wraps the name string. |
Type-system make handler – intern or allocate a new SYMBOL.
If a symbol with the same name already exists, returns the existing interned object. Otherwise allocates a new one, appends it to the intern list, and inserts it into the BST. Ownership of the source string is transferred when the source has X_OBJ_FLAG_OWN set.
Interning sequence:
| p_base | Base (execution context). |
| p_args | Argument list: (name-atom [flags-atom]). |
Register (or retrieve) the SYMBOL type and initialize its data field.
On first call, allocates the intern list and BST root in the type's data slot.
| p_base | Base (execution context). |
| p_args | Unused. |
Build the SYMBOL type struct descriptor.
Populates name, make, eval, analyse, read, write, and display hooks.
| p_base | Base (execution context). |
| p_obj | Unused. |
Build the SYMBOL type struct descriptor.
| x_satom_t x_type_symbol_eval_prim = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { (x_obj_t *)&x_type_symbol_eval }) |
| x_satom_t x_type_symbol_make_prim = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { (x_obj_t *)&x_type_symbol_make }) |
| x_satom_t x_type_symbol_name = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { .s = (x_char_t *)X_TYPE_SYMBOL_NAME }) |
| x_satom_t x_type_symbol_save_prim = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { (x_obj_t *)&x_type_symbol_save }) |
| x_satom_t x_type_symbol_struct_prim = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { (x_obj_t *)&x_type_symbol_struct }) |