|
x-engine-c v0.2.13
The C engine for x-lang
|
Type struct construction, dispatch, and GC hooks for the type system. More...
#include "x-type.h"#include "x-eval.h"#include "x-heap.h"#include "x-obj.h"#include "x-type/prim.h"#include "x-type/symbol.h"#include "x-type/int.h"Macros | |
| #define | nil NULL |
| #define | pair(X, Y) (x_mkspair(p_base, X_OBJ_FLAG_NONE, (X), (Y))) |
| #define | atom(X) (x_mksatom(p_base, X_OBJ_FLAG_NONE, (X))) |
Variables | |
| x_satom_t | x_type_save_default_prim = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { (x_obj_t *)&x_type_save_default }) |
Type struct construction, dispatch, and GC hooks for the type system.
| #define atom | ( | X | ) | (x_mksatom(p_base, X_OBJ_FLAG_NONE, (X))) |
| #define nil NULL |
| #define pair | ( | X, | |
| Y | |||
| ) | (x_mkspair(p_base, X_OBJ_FLAG_NONE, (X), (Y))) |
GC free hook for typed heap objects.
If the object's type has a free callback, invokes it to release type-specific resources before the heap cell is reclaimed.
| p_base | x_obj_t* – Base (execution context) |
| p_obj | x_obj_t* – Object being freed |
| x_obj_t * x_type_heap_mark | ( | x_obj_t * | p_base, |
| x_obj_t * | p_obj, | ||
| x_obj_flag_t | flags | ||
| ) |
GC mark hook for typed heap objects.
For child base objects (type == x_eval_obj), returns the data pointer so the GC traverses the base's pair tree. For custom types, calls the type's mark callback if present. Otherwise falls back to a generic N-slot traversal using the units count.
| p_base | x_obj_t* – Base (execution context) |
| p_obj | x_obj_t* – Object being marked |
| flags | x_obj_flag_t – GC mark flags |
| int x_type_op_try | ( | x_obj_t * | p_base, |
| x_char_t * | op, | ||
| x_obj_t * | p_a, | ||
| x_obj_t * | p_b, | ||
| x_obj_t ** | pp_result | ||
| ) |
Try generic-operator dispatch for a binary op; 1 if dispatched.
Return the length for an object. x-lang: (length obj)
Dispatches to pair or atom length primitives for built-in types. For custom types, calls the type's length hook function.
| p_base | x_obj_t* – Base (execution context) |
| p_args | x_obj_t* – (object) |
Return the type name for an object. x-lang: (type-name obj)
For stack atoms/pairs and untyped objects, returns the raw type pointer. For heap-typed objects, extracts the name from the type struct.
| p_base | x_obj_t* – Base (execution context) |
| p_args | x_obj_t* – (object) |
Return the unit count for an object. x-lang: (units obj)
Dispatches to pair or atom unit primitives for built-in types. For custom types, reads the type's units count.
| p_base | x_obj_t* – Base (execution context) |
| p_args | x_obj_t* – (object) |
The default save: the units the type's shape declares, each with the kind the shape's mask gives it (a bare count: all references). Args are already evaluated: (obj buf).
The default save handler: every unit the type's units shape declares.
| x_obj_t * x_type_save_units | ( | x_obj_t * | p_obj, |
| x_int_t * | buf, | ||
| x_int_t | n, | ||
| const int * | kinds, | ||
| int | nkinds | ||
| ) |
Write n at buf[0] and the units of p_obj as [kind][word] pairs after it, kinds from kinds (the last repeats); every C save handler's helper. Returns p_obj.
Retrieve or create a type struct by name.
First checks the type alist cache. On miss, calls the callable in rest of p_args to construct the type, then caches it in the type alist for future lookups.
| p_base | x_obj_t* – Base (execution context) |
| p_args | x_obj_t* – (type-name . constructor-callable) |
Construct a type struct from a type descriptor.
Builds the canonical nested-pair structure that represents a type in the type alist: name-stack, data-stack, heap group (mark, make, free, clone, units, length), proc group (call, eval), cvt group (from, to), IO group (analyse, delimit, read, write, display, error), iter group, and ops group.
| p_base | x_obj_t* – Base (execution context) (for allocation) |
| type | struct x_type_t – Type descriptor with all hook pointers |
The kind of unit i.
Units at or past described take the kind of the last described unit. That is the repeat rule, and it is how a dynamic-size type says what its payload units are without a marker.
| mask | x_int_t – The kind mask |
| i | x_int_t – Unit index |
| described | x_int_t – Fields the mask describes |
The declared unit count, from either form of a p_units slot.
A bare INT atom is the count itself; a pair is (count . mask) and the count is its first. Negative keeps its dynamic-size meaning in both.
| p_units | x_obj_t* – A type's p_units slot, or NULL |
How many leading units the mask describes before the repeat rule applies.
A fixed count describes exactly its own units. A dynamic count of -k describes the k leading units plus the kind of the payload that follows them – k + 1 fields – so a count of -1 with mask (ref, ref) covers slot 0 and the slot-0-many payload units after it, with no repeat marker.
Note that the slot-0-counted convention holds its length as a heap INTEGER OBJECT, so slot 0 is X_TYPE_UNIT_REF, not X_TYPE_UNIT_WORD – see the kind documentation in x-type.h.
| p_units | x_obj_t* – A type's p_units slot, or NULL |
The per-unit kind mask, from either form of a p_units slot.
The bare-count form has no mask; 0 is the honest answer for it, since X_TYPE_UNIT_REF is 0 and "every unit a reference" is what a bare count has always meant.
| p_units | x_obj_t* – A type's p_units slot, or NULL |
| x_satom_t x_type_save_default_prim = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { (x_obj_t *)&x_type_save_default }) |