Skip to main content

Evaluator

Struct Evaluator 

Source
pub struct Evaluator {
    pub env: Environment,
    pub gas: u64,
    pub gas_limit: u64,
    pub log_output: Vec<String>,
    pub action_names: Vec<String>,
    pub mock_responses: Vec<(String, String, Value)>,
}
Expand description

The core evaluator — walks AST nodes and produces Values.

Fields§

§env: Environment

Variable environment (scoped).

§gas: u64

Gas counter — limits total steps to prevent infinite loops.

§gas_limit: u64

Gas limit.

§log_output: Vec<String>

Captured log output from core.log.

§action_names: Vec<String>

Action names registered in the space (for resolving action references).

§mock_responses: Vec<(String, String, Value)>

Mock capability responses (module, function) → response Value. Used by the test runner for with_responses blocks.

Implementations§

Source§

impl Evaluator

Source

pub fn new(gas_limit: u64) -> Self

Create a new evaluator with the given gas limit.

Source

pub fn eval_expr(&mut self, expr: &Expr) -> EvalResult<Value>

Evaluate an expression to a Value.

Source

pub fn eval_qualified_call( &mut self, module: &str, function: &str, args: &[Expr], ) -> EvalResult<Value>

Evaluate a qualified call: module.function(args).

Source

pub fn eval_if_expr(&mut self, if_expr: &IfExpr) -> EvalResult<Value>

Source

pub fn eval_lambda(&mut self, lambda: &LambdaExpr) -> EvalResult<Value>

Source

pub fn eval_block(&mut self, block: &Block) -> EvalResult<Value>

Execute a block of statements. Returns the value of the last expression, or Nil.

Source

pub fn eval_stmt(&mut self, stmt: &Stmt) -> EvalResult<Value>

Execute a single statement.

Source

pub fn call_stdlib( &mut self, module: &str, function: &str, args: Vec<Value>, ) -> EvalResult<Value>

Call a stdlib function by module and function name.

Source

pub fn structural_eq(&self, a: &Value, b: &Value) -> bool

Deep structural equality. NaN != NaN. Functions always false.

Source

pub fn value_to_display_string(&self, val: &Value) -> String

Convert a Value to its display string (for string interpolation, core.log, etc.)

Source

pub fn string_comparison(&self, _a: &str, _b: &str) -> Ordering

String comparison for ordering (used by string comparison operators). Note: PEPL spec says string comparison compares by length, not lexicographic. This matches the eval_comparison implementation.

Auto Trait Implementations§

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.