|
x-engine-c v0.2.13
The C engine for x-lang
|
Interned symbol type with BST-accelerated lookup. More...
#include "x-type.h"Go to the source code of this file.
Macros | |
| #define | X_TYPE_SYMBOL_NAME "SYMBOL" |
Predicates | |
| #define | x_obj_type_issymbol(B, X) x_obj_is_type((B), (X), X_TYPE_SYMBOL_NAME) |
Accessors | |
| #define | x_symbolval(X) x_firststr((X)) |
| #define | x_symbolname(X) x_firststr((X)) |
Type Data Accessors | |
| #define | x_symbol_data x_type_field_data |
| #define | x_symbol_data_list(X) x_0(x_symbol_data((X))) |
Constructors | |
| #define | x_mksymbol(B, S) x_make_symbol((B), X_OBJ_FLAG_NONE, (S)) |
| #define | x_mkfsymbol(B, F, S) x_make_symbol((B), (F), (S)) |
| #define | x_mksymbolown(B, S) x_make_symbol((B), X_OBJ_FLAG_OWN, (S)) |
| #define | x_mkfsymbolown(B, F, S) x_make_symbol((B), X_OBJ_FLAG_OWN | (F), (S)) |
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_struct (x_obj_t *p_base, x_obj_t *p_args) |
| x_obj_t * | x_type_symbol_register (x_obj_t *p_base, x_obj_t *p_args) |
| x_obj_t * | x_type_symbol_init (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) |
| x_obj_t * | x_type_symbol_write (x_obj_t *p_base, x_obj_t *p_args) |
Interned symbol type with BST-accelerated lookup.
Symbols are atom objects keyed by their string name. All symbols with the same name share the same object (interning), which enables fast pointer-identity comparison during evaluation. An internal BST index provides O(log n) lookup by name.
| #define x_mkfsymbol | ( | B, | |
| F, | |||
| S | |||
| ) | x_make_symbol((B), (F), (S)) |
Intern or create a symbol with explicit flags.
| #define x_mkfsymbolown | ( | B, | |
| F, | |||
| S | |||
| ) | x_make_symbol((B), X_OBJ_FLAG_OWN | (F), (S)) |
Intern or create an owning symbol with extra flags.
| #define x_mksymbol | ( | B, | |
| S | |||
| ) | x_make_symbol((B), X_OBJ_FLAG_NONE, (S)) |
Intern or create a symbol with default flags.
| #define x_mksymbolown | ( | B, | |
| S | |||
| ) | x_make_symbol((B), X_OBJ_FLAG_OWN, (S)) |
Intern or create an owning symbol.
| #define x_obj_type_issymbol | ( | B, | |
| X | |||
| ) | x_obj_is_type((B), (X), X_TYPE_SYMBOL_NAME) |
Test whether X is a SYMBOL object.
| #define x_symbol_data x_type_field_data |
Access the type-level data field for the SYMBOL type.
| #define x_symbol_data_list | ( | X | ) | x_0(x_symbol_data((X))) |
Get the interned symbol list from the type data.
| #define x_symbolname | ( | X | ) | x_firststr((X)) |
Alias for x_symbolval – get the symbol's name.
| #define x_symbolval | ( | X | ) | x_firststr((X)) |
Get the symbol's string value.
| #define X_TYPE_SYMBOL_NAME "SYMBOL" |
Canonical type name.
| 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.
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. |
Type-system eval handler – 3-step environment lookup.
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 (BST-accelerated).
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. |
Initialize the SYMBOL type's intern table.
Type-system make handler – intern or allocate a new SYMBOL.
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 init its data field.
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.