pub struct Interpreter {
pub env: Environment,
pub effect_handlers: EffectStack,
pub builtins: BuiltinRegistry,
/* private fields */
}Expand description
Tree-walking interpreter for Bock AIR.
Evaluates expressions against a typed AIR tree. The Environment manages
lexical variable bindings; the EffectStack will be used by P5.5 for
algebraic effect dispatch.
Fields§
§env: EnvironmentCurrent variable bindings (nested scopes).
effect_handlers: EffectStackAlgebraic effect handler stack (populated by P5.5).
builtins: BuiltinRegistryBuilt-in method and global function dispatch table.
Implementations§
Source§impl Interpreter
impl Interpreter
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new interpreter with an empty global environment and default built-in functions registered.
Sourcepub fn register_enum(&mut self, enum_name: &str, variants: &[AIRNode])
pub fn register_enum(&mut self, enum_name: &str, variants: &[AIRNode])
Register all variants of an enum declaration in the environment.
- Unit variants become
Value::Enumvalues. - Tuple variants become constructor functions wrapping args in
Value::Enum. - Record (struct) variants become constructor functions producing
Value::Record.
Sourcepub fn register_fn(&mut self, name: &str, params: Vec<String>, body: AIRNode)
pub fn register_fn(&mut self, name: &str, params: Vec<String>, body: AIRNode)
Register a named function in the global environment.
The function is stored in the registry and bound by name so that
Identifier nodes referencing it will resolve to Value::Function.
Sourcepub fn register_fn_with_async(
&mut self,
name: &str,
params: Vec<String>,
body: AIRNode,
is_async: bool,
)
pub fn register_fn_with_async( &mut self, name: &str, params: Vec<String>, body: AIRNode, is_async: bool, )
Register a named function whose body may be async.
When is_async is true, calling the function spawns a tokio task and
returns a Value::Future; when false, it runs inline like a regular
function call.
Sourcepub fn register_impl(&mut self, target: &AIRNode, methods: &[AIRNode])
pub fn register_impl(&mut self, target: &AIRNode, methods: &[AIRNode])
Register methods from an impl block in the method table.
Extracts the target type name and each method’s parameter names + body,
storing them in method_table[type_name][method_name].
Sourcepub fn register_effect(&mut self, effect_name: &str, operations: &[AIRNode])
pub fn register_effect(&mut self, effect_name: &str, operations: &[AIRNode])
Register an effect declaration’s operations so they can be dispatched at runtime through the effect handler stack.
For each operation in the effect, records a mapping from the operation
name to the effect name. When a call like log(msg) is evaluated,
the interpreter checks this map, finds the effect (Logger), resolves
the handler, and dispatches the call.
Sourcepub fn invoke_callback<'life0, 'life1, 'life_self, 'async_recursion>(
&'life_self mut self,
callable: &'life0 Value,
args: &'life1 [Value],
) -> Pin<Box<dyn Future<Output = Result<Value, RuntimeError>> + Send + 'async_recursion>>where
'life0: 'async_recursion,
'life1: 'async_recursion,
'life_self: 'async_recursion,
pub fn invoke_callback<'life0, 'life1, 'life_self, 'async_recursion>(
&'life_self mut self,
callable: &'life0 Value,
args: &'life1 [Value],
) -> Pin<Box<dyn Future<Output = Result<Value, RuntimeError>> + Send + 'async_recursion>>where
'life0: 'async_recursion,
'life1: 'async_recursion,
'life_self: 'async_recursion,
Invoke a callable (function value) using the interpreter’s closure machinery.
This is the public entry point for callback invocation from builtins.
Sourcepub fn eval_expr<'life0, 'life_self, 'async_recursion>(
&'life_self mut self,
node: &'life0 AIRNode,
) -> Pin<Box<dyn Future<Output = Result<Value, RuntimeError>> + Send + 'async_recursion>>where
'life0: 'async_recursion,
'life_self: 'async_recursion,
pub fn eval_expr<'life0, 'life_self, 'async_recursion>(
&'life_self mut self,
node: &'life0 AIRNode,
) -> Pin<Box<dyn Future<Output = Result<Value, RuntimeError>> + Send + 'async_recursion>>where
'life0: 'async_recursion,
'life_self: 'async_recursion,
Evaluate a single AIR expression node and return its runtime value.
Sourcepub fn call_fn_value<'life0, 'life_self, 'async_recursion>(
&'life_self mut self,
val: &'life0 Value,
args: Vec<Value>,
) -> Pin<Box<dyn Future<Output = Result<Value, RuntimeError>> + Send + 'async_recursion>>where
'life0: 'async_recursion,
'life_self: 'async_recursion,
pub fn call_fn_value<'life0, 'life_self, 'async_recursion>(
&'life_self mut self,
val: &'life0 Value,
args: Vec<Value>,
) -> Pin<Box<dyn Future<Output = Result<Value, RuntimeError>> + Send + 'async_recursion>>where
'life0: 'async_recursion,
'life_self: 'async_recursion,
Call a Value::Function by its identity, looking up the closure in
the function registry.
Call a function value with the given arguments.
Sourcepub fn eval_block<'life0, 'life1, 'life_self, 'async_recursion>(
&'life_self mut self,
stmts: &'life0 [AIRNode],
tail: Option<&'life1 AIRNode>,
) -> Pin<Box<dyn Future<Output = Result<Value, RuntimeError>> + Send + 'async_recursion>>where
'life0: 'async_recursion,
'life1: 'async_recursion,
'life_self: 'async_recursion,
pub fn eval_block<'life0, 'life1, 'life_self, 'async_recursion>(
&'life_self mut self,
stmts: &'life0 [AIRNode],
tail: Option<&'life1 AIRNode>,
) -> Pin<Box<dyn Future<Output = Result<Value, RuntimeError>> + Send + 'async_recursion>>where
'life0: 'async_recursion,
'life1: 'async_recursion,
'life_self: 'async_recursion,
Evaluate a block: push scope, execute statements, eval tail expression.
Sourcepub fn try_match_pattern<'life0, 'life1, 'life_self, 'async_recursion>(
&'life_self mut self,
pattern: &'life0 AIRNode,
value: &'life1 Value,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_recursion>>where
'life0: 'async_recursion,
'life1: 'async_recursion,
'life_self: 'async_recursion,
pub fn try_match_pattern<'life0, 'life1, 'life_self, 'async_recursion>(
&'life_self mut self,
pattern: &'life0 AIRNode,
value: &'life1 Value,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_recursion>>where
'life0: 'async_recursion,
'life1: 'async_recursion,
'life_self: 'async_recursion,
Attempt to match value against pattern, binding names into the
current scope. Returns true on a successful match.
Sourcepub fn bind_pattern<'life0, 'life_self, 'async_recursion>(
&'life_self mut self,
pattern: &'life0 AIRNode,
value: Value,
) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_recursion>>where
'life0: 'async_recursion,
'life_self: 'async_recursion,
pub fn bind_pattern<'life0, 'life_self, 'async_recursion>(
&'life_self mut self,
pattern: &'life0 AIRNode,
value: Value,
) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_recursion>>where
'life0: 'async_recursion,
'life_self: 'async_recursion,
Bind value to pattern in the current scope, for use in let.
Sourcepub fn exec_stmt<'life0, 'life_self, 'async_recursion>(
&'life_self mut self,
node: &'life0 AIRNode,
) -> Pin<Box<dyn Future<Output = Result<Option<Value>, RuntimeError>> + Send + 'async_recursion>>where
'life0: 'async_recursion,
'life_self: 'async_recursion,
pub fn exec_stmt<'life0, 'life_self, 'async_recursion>(
&'life_self mut self,
node: &'life0 AIRNode,
) -> Pin<Box<dyn Future<Output = Result<Option<Value>, RuntimeError>> + Send + 'async_recursion>>where
'life0: 'async_recursion,
'life_self: 'async_recursion,
Execute a statement node.
Returns None for pure statements (let bindings, for/while loops,
guard) and Some(value) for expression-statements (including loop
which can yield a break value, and blocks).
Sourcepub fn exec_block<'life0, 'life_self, 'async_recursion>(
&'life_self mut self,
block: &'life0 AIRNode,
) -> Pin<Box<dyn Future<Output = Result<Value, RuntimeError>> + Send + 'async_recursion>>where
'life0: 'async_recursion,
'life_self: 'async_recursion,
pub fn exec_block<'life0, 'life_self, 'async_recursion>(
&'life_self mut self,
block: &'life0 AIRNode,
) -> Pin<Box<dyn Future<Output = Result<Value, RuntimeError>> + Send + 'async_recursion>>where
'life0: 'async_recursion,
'life_self: 'async_recursion,
Execute a block node, returning the value of its tail expression.
Handles NodeKind::Block directly; falls back to eval_expr for any
other node kind so callers can pass bare expression nodes too.
Trait Implementations§
Source§impl CallbackInvoker for Interpreter
impl CallbackInvoker for Interpreter
Source§impl Clone for Interpreter
impl Clone for Interpreter
Source§fn clone(&self) -> Interpreter
fn clone(&self) -> Interpreter
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for Interpreter
impl !RefUnwindSafe for Interpreter
impl Send for Interpreter
impl Sync for Interpreter
impl Unpin for Interpreter
impl UnsafeUnpin for Interpreter
impl !UnwindSafe for Interpreter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);