|
x-engine-c v0.2.13
The C engine for x-lang
|
Sandbox-base primitives – make-base, base-eval (setjmp cross-base eval), base-bind, make-token-base, base-make-type. More...
#include "x-prim.h"#include "x-alist.h"#include "x-eval.h"#include "x-env.h"#include "x-heap.h"#include "x-type.h"#include <setjmp.h>#include "x-token.h"#include "x-type/buffer.h"#include "x-type/char.h"#include "x-type/err.h"#include "x-type/comment.h"#include "x-type/int.h"#include "x-type/list.h"#include "x-type/operative.h"#include "x-type/prim.h"#include "x-type/procedure.h"#include "x-type/ptr.h"#include "x-type/str.h"#include "x-type/symbol.h"#include "x-type/whitespace.h"Functions | |
| static x_obj_t * | x_prim_base_make_type (x_obj_t *p_base, x_obj_t *p_args) |
| Create a type on a target base (cross-base type registration). | |
| static void | x_base_attach_read_buffer (x_obj_t *p_new) |
| Give a base the reader buffer the tokenizer reads through. | |
| static x_obj_t * | x_prim_make_token_base (x_obj_t *p_base, x_obj_t *p_args) |
| Create a bare base suitable for tokenization only. | |
| static x_obj_t * | x_prim_make_base (x_obj_t *p_base, x_obj_t *p_args) |
| Create a fully initialized sandboxed interpreter base. | |
| static x_obj_t * | x_prim_base_eval (x_obj_t *p_base, x_obj_t *p_args) |
| Evaluate an expression in a target base's environment. | |
| static x_obj_t * | x_prim_base_bind (x_obj_t *p_base, x_obj_t *p_args) |
| Bind a name-value pair in a target base's environment. | |
| static x_obj_t * | x_prim_define_global (x_obj_t *p_base, x_obj_t *p_args) |
| Bind a name in the base's ROOT environment, whatever environment is current. | |
| x_obj_t * | x_prim_base_register (x_obj_t *p_base, x_obj_t *p_args) |
Sandbox-base primitives – make-base, base-eval (setjmp cross-base eval), base-bind, make-token-base, base-make-type.
|
static |
Give a base the reader buffer the tokenizer reads through.
Both base constructors need this and each used to spell it out, which is how make-tok came to be missing it entirely: an empty input happened to work, because nothing was ever read, and the first character dereferenced a buffer that was never made.
Attaching rather than allocating-and-returning keeps each caller's existing order intact – make-base registers its types before this runs, and that ordering is not something to disturb while fixing a crash.
| p_new | The base to attach a reader buffer to. |
Bind a name-value pair in a target base's environment.
x-lang form:
Binds name to value in the target base's ROOT environment, where every environment in that base reaches it: the door for handing a child base a capability.
| p_base | Calling execution context. |
| p_args | Unevaluated: (self target-base name value). |
Evaluate an expression in a target base's environment.
x-lang form:
Pushes a setjmp-based error handler onto the target base's error handler stack, evaluates p_expr in the target, then pops the handler. If an error occurs in the target, it is caught, the handler is popped, the environment is restored, and the error is propagated to the calling base's error handler (or printed if none exists).
| p_base | Calling execution context. |
| p_args | Unevaluated: (self target-base expr). |
expr in the target base, or NULL on error. Create a type on a target base (cross-base type registration).
x-lang form:
Like make-type, but registers the type on p_target rather than the calling base. Pins the type struct as SHARED so the calling base's GC will not sweep the name atom or the handler closures the target now refers to from its own heap chain.
| p_base | Calling execution context (used for handler closure allocation). |
| p_args | Unevaluated: (self target-base name-string handlers-alist). |
Register the sandbox base primitives.
Bind a name in the base's ROOT environment, whatever environment is current.
x-lang form:
This is def with the root named instead of the current environment, and it is expressible without a primitive now that environments are values: a def evaluated with the root as its environment binds there. It stays for one release so the langs that call it through the catalog keep working until they move to that spelling; its manifest row goes with it.
| p_base | Base (execution context). |
| p_args | Unevaluated: (self name value); both are evaluated. |
Create a fully initialized sandboxed interpreter base.
x-lang form:
Allocates a new base, registers all built-in types (prim, operative, procedure, symbol, list, int, str, char, whitespace, comment), sets up a read buffer, and registers all C primitives. The result is a complete interpreter context that can be evaluated into via base-eval.
| p_base | Base (execution context) (unused beyond allocation). |
| p_args | Unused. |
Create a bare base suitable for tokenization only.
x-lang form:
Allocates a minimal base with no types or primitives registered, inheriting only the boolean singletons (t/f) from the calling base. Used for custom tokenizer type registration on an isolated base.
| p_base | Base (execution context) (boolean singletons are inherited). |
| p_args | Unused. |