x-engine-c v0.2.13
The C engine for x-lang
Loading...
Searching...
No Matches
prim.c File Reference

Primitive type – construction, registration, and unified callable dispatch. More...

#include "x-type/prim.h"
#include "x-type/procedure.h"
#include "x-type/operative.h"
#include "x-eval.h"

Functions

x_obj_tx_make_prim (x_obj_t *p_base, x_obj_flag_t flags, x_fn_t fn)
 
x_obj_tx_type_prim_save (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_type_prim_struct (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_type_prim_register (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_type_prim_make (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_callable_call (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_callable_apply (x_obj_t *p_base, x_obj_t *p_args)
 

Variables

x_satom_t x_type_prim_name = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { .s = (x_char_t *)X_TYPE_PRIM_NAME })
 
x_satom_t x_type_prim_make_prim = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { (x_obj_t *)&x_type_prim_make })
 
x_satom_t x_callable_call_prim = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { (x_obj_t *)&x_callable_call })
 
x_satom_t x_type_prim_struct_prim = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { (x_obj_t *)&x_type_prim_struct })
 
x_satom_t x_type_prim_save_prim = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { (x_obj_t *)&x_type_prim_save })
 

Detailed Description

Primitive type – construction, registration, and unified callable dispatch.

Author
Jon Ruttan (jonru.nosp@m.ttan.nosp@m.@gmai.nosp@m.l.co.nosp@m.m)

Function Documentation

◆ x_callable_apply()

x_obj_t * x_callable_apply ( x_obj_t p_base,
x_obj_t p_args 
)

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.

Parameters
p_baseBase (execution context).
p_argsArgument list: (callable . args).
Returns
Result of the applied function.
See also
x_callable_call
x_eval_tco_trampoline

◆ x_callable_call()

x_obj_t * x_callable_call ( x_obj_t p_base,
x_obj_t p_args 
)

Unified call dispatch for all callable types.

All callables store a function pointer in slot 0:

  • Closures/operatives: fn-ptr is x_type_procedure_call / x_type_operative_call.
  • C primitives (spair): fn-ptr is the C function itself.
  • Type handlers (satom): fn-ptr is a type-internal handler (no self-passing).
Parameters
p_baseBase (execution context).
p_argsArgument list: (callable . args).
Returns
Result of the called function.

◆ x_make_prim()

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 a C function pointer.

Parameters
p_baseBase (execution context).
flagsObject flags.
fnC function pointer to wrap.
Returns
Newly allocated PRIMITIVE object.

◆ x_type_prim_make()

x_obj_t * x_type_prim_make ( x_obj_t p_base,
x_obj_t p_args 
)

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().

Parameters
p_baseBase (execution context).
p_argsArgument list: (fn-atom [flags-atom]).
Returns
Newly allocated PRIMITIVE object.

◆ x_type_prim_register()

x_obj_t * x_type_prim_register ( x_obj_t p_base,
x_obj_t p_args 
)

Register (or retrieve) the PRIMITIVE type in the type alist.

Parameters
p_baseBase (execution context).
p_argsUnused.
Returns
The registered PRIMITIVE type object.

◆ x_type_prim_save()

x_obj_t * x_type_prim_save ( x_obj_t p_base,
x_obj_t p_args 
)

Build the PRIMITIVE type struct descriptor.

Populates name, make, and call hooks.

Parameters
p_baseBase (execution context).
p_argsUnused.
Returns
Type struct pair-tree for PRIMITIVE.

◆ x_type_prim_struct()

x_obj_t * x_type_prim_struct ( x_obj_t p_base,
x_obj_t p_args 
)

Build the PRIMITIVE type struct descriptor.

Variable Documentation

◆ x_callable_call_prim

◆ x_type_prim_make_prim

◆ x_type_prim_name

Static atom: type name.

◆ x_type_prim_save_prim

◆ x_type_prim_struct_prim