Skip to main content

InterpreterRe

Struct InterpreterRe 

Source
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,

Source

pub fn new() -> Interpreter<H>

Source

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.

Source

pub fn modules(&self) -> &ModuleRegistry

Borrow the module registry. Useful for tests + inspection.

Source

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.

Source

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.

Source

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 defmacroeval_top_form is the entry point for that.

Source

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.

Source

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.

Source

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.

Source

pub fn expander(&self) -> &SpannedExpander

Borrow the macro expander. Embedders may register macros directly (e.g. preloaded standard library) without reading them from source.

Source

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.

Source

pub fn lookup_global(&self, name: &str) -> Option<Value>

Look up a symbol in the global env.

Source

pub fn define_global(&mut self, name: impl Into<Arc<str>>, value: Value)

Bind a value in the global env.

Source

pub fn globals_snapshot(&self) -> &Env

Borrow the globals env. Used by the VM to snapshot at closure creation time.

Source

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.

Source

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.

Source

pub fn register_typed0<R, F>(&mut self, name: impl Into<Arc<str>>, f: F)
where R: IntoValue + 'static, F: Fn(&mut H) -> Result<R, EvalError> + Send + Sync + 'static,

Register a 0-arity native fn with typed return value.

Source

pub fn register_typed1<A, R, F>(&mut self, name: impl Into<Arc<str>>, f: F)
where A: FromValue + 'static, R: IntoValue + 'static, F: Fn(&mut H, A) -> Result<R, EvalError> + Send + Sync + 'static,

Register a 1-arity native fn with typed arg + return.

Source

pub fn register_typed2<A, B, R, F>(&mut self, name: impl Into<Arc<str>>, f: F)
where A: FromValue + 'static, B: FromValue + 'static, R: IntoValue + 'static, F: Fn(&mut H, A, B) -> Result<R, EvalError> + Send + Sync + 'static,

Register a 2-arity native fn with typed args + return.

Source

pub fn register_typed3<A, B, C, R, F>( &mut self, name: impl Into<Arc<str>>, f: F, )
where A: FromValue + 'static, B: FromValue + 'static, C: FromValue + 'static, R: IntoValue + 'static, F: Fn(&mut H, A, B, C) -> Result<R, EvalError> + Send + Sync + 'static,

Register a 3-arity native fn with typed args + return.

Source

pub fn register_typed4<A, B, C, D, R, F>( &mut self, name: impl Into<Arc<str>>, f: F, )
where A: FromValue + 'static, B: FromValue + 'static, C: FromValue + 'static, D: FromValue + 'static, R: IntoValue + 'static, F: Fn(&mut H, A, B, C, D) -> Result<R, EvalError> + Send + Sync + 'static,

Register a 4-arity native fn with typed args + return.

Trait Implementations§

Source§

impl<H> Default for Interpreter<H>
where H: 'static,

Source§

fn default() -> Interpreter<H>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<H> Freeze for Interpreter<H>

§

impl<H> !RefUnwindSafe for Interpreter<H>

§

impl<H> Send for Interpreter<H>

§

impl<H> Sync for Interpreter<H>

§

impl<H> Unpin for Interpreter<H>

§

impl<H> UnsafeUnpin for Interpreter<H>

§

impl<H> !UnwindSafe for Interpreter<H>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.