Skip to main content

Evaluator

Trait Evaluator 

Source
pub trait Evaluator: Send + Sync {
    // Required methods
    fn eval(
        &self,
        node: &Node,
        scope: &Arc<Scope>,
    ) -> Result<Value, RuntimeError>;
    fn eval_root(&self, scope: &Arc<Scope>) -> Result<Value, RuntimeError>;
    fn run_main(
        &self,
        args: HashMap<String, Value>,
    ) -> Result<Value, RuntimeError>;
    fn force_thunk(&self, thunk: &Arc<Thunk>) -> Result<Value, RuntimeError>;
    fn invoke_closure(
        &self,
        closure: &ClosureData,
        args: &[Value],
    ) -> Result<Value, RuntimeError>;
}
Expand description

Backend-agnostic evaluator contract.

Implementations turn an analyzed AST into a Value. The interface is deliberately object-safe: every method is &self with concrete-type arguments and return values — no generic methods — so hosts can hold a Box<dyn Evaluator> for backend swap or dynamic dispatch.

The five methods cover one full evaluation lifecycle:

  • eval — evaluate a single node (fragment / debug entry).
  • eval_root — evaluate the document attached via Context::with_root as a library / static config.
  • run_main — evaluate the document as an entry program: check host args against the #main(...) signature, bind them, then walk the body.
  • force_thunk — drive a lazy dict entry to a value, caching the result for later accesses.
  • invoke_closure — call a constructed closure value with positional args; the shortest entry point for hosts that treat Relon closures as plain callbacks.

Required Methods§

Source

fn eval(&self, node: &Node, scope: &Arc<Scope>) -> Result<Value, RuntimeError>

Evaluate a single AST node under scope.

Source

fn eval_root(&self, scope: &Arc<Scope>) -> Result<Value, RuntimeError>

Evaluate the document attached via Context::with_root as a library / static config (no #main(...) consultation, no host args).

Source

fn run_main(&self, args: HashMap<String, Value>) -> Result<Value, RuntimeError>

Evaluate the document as an entry program: check args against the file’s #main(...) signature, bind them, then walk the body.

Tuple parameters must be supplied as Value::Tuple (or Value::tuple(...)). Targetless JSON decoding such as serde_json::from_value::<Value> maps JSON arrays to Value::List, which intentionally does not satisfy Tuple<...> parameters; JSON null is rejected unless a host boundary decodes it against an explicit Option<T> or T? target.

Returns NoMainSignature if the file lacks #main(...).

Source

fn force_thunk(&self, thunk: &Arc<Thunk>) -> Result<Value, RuntimeError>

Drive a lazy thunk to a value. The first call evaluates thunk.node under thunk.scope and caches the result; later calls return the cached value.

Source

fn invoke_closure( &self, closure: &ClosureData, args: &[Value], ) -> Result<Value, RuntimeError>

Invoke a constructed closure value with positional args. The shortest entry point when a host wants to call a Relon closure as a plain callback.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§