|
x-engine-c v0.2.13
The C engine for x-lang
|
Primitive (C function) type and unified callable dispatch. More...
#include "x-type.h"Go to the source code of this file.
Macros | |
| #define | X_TYPE_PRIM_NAME "PRIMITIVE" |
Predicates | |
| #define | x_obj_type_isprim(B, X) x_obj_is_type((B), (X), X_TYPE_PRIM_NAME) |
Accessors | |
| #define | x_primval(X) x_firstfn((X)) |
| #define | x_callable_state(X) x_secondobj((X)) |
Constructors | |
| #define | x_mkprim(B, FN) x_make_prim((B), X_OBJ_FLAG_NONE, (FN)) |
| #define | x_mkfprim(B, F, FN) x_make_prim((B), (F), (FN)) |
Functions | |
| x_obj_t * | x_make_prim (x_obj_t *p_base, x_obj_flag_t flags, x_fn_t fn) |
| x_obj_t * | x_type_prim_register (x_obj_t *p_base, x_obj_t *p_args) |
| x_obj_t * | x_type_prim_struct (x_obj_t *p_base, x_obj_t *p_args) |
| x_obj_t * | x_type_prim_make (x_obj_t *p_base, x_obj_t *p_args) |
| x_obj_t * | x_callable_call (x_obj_t *p_base, x_obj_t *p_args) |
| x_obj_t * | x_callable_apply (x_obj_t *p_base, x_obj_t *p_args) |
Variables | |
Static Atoms | |
| x_satom_t | x_type_prim_name |
| x_satom_t | x_type_prim_make_prim |
| x_satom_t | x_callable_call_prim |
| x_satom_t | x_type_prim_struct_prim |
Primitive (C function) type and unified callable dispatch.
A PRIMITIVE wraps a C function pointer (x_fn_t) as a first-class object. The callable_call / callable_apply functions provide unified dispatch for all callable types (primitives, closures, operatives, and type-internal handlers).
| #define x_callable_state | ( | X | ) | x_secondobj((X)) |
Access the state slot (second object) of a callable.
| #define x_mkfprim | ( | B, | |
| F, | |||
| FN | |||
| ) | x_make_prim((B), (F), (FN)) |
Create a PRIMITIVE with explicit flags.
| #define x_mkprim | ( | B, | |
| FN | |||
| ) | x_make_prim((B), X_OBJ_FLAG_NONE, (FN)) |
Create a PRIMITIVE with default flags.
| #define x_obj_type_isprim | ( | B, | |
| X | |||
| ) | x_obj_is_type((B), (X), X_TYPE_PRIM_NAME) |
Test whether X is a PRIMITIVE object.
| #define x_primval | ( | X | ) | x_firstfn((X)) |
Extract the x_fn_t function pointer from a callable.
| #define X_TYPE_PRIM_NAME "PRIMITIVE" |
Canonical type name.
Unified apply dispatch with TCO trampoline support.
Unified apply dispatch with TCO trampoline support.
Like x_callable_call() but uses the non-TCO apply path for procedures (args already evaluated) and a trampoline for operatives.
| p_base | Base (execution context). |
| p_args | Argument list: (callable . args). |
Unified call dispatch for all callable types.
Unified call dispatch for all callable types.
All callables store a function pointer in slot 0:
| p_base | Base (execution context). |
| p_args | Argument list: (callable . args). |
| x_obj_t * x_make_prim | ( | x_obj_t * | p_base, |
| x_obj_flag_t | flags, | ||
| x_fn_t | fn | ||
| ) |
Allocate a PRIMITIVE object wrapping fn.
Allocate a PRIMITIVE object wrapping a C function pointer.
| p_base | Base (execution context). |
| flags | Object flags. |
| fn | C function pointer to wrap. |
Type-system make handler for PRIMITIVE objects.
Type-system make handler for PRIMITIVE objects.
Extracts the function pointer from p_args[0] and optional flags from p_args[1], then allocates a pair-length object via x_obj_make().
| p_base | Base (execution context). |
| p_args | Argument list: (fn-atom [flags-atom]). |
Register (or retrieve) the PRIMITIVE type in the type alist.
Register (or retrieve) the PRIMITIVE type in the type alist.
| p_base | Base (execution context). |
| p_args | Unused. |
Build the PRIMITIVE type struct descriptor.
| x_satom_t x_callable_call_prim |
Static atom: call handler.
| x_satom_t x_type_prim_make_prim |
Static atom: make handler.
|
extern |
Static atom: type name.
| x_satom_t x_type_prim_struct_prim |
Static atom: struct constructor.