x-engine-c v0.2.31
The C engine for x-lang
Loading...
Searching...
No Matches
Argument Unpacking Helpers

Variadic helpers for extracting arguments from x-lang arg lists. More...

Functions

static void __attribute__ ((unused)) x_args(x_obj_t *p_base
 
 va_start (ap, count)
 
 for (i=0;i< count;i++)
 
 va_end (ap)
 
 x_heap_root_push (p_cell, roots[0])
 
 x_heap_root_push (p_cell, roots[1])
 
 x_heap_root_pop (p_cell)
 

Variables

static void x_obj_t * p_args
 
static void x_obj_t int count
 
static void x_obj_t int int i
 
int held = 0
 
x_obj_t ** p_cell = x_heap_root_slot(p_base)
 
x_spair_t roots [2]
 

Detailed Description

Variadic helpers for extracting arguments from x-lang arg lists.

Function Documentation

◆ __attribute__()

static x_obj_t __attribute__ ( (unused)  )
static

Unpack count elements from an args list into output pointers.

NULL pointers skip that position (like _ in pattern matching).

x_args(p_base, p_args, 3, NULL, &a, &b); // skip self, extract 2
static void x_obj_t * p_args
Definition x-prim.h:56
Parameters
p_baseBase/execution context (for the improper-spine raise).
p_argsArgument list (pair chain).
countNumber of positions to unpack.
...Pointers to x_obj_t* slots (or NULL to skip).
Note
Walking off the proper prefix of an IMPROPER list used to read the tail atom's value word as a pair pointer (#487). The nil test below ends a proper list; x_eval_spine_guard raises on the atom a dotted tail ends with, which is the same catchable error an applicative already gave for a call with a dotted tail.

Unpack and evaluate count elements from an args list.

NULL pointers skip that position without evaluating.

x_eargs(p_base, p_args, 3, NULL, &a, &b); // skip self, eval+extract 2
Parameters
p_baseBase/execution context.
p_argsArgument list (pair chain).
countNumber of positions to unpack.
...Pointers to x_obj_t* slots (or NULL to skip).

The args list past its first count positions, or nil if it is shorter.

For a prim that unpacks a fixed prefix with x_args/x_eargs and then takes the tail as a body or a variadic rest. Walking there with x_11/x_111 reads rest of nil when the call is short – (fn), (eval) – which is a SIGSEGV where x_args had already stopped at the end.

Parameters
p_baseBase/execution context (for the improper-spine raise).
p_argsArgument list (pair chain).
countNumber of positions to skip.
Returns
The remaining list, or nil.

◆ for()

for ( )

◆ va_end()

va_end ( ap  )

◆ va_start()

va_start ( ap  ,
count   
)

◆ x_heap_root_pop()

x_heap_root_pop ( p_cell  )

◆ x_heap_root_push() [1/2]

x_heap_root_push ( p_cell  ,
roots  [0] 
)

◆ x_heap_root_push() [2/2]

x_heap_root_push ( p_cell  ,
roots  [1] 
)

Variable Documentation

◆ count

static x_obj_t x_obj_t int count
Initial value:
{
while (count-- > 0 && p_args != NULL) {
}
return p_args
static void x_obj_t int count
Definition x-prim.h:57
void x_eval_spine_guard(x_obj_t *p_base, x_obj_t *p_obj)
Definition x-eval.c:375
#define x_restobj(X)
Definition x-obj.h:439

◆ held

int held = 0

◆ i

static void x_obj_t int int i
Initial value:
{
va_list ap

◆ p_args

static x_obj_t x_obj_t * p_args

◆ p_cell

x_obj_t** p_cell = x_heap_root_slot(p_base)

◆ roots

x_spair_t roots[2]
Initial value:
= {
{ NULL }, { NULL }),
{ NULL }, { NULL })
}
Definition x-obj.h:214
@ X_OBJ_FLAG_NONE
Definition x-obj.h:131
#define x_obj_set(T, F,...)
Definition x-obj.h:344
x_satom_t x_type_pair_obj
Definition x-obj.c:32