x-lang

← Index

x/type/base

Base: execution-context / sandbox objects, via the Base class.

(Base make) -> a Base instance wrapping a fresh execution-context; (b eval expr) / (Base eval b expr) evaluates expr inside it, isolated from the outer env.

CONTRACT: a fresh base is the bare C ISA – no display/write, no catalog protocol. Reach in with parent closures or (b bind …); see core/sandbox specs.

Field reflection: (b cell ‘line) walks the layout contract; (Base fields) lists the names. The raw C base rides the raw member; statics and tokenizer seams accept either form.

Class Base

Execution-context / sandbox objects: each base is a whole, isolated interpreter – its own environment, type registry, and reader state – wrapped as a Base instance.

CONTRACT: a fresh base is the bare C ISA – no display/write, no reader macros, no catalog protocol. Reach in with parent closures or (b bind …); see core/sandbox specs.

An instance renders as #; the raw C base it wraps (the `raw` member) renders as the opaque #.

Field access walks the layout contract: (b cell ‘line), names from (Base fields).

raw

The raw C base object this instance wraps – what the C prims and tokenizer doors consume. Read it to hand the base to raw plumbing; (Base wrap r) re-clothes one.

Member: data carried by a Base instance.

(eval expr)

Evaluate expr inside this base, isolated from the outer env. An error raised inside propagates to the caller’s guard; the base’s env is restored to its pre-eval shape on the way out.

Instance method: called on a Base instance.

Parameters:

Returns: ANY — The result of the evaluation

Examples:

(let ((b (Base make))) (b eval '(+ 1 2))) => 3

(bind name val)

Define name as val in this base’s environment, visible to subsequent evals – the door for handing a child selected capabilities.

Instance method: called on a Base instance.

Parameters:

Returns: ANY — val

Examples:

(let ((b (Base make))) (b bind 'x 5) (b eval 'x)) => 5

(make-type name h)

Register a custom type on this base – cross-base make-type. Handler closures are built in the CALLING base and travel with instances; this base is marked shared so the caller’s GC never sweeps them.

Instance method: called on a Base instance.

Parameters:

Returns: ANY — The type handle, for use inside this base

(cell fname)

The object the layout contract’s path addresses for fname, walked from this base. A cell-kind field’s value sits in the cell’s first slot; refuses non-base-rooted names.

What it hands back is raw engine structure. Some of it is a C-built spine – the type-alist field is one – whose nodes answer #f to pair?; walk those with the bare first/rest/null? accessors, never the List or Iter walkers, which refuse them.

Instance method: called on a Base instance.

Parameters:

Returns: ANY — The addressed cell/object

Examples:

(let ((b (Base make))) (%cell-int (first (b cell 'line)))) => 1

(fields)

Every base field name from the layout contract.

Instance method: called on a Base instance.

Returns: LIST — Field name symbols, contract order

(%repr)

Inspection form: # (N = the base's live allocation count).

Instance method: called on a Base instance.

Returns: STRING — The repr string

(Base make)

Create a fully initialized, isolated interpreter base, wrapped as a Base instance: the built-in types, the C prims, and a read buffer – no lib is loaded.

Returns: OBJECT — A Base instance; its raw member is the C base object

Examples:

(let ((b (Base make))) (b eval '(* 6 7))) => 42

(Base make-tok)

Create a minimal tokenizer base, wrapped as a Base instance: no types, no prims – only the boolean singletons are inherited. For custom tokenizer type registration on an isolated base.

Returns: OBJECT — A Base instance

(Base wrap r)

Clothe a raw base object as a Base instance.

Parameters:

Returns: OBJECT — The instance

(Base base? v)

Test whether v is a Base instance.

Parameters:

Returns: BOOL — #t for Base instances only

Examples:

(Base base? 5) => #f

(Base raw-of v)

The raw base object of either form – instances unwrap, anything else passes through. The seam the statics and tokenizer doors use.

Parameters:

Returns: ANY — The raw base object

(Base eval target expr)

Evaluate expr inside target, isolated from the outer env. An error raised in target propagates to the caller’s guard; target’s env is restored to its pre-eval shape on the way out.

Parameters:

Returns: ANY — The result of evaluating expr in target

Examples:

(let ((b (Base make))) (Base eval b '(+ 1 2))) => 3

(Base bind target name val)

Define name as val in target’s environment, visible to subsequent (Base eval target …) forms.

Parameters:

Returns: ANY — val

Examples:

(let ((b (Base make))) (Base bind b 'x 5) (Base eval b 'x)) => 5

(Base make-type target name h)

Register a custom type on target – cross-base make-type. Handler closures are built in the CALLING base and travel with instances; target is marked shared so the caller’s GC never sweeps them.

Parameters:

Returns: ANY — The type handle, for use inside target

(Base cell target fname)

The layout-contract cell for fname, walked from target. Refuses non-base-rooted names.

What it hands back is raw engine structure. Some of it is a C-built spine – the type-alist field is one – whose nodes answer #f to pair?; walk those with the bare first/rest/null? accessors, never the List or Iter walkers, which refuse them.

Parameters:

Returns: ANY — The addressed cell/object

(Base fields)

Every base field name in the layout contract (base-rooted rows of engine/tools/contract/base-paths.x).

Returns: LIST — Field name symbols, contract order