x-engine-c v0.2.13
The C engine for x-lang
Loading...
Searching...
No Matches
x-prim.h
Go to the documentation of this file.
1#ifndef X_PRIM_H
2#define X_PRIM_H
3
18/*
19 * ., .,
20 * {O,O}
21 * ( )
22 * " "
23 */
24
25#include "x-obj.h"
26#include "x-heap.h"
27#include "x-eval.h" /* x_eval_arg: the x_eargs helper below evaluates args */
28#include <stdarg.h>
29
30
56static void __attribute__((unused)) x_args(x_obj_t *p_base, x_obj_t *p_args,
57 int count, ...)
58{
59 va_list ap;
60 int i;
61
63 for (i = 0; i < count; i++) {
64 x_obj_t **slot = va_arg(ap, x_obj_t **);
65 if (p_args == NULL) { if (slot) *slot = NULL; continue; }
67 if (slot != NULL)
68 *slot = x_firstobj(p_args);
70 }
71 va_end(ap);
72}
73
87static void __attribute__((unused)) x_eargs(x_obj_t *p_base, x_obj_t *p_args, int count, ...)
88{
89 va_list ap;
90 int i;
91 int held = 0;
92 x_obj_t **p_cell = x_heap_root_slot(p_base);
93 /* Earlier results may be fresh objects whose only other homes are the
94 * caller's out-slots -- bare C stack the collector does not scan under
95 * precise rooting -- so each result is parked in a registered slot
96 * while the later arguments evaluate. Two pair cells give four slots:
97 * enough for the deepest x_eargs caller (count 5 = four results, of
98 * which the last needs no protection here). */
101 { NULL }, { NULL }),
103 { NULL }, { NULL })
104 };
105
108
109 va_start(ap, count);
110 for (i = 0; i < count; i++) {
111 x_obj_t **slot = va_arg(ap, x_obj_t **);
112 if (p_args == NULL) { if (slot) *slot = NULL; continue; }
113 /* A proper list ends at nil, handled above; an IMPROPER one ends
114 * at an ATOM, which the walk below would have read as a pair
115 * (#487). Raising here is safe with the roots pushed: the
116 * handler restores the root chain to its snapshot on the error
117 * path, exactly as it does for the C frames a longjmp cuts. */
118 x_eval_spine_guard(p_base, p_args);
119 if (slot != NULL) {
120 *slot = x_eval_arg(p_base, x_firstobj(p_args));
121 if (held < 4) {
122 x_obj_data_i((x_obj_t *)roots[held >> 1], held & 1).p = *slot;
123 held++;
124 }
125 }
127 }
128 va_end(ap);
129
132}
133
/* end arg_helpers */
135
136
148
150void x_value_bind(x_obj_t *p_base, x_char_t *name, x_obj_t *p_val);
151
153void x_callable_bind(x_obj_t *p_base, x_char_t *name, x_fn_t fn);
154
156void x_callable_bind_table(x_obj_t *p_base, const x_callable_entry_t *table, int count);
157
175x_obj_t *x_prims(x_obj_t *p_base);
176
187
191void x_prims_bind_table(x_obj_t *p_base, const x_prim_entry_t *table, int count);
192
200
203
207
211
216
219
222
225
230
233x_obj_t *x_prim_type_build_struct(x_obj_t *p_base, x_obj_t *p_name_atom,
234 x_obj_t *p_handlers);
235
238
242 x_obj_t *(*op)(x_obj_t *, x_obj_t *));
243
246
249
253
256
257#ifdef X_SIGNAL
260#endif
261
263void x_callcc_init(void);
268
269#endif /* X_PRIM_H */
static void x_obj_t int int i
Definition x-prim.h:60
x_spair_t roots[2]
Definition x-prim.h:99
static void __attribute__((unused)) x_args(x_obj_t *p_base
static void x_obj_t int count
Definition x-prim.h:57
va_start(ap, count)
x_obj_t ** p_cell
Definition x-prim.h:92
int held
Definition x-prim.h:91
va_end(ap)
static void x_obj_t * p_args
Definition x-prim.h:56
x_heap_root_push(p_cell, roots[0])
x_heap_root_pop(p_cell)
void x_value_bind(x_obj_t *p_base, x_char_t *name, x_obj_t *p_val)
Definition x-prim.c:66
void x_callable_bind(x_obj_t *p_base, x_char_t *name, x_fn_t fn)
Definition x-prim.c:49
void x_callable_bind_table(x_obj_t *p_base, const x_callable_entry_t *table, int count)
Definition x-prim.c:95
void x_prims_bind_table(x_obj_t *p_base, const x_prim_entry_t *table, int count)
Definition x-prim.c:253
x_obj_t * x_prims(x_obj_t *p_base)
Definition x-prim.c:116
x_obj_t * x_prim_signal_register(x_obj_t *p_base, x_obj_t *p_args)
Definition signal.c:81
Definition x-prim.h:144
x_fn_t fn
Definition x-prim.h:146
x_char_t * name
Definition x-prim.h:145
Definition x-prim.h:181
x_char_t * method
Definition x-prim.h:185
x_fn_t fn
Definition x-prim.h:183
x_char_t * ns
Definition x-prim.h:184
x_char_t * name
Definition x-prim.h:182
Definition x-obj.h:212
void x_eval_spine_guard(x_obj_t *p_base, x_obj_t *p_obj)
Definition x-eval.c:354
x_obj_t * x_eval_arg(x_obj_t *p_base, x_obj_t *p_arg)
Definition x-eval.c:310
Evaluator object and interface – x-expr's base object plus the environment, control-flow,...
Heap management and mark-sweep garbage collection.
The x-expr object system – atoms, pairs, flags, and type dispatch.
@ X_OBJ_FLAG_NONE
Definition x-obj.h:129
#define x_obj_data_i(X, I)
Definition x-obj.h:330
#define x_obj_set(T, F,...)
Definition x-obj.h:342
x_obj_t *(* x_fn_t)(x_obj_t *p_base, x_obj_t *p_args)
Definition x-obj.h:197
#define x_firstobj(X)
Definition x-obj.h:414
x_satom_t x_type_pair_obj
Definition x-obj.c:32
x_obj_t x_spair_t[X_OBJ_META_LEN+X_OBJ_UNITS_PAIR]
Definition x-obj.h:286
#define x_restobj(X)
Definition x-obj.h:435
x_obj_t * x_prim_arith_register(x_obj_t *p_base, x_obj_t *p_args)
Definition arith.c:245
x_obj_t * x_prim_base_register(x_obj_t *p_base, x_obj_t *p_args)
Definition base.c:343
x_obj_t * x_prim_pred_register(x_obj_t *p_base, x_obj_t *p_args)
Definition pred.c:140
x_obj_t * x_prim_ffi_register(x_obj_t *p_base, x_obj_t *p_args)
Register all FFI primitives and platform constants.
Definition ffi.c:1084
x_obj_t * x_prim_type_build_struct(x_obj_t *p_base, x_obj_t *p_name_atom, x_obj_t *p_handlers)
Build a type struct from a handlers alist.
Definition type.c:61
x_obj_t * x_prim_heap_register(x_obj_t *p_base, x_obj_t *p_args)
Definition heap.c:371
x_obj_t * x_prim_io_register(x_obj_t *p_base, x_obj_t *p_args)
Definition io.c:223
x_obj_t * x_prim_op1(x_obj_t *p_base, x_obj_t *p_args, x_obj_t *(*op)(x_obj_t *, x_obj_t *))
Definition type.c:319
x_obj_t * x_prim_callcc_register(x_obj_t *p_base, x_obj_t *p_args)
Definition callcc.c:359
x_obj_t * x_prim_image_register(x_obj_t *p_base, x_obj_t *p_args)
Definition image.c:907
x_obj_t * x_prim_register(x_obj_t *p_base, x_obj_t *p_args)
Definition x-prim.c:286
void x_callcc_init(void)
Definition callcc.c:104
x_obj_t * x_prim_core_register(x_obj_t *p_base, x_obj_t *p_args)
Definition core.c:337
x_obj_t * x_prim_repl(x_obj_t *p_base, x_obj_t *p_args)
Definition io.c:148
x_obj_t * x_prim_type_register(x_obj_t *p_base, x_obj_t *p_args)
Register all type-system and sandboxing primitives.
Definition type.c:352
x_obj_t * x_prim_string_register(x_obj_t *p_base, x_obj_t *p_args)
Definition string.c:215
x_obj_t * x_prim_iter_register(x_obj_t *p_base, x_obj_t *p_args)
Definition iter.c:68
x_obj_t * x_prim_buffer_register(x_obj_t *p_base, x_obj_t *p_args)
Definition buffer.c:262
char x_char_t
Definition x.h:138