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

Pair type for the x-lang type system. More...

#include "x-type.h"

Go to the source code of this file.

Macros

#define X_TYPE_PAIR_NAME   "PAIR"
 
#define x_obj_type_ispair(B, X)   x_obj_is_type((B), (X), X_TYPE_PAIR_NAME)
 
#define x_mkpair(B, P1, P2)   x_make_pair((B), X_OBJ_FLAG_NONE, (P1), (P2))
 
#define x_mkfpair(B, F, P1, P2)   x_make_pair((B), (F), (P1), (P2))
 

Functions

x_obj_tx_make_pair (x_obj_t *p_base, x_obj_flag_t flags, void *p1, void *p2)
 
x_obj_tx_type_pair_register (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_type_pair_struct (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_type_pair_make (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_type_pair_length (x_obj_t *p_base, x_obj_t *p_args)
 

Detailed Description

Pair type for the x-lang type system.

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

Macro Definition Documentation

◆ x_mkfpair

#define x_mkfpair (   B,
  F,
  P1,
  P2 
)    x_make_pair((B), (F), (P1), (P2))

Make a pair with explicit flags F.

◆ x_mkpair

#define x_mkpair (   B,
  P1,
  P2 
)    x_make_pair((B), X_OBJ_FLAG_NONE, (P1), (P2))

Make a pair with default flags.

◆ x_obj_type_ispair

#define x_obj_type_ispair (   B,
 
)    x_obj_is_type((B), (X), X_TYPE_PAIR_NAME)

Test whether object X is a pair on base B.

◆ X_TYPE_PAIR_NAME

#define X_TYPE_PAIR_NAME   "PAIR"

Type-system name string

Function Documentation

◆ x_make_pair()

x_obj_t * x_make_pair ( x_obj_t p_base,
x_obj_flag_t  flags,
void *  p1,
void *  p2 
)

Allocate a heap pair from first/rest pointers.

Allocate a heap pair from first/rest pointers.

Wraps p1 and p2 in stack-allocated objects, builds a stack arg list, and delegates to x_type_pair_make.

Parameters
p_basex_obj_t* – Base (execution context)
flagsx_obj_flag_t – Object flags
p1void* – First element
p2void* – Rest element
Returns
x_obj_t* – New heap-allocated pair

◆ x_type_pair_length()

x_obj_t * x_type_pair_length ( x_obj_t p_base,
x_obj_t p_args 
)

Compute the length of a pair list.

Compute the length of a pair list by walking rest pointers.

Parameters
p_basex_obj_t* – Base (execution context)
p_argsx_obj_t* – (pair-object . ...)
Returns
x_obj_t* – Integer object with list length

◆ x_type_pair_make()

x_obj_t * x_type_pair_make ( x_obj_t p_base,
x_obj_t p_args 
)

Type-system make callback for pair.

Type-system make callback for pair objects.

Extracts first/rest from the pair arg and optional flags, then allocates a heap pair via x_obj_make.

Parameters
p_basex_obj_t* – Base (execution context)
p_argsx_obj_t* – (pair-value . (flags | nil))
Returns
x_obj_t* – New heap-allocated pair object

◆ x_type_pair_register()

x_obj_t * x_type_pair_register ( x_obj_t p_base,
x_obj_t p_args 
)

Register (or retrieve) the pair type struct on p_base.

Register or retrieve the pair type on the base context.

Parameters
p_basex_obj_t* – Base (execution context)
p_argsx_obj_t* – Unused
Returns
x_obj_t* – Registered type object

◆ x_type_pair_struct()

x_obj_t * x_type_pair_struct ( x_obj_t p_base,
x_obj_t p_args 
)

Build the pair type descriptor struct.

Build the pair type descriptor struct.

Populates name, units, make, length, and write callbacks.

Parameters
p_basex_obj_t* – Base (execution context)
p_argsx_obj_t* – Unused
Returns
x_obj_t* – Type descriptor pair list