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

Predicate and type-conversion primitives. More...

#include "x-prim.h"
#include "x-type.h"
#include "x-type/char.h"
#include "x-type/int.h"

Functions

static x_obj_tx_prim_same (x_obj_t *p_base, x_obj_t *p_args)
 
static x_obj_tx_prim_eq (x_obj_t *p_base, x_obj_t *p_args)
 
static x_obj_tx_prim_num_eq (x_obj_t *p_base, x_obj_t *p_args)
 
static x_obj_tx_prim_lt (x_obj_t *p_base, x_obj_t *p_args)
 
static x_obj_tx_prim_char_to_integer (x_obj_t *p_base, x_obj_t *p_args)
 
static x_obj_tx_prim_integer_to_char (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_prim_pred_register (x_obj_t *p_base, x_obj_t *p_args)
 

Detailed Description

Predicate and type-conversion primitives.

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

Function Documentation

◆ x_prim_char_to_integer()

static x_obj_t * x_prim_char_to_integer ( x_obj_t p_base,
x_obj_t p_args 
)
static

Convert a character to its integer code point. x-lang: (char->integer c)

Parameters
p_baseInterpreter base context.
p_argsUnevaluated argument list: (char->integer c).
Returns
An integer object holding the character's code point value.
Note
Zero-allocation cast; safe inside tokenizer callbacks.

◆ x_prim_eq()

static x_obj_t * x_prim_eq ( x_obj_t p_base,
x_obj_t p_args 
)
static

Value equality test (also bound as =). x-lang: (eq? a b) / (= a b)

Parameters
p_baseInterpreter base context.
p_argsUnevaluated argument list: (eq? a b).
Returns
#t if a and b are equal by value, #f otherwise.
Note
Compares the object's value word. The union slot is pointer-width (x_assert_int_ptr_size), so one comparison serves integers, characters, and any pointer-valued scalar. The a==b fast path covers nil, booleans, and interned symbols – and, being checked before any dereference, keeps (eq? x ()) from reading a nil value slot. Use same? for strict object identity.

◆ x_prim_integer_to_char()

static x_obj_t * x_prim_integer_to_char ( x_obj_t p_base,
x_obj_t p_args 
)
static

Convert an integer code point to a character. x-lang: (integer->char n)

Parameters
p_baseInterpreter base context.
p_argsUnevaluated argument list: (integer->char n).
Returns
A character object for the given code point.
Note
Zero-allocation cast; safe inside tokenizer callbacks.

◆ x_prim_lt()

static x_obj_t * x_prim_lt ( x_obj_t p_base,
x_obj_t p_args 
)
static

Integer less-than comparison, with typed-operand dispatch. x-lang: (< a b)

Parameters
p_baseInterpreter base context.
p_argsUnevaluated argument list: (< a b).
Returns
#t if a is numerically less than b, #f otherwise.

◆ x_prim_num_eq()

static x_obj_t * x_prim_num_eq ( x_obj_t p_base,
x_obj_t p_args 
)
static

Numeric equality with typed-operand dispatch (bound as = only). x-lang: (= a b)

Parameters
p_baseInterpreter base context.
p_argsUnevaluated argument list: (= a b).
Returns
#t if equal, #f otherwise.
Note
Distinct from x_prim_eq, which doubles as eq? – identity semantics must never dispatch through a type's ops (eq? on two floats is value-word identity, not f=). Evaluates its own args, so the fallthrough repeats x_prim_eq's comparison inline rather than delegating (delegation would re-evaluate the args).

◆ x_prim_pred_register()

x_obj_t * x_prim_pred_register ( x_obj_t p_base,
x_obj_t p_args 
)

Register predicate and type-conversion primitives.

Binds: same?, eq?, =, <, char->integer, integer->char.

Parameters
p_baseInterpreter base context.
p_argsUnused.
Returns
p_base.

◆ x_prim_same()

static x_obj_t * x_prim_same ( x_obj_t p_base,
x_obj_t p_args 
)
static

Object identity test (pointer equality). x-lang: (same? a b)

Parameters
p_baseInterpreter base context.
p_argsUnevaluated argument list: (same? a b).
Returns
#t if a and b are the same object (pointer), #f otherwise.
Note
Strict identity: two distinct integer/character objects with equal values are NOT same?. Use eq? for value equality of scalars.