pub struct InterpreterRe<H> { /* private fields */ }Expand description
An embedded tatara-lisp evaluator, parameterized over the host context
H that registered functions read/write.
Implementations§
Source§impl<H> Interpreter<H>where
H: 'static,
impl<H> Interpreter<H>where
H: 'static,
pub fn new() -> Interpreter<H>
Sourcepub fn set_loader(&mut self, loader: Arc<dyn Loader>)
pub fn set_loader(&mut self, loader: Arc<dyn Loader>)
Replace the source loader. Required for (require ...) to do
anything useful — the default NoLoader rejects every require.
Sourcepub fn modules(&self) -> &ModuleRegistry
pub fn modules(&self) -> &ModuleRegistry
Borrow the module registry. Useful for tests + inspection.
Sourcepub fn register_fn<F>(
&mut self,
name: impl Into<Arc<str>>,
arity: Arity,
callable: F,
)where
F: NativeCallable<H>,
pub fn register_fn<F>(
&mut self,
name: impl Into<Arc<str>>,
arity: Arity,
callable: F,
)where
F: NativeCallable<H>,
Register a native Rust function, exposing it to Lisp code under
name. Re-registering the same name overwrites the prior entry
(last-write-wins) and leaves the global binding intact.
Sourcepub fn register_higher_order_fn<F>(
&mut self,
name: impl Into<Arc<str>>,
arity: Arity,
callable: F,
)where
F: HigherOrderCallable<H>,
pub fn register_higher_order_fn<F>(
&mut self,
name: impl Into<Arc<str>>,
arity: Arity,
callable: F,
)where
F: HigherOrderCallable<H>,
Register a higher-order Rust primitive — receives a Caller so it
can invoke Value::Closure / Value::NativeFn arguments back into
the eval loop. Used for map, filter, fold, apply,
for-each, etc. Same overwrite semantics as register_fn.
Sourcepub fn eval_spanned(
&mut self,
form: &Spanned,
host: &mut H,
) -> Result<Value, EvalError>
pub fn eval_spanned( &mut self, form: &Spanned, host: &mut H, ) -> Result<Value, EvalError>
Evaluate a single already-read spanned form in this interpreter’s
global environment. Macro expansion runs first if any macros are
registered. Bare eval_spanned does NOT register top-level
defmacro — eval_top_form is the entry point for that.
Sourcepub fn eval_program(
&mut self,
forms: &[Spanned],
host: &mut H,
) -> Result<Value, EvalError>
pub fn eval_program( &mut self, forms: &[Spanned], host: &mut H, ) -> Result<Value, EvalError>
Evaluate a slice of forms in order, returning the last result.
Top-level defmacro / defpoint-template / defcheck forms register
into the persistent expander and yield Value::Nil. All other forms
are fully expanded (recursively rewriting macro calls anywhere
in the form tree, with each macro body run through the live
evaluator at expansion time) before being evaluated. This is the
canonical entry point for running a tatara-lisp program — REPL,
embedded host, batch script.
Empty input returns Value::Nil.
Sourcepub fn eval_top_form(
&mut self,
form: &Spanned,
host: &mut H,
) -> Result<Value, EvalError>
pub fn eval_top_form( &mut self, form: &Spanned, host: &mut H, ) -> Result<Value, EvalError>
Evaluate one top-level form: register macros, handle module-
system forms (provide / require), expand, then eval.
Public so embedders that drive the read-eval loop themselves
(REPL, hot-reload watchers) can preserve top-level semantics
without re-implementing the registration handshake.
Sourcepub fn fully_expand(
&mut self,
form: &Spanned,
host: &mut H,
) -> Result<Spanned, EvalError>
pub fn fully_expand( &mut self, form: &Spanned, host: &mut H, ) -> Result<Spanned, EvalError>
Fully expand a form: walk the tree; whenever the head of a list is a registered macro, evaluate the macro body (a regular Lisp program) at expansion time, convert the resulting Value back to a Spanned tree, and recurse — the expansion may itself contain further macro calls.
This is the CL/Racket macro model: the macro body has full access to every primitive and library function, can compute over its argument source forms (which arrive as Lisp data structures — lists of symbols, etc.), and produces code as data.
Sourcepub fn expander(&self) -> &SpannedExpander
pub fn expander(&self) -> &SpannedExpander
Borrow the macro expander. Embedders may register macros directly (e.g. preloaded standard library) without reading them from source.
Sourcepub fn expander_mut(&mut self) -> &mut SpannedExpander
pub fn expander_mut(&mut self) -> &mut SpannedExpander
Mutable access to the expander — for preloading macros via
try_register_macro from a separately-read form list, or clearing
the registry.
Sourcepub fn lookup_global(&self, name: &str) -> Option<Value>
pub fn lookup_global(&self, name: &str) -> Option<Value>
Look up a symbol in the global env.
Sourcepub fn define_global(&mut self, name: impl Into<Arc<str>>, value: Value)
pub fn define_global(&mut self, name: impl Into<Arc<str>>, value: Value)
Bind a value in the global env.
Sourcepub fn globals_snapshot(&self) -> &Env
pub fn globals_snapshot(&self) -> &Env
Borrow the globals env. Used by the VM to snapshot at closure creation time.
Sourcepub fn apply_external_value(
&mut self,
callee: &Value,
args: Vec<Value>,
host: &mut H,
call_span: Span,
) -> Result<Value, EvalError>
pub fn apply_external_value( &mut self, callee: &Value, args: Vec<Value>, host: &mut H, call_span: Span, ) -> Result<Value, EvalError>
External entry point: apply a callable Value (closure or
native fn) with args. Wraps the internal apply_external so
the VM can dispatch to the tree-walker for non-VM callables.
Sourcepub fn eval_program_vm(
&mut self,
forms: &[Spanned],
host: &mut H,
) -> Result<Value, EvalError>
pub fn eval_program_vm( &mut self, forms: &[Spanned], host: &mut H, ) -> Result<Value, EvalError>
Compile + execute a parsed program through the bytecode VM.
Top-level defmacro forms register into the persistent
expander (same as eval_program); every other form is
macro-expanded in place, then a fresh Chunk is compiled and
run. This is the opt-in fast path; eval_program remains the
authoritative tree-walker. Returns the value of the last form.
Sourcepub fn register_typed0<R, F>(&mut self, name: impl Into<Arc<str>>, f: F)
pub fn register_typed0<R, F>(&mut self, name: impl Into<Arc<str>>, f: F)
Register a 0-arity native fn with typed return value.
Sourcepub fn register_typed1<A, R, F>(&mut self, name: impl Into<Arc<str>>, f: F)
pub fn register_typed1<A, R, F>(&mut self, name: impl Into<Arc<str>>, f: F)
Register a 1-arity native fn with typed arg + return.
Sourcepub fn register_typed2<A, B, R, F>(&mut self, name: impl Into<Arc<str>>, f: F)
pub fn register_typed2<A, B, R, F>(&mut self, name: impl Into<Arc<str>>, f: F)
Register a 2-arity native fn with typed args + return.
Sourcepub fn register_typed3<A, B, C, R, F>(
&mut self,
name: impl Into<Arc<str>>,
f: F,
)
pub fn register_typed3<A, B, C, R, F>( &mut self, name: impl Into<Arc<str>>, f: F, )
Register a 3-arity native fn with typed args + return.
Sourcepub fn register_typed4<A, B, C, D, R, F>(
&mut self,
name: impl Into<Arc<str>>,
f: F,
)
pub fn register_typed4<A, B, C, D, R, F>( &mut self, name: impl Into<Arc<str>>, f: F, )
Register a 4-arity native fn with typed args + return.