|
x-engine-c v0.2.13
The C engine for x-lang
|
Functions | |
| static x_obj_t * | x_prim_arith_binop (x_obj_t *p_base, x_obj_t *p_args, x_char_t *p_op, x_char_t *p_err, int use_ops) |
| static x_obj_t * | x_prim_sum (x_obj_t *p_base, x_obj_t *p_args) |
| static x_obj_t * | x_prim_sub (x_obj_t *p_base, x_obj_t *p_args) |
| static x_obj_t * | x_prim_prod (x_obj_t *p_base, x_obj_t *p_args) |
| static x_obj_t * | x_prim_div (x_obj_t *p_base, x_obj_t *p_args) |
| static x_obj_t * | x_prim_mod (x_obj_t *p_base, x_obj_t *p_args) |
| static x_obj_t * | x_prim_bitnot (x_obj_t *p_base, x_obj_t *p_args) |
| static x_obj_t * | x_prim_bitand (x_obj_t *p_base, x_obj_t *p_args) |
| static x_obj_t * | x_prim_bitor (x_obj_t *p_base, x_obj_t *p_args) |
| static x_obj_t * | x_prim_bitxor (x_obj_t *p_base, x_obj_t *p_args) |
| static x_obj_t * | x_prim_shl (x_obj_t *p_base, x_obj_t *p_args) |
| static x_obj_t * | x_prim_shr (x_obj_t *p_base, x_obj_t *p_args) |
| x_obj_t * | x_prim_arith_register (x_obj_t *p_base, x_obj_t *p_args) |
|
static |
Shared body for the binary integer ops: evaluate both operands, optionally dispatch through the type-ops registry, guard nil, compute.
use_ops selects the x_type_op_try dispatch. The tower ops (+ * / %) pass 1 so a typed operand (float, bigint, ...) reaches its type's handler; the bitwise family passes 0 – #52 ruled bitwise has no tower semantics (there is no float &; lib/x/core/arithmetic.x records the ruling), so the dispatch hook is deliberately not offered there.
Nil operands raise instead of reading x_intval(NULL) – the same nil-safety convention x_prim_eq already follows (#52 ruled: an x-level wrapper test measured +9% on every method dispatch, so the check lives here, where it is two pointer tests). Runs AFTER op_try, so typed operands never reach it. The raw prims are the only guard on the bare-core and (Base make) child paths, where the lib wrappers are absent (#239).
The switch keys on the operator's first byte: all nine ops are unique there (<</>> via </>).
| p_base | x_obj_t* – Base (execution context) |
| p_args | x_obj_t* – Unevaluated args, evaluated via x_eargs |
| p_op | x_char_t* – Operator spelling, as registered |
| p_err | x_char_t* – Raise message for a nil operand |
| use_ops | int – Non-zero to try x_type_op_try first |
Register arithmetic primitives into the environment.
Binds: +, -, *, /, %, ~, &, |, ^, <<, >>
| p_base | x_obj_t* – Base (execution context) |
| p_args | x_obj_t* – Unused |
Bitwise AND. x-lang: (& a b)
Bitwise NOT. x-lang: (~ n)
Unary: no binary op dispatch; the nil guard mirrors x_prim_sub's unary branch (#239 – the raw prim is the only guard on bare-core and (Base make) child paths).
Bitwise OR. x-lang: (| a b)
Bitwise XOR. x-lang: (^ a b)
Binary integer division (truncates toward zero). x-lang: (/ a b)
Binary integer modulo. x-lang: (% a b)
Binary integer multiplication. x-lang: (* a b)
Left shift. x-lang: (<< a b)
Right shift. x-lang: (>> a b)
Integer subtraction or negation. x-lang: (- a b) or (- a)
With one argument, returns the negation. With two, returns the difference. The second argument is evaluated lazily (only if present).
| p_base | x_obj_t* – Base (execution context) |
| p_args | x_obj_t* – Unevaluated args (1 or 2) |
Binary integer addition, with typed-operand dispatch. x-lang: (+ a b)