pub struct Interpreter {Show 37 fields
pub globals: Rc<RefCell<Environment>>,
pub environment: Rc<RefCell<Environment>>,
pub types: HashMap<String, TypeDef>,
pub variant_constructors: HashMap<String, (String, String, usize)>,
pub default_structs: HashMap<String, StructDef>,
pub output: Vec<String>,
pub program_args: Option<Vec<String>>,
pub current_module: Option<String>,
pub current_self_type: Option<String>,
pub generic_type_bindings: HashMap<String, String>,
pub current_source_dir: Option<String>,
pub loaded_crates: HashSet<String>,
pub loading_crates: HashSet<String>,
pub project_root: Option<PathBuf>,
pub workspace_members: HashMap<String, PathBuf>,
pub drop_types: HashSet<String>,
pub linear_state: LinearTypeState,
pub mutable_vars: RefCell<HashSet<String>>,
pub var_types: RefCell<HashMap<String, (String, Vec<String>)>>,
pub type_context: TypeConstructionContext,
pub ir_functions: RefCell<Vec<Value>>,
pub ir_traits: RefCell<Vec<Value>>,
pub ir_modules: RefCell<Vec<Value>>,
pub ir_constants: RefCell<Vec<Value>>,
pub ir_impls: RefCell<Vec<Value>>,
pub source_code: RefCell<String>,
pub user_macros: RefCell<HashMap<String, (Vec<String>, String, HashMap<String, String>)>>,
pub source_text: Option<String>,
pub function_spans: HashMap<String, Span>,
pub trait_defs: Vec<TraitDef>,
pub impl_blocks: Vec<ImplBlock>,
pub const_defs: Vec<(String, Span)>,
pub crate_modules: HashSet<String>,
pub crate_name: Option<String>,
pub crate_alias: Option<String>,
pub const_generic_params: HashMap<String, Vec<String>>,
pub const_generic_deferred_consts: HashMap<String, Expr>,
/* private fields */
}Expand description
The Sigil interpreter
Fields§
§globals: Rc<RefCell<Environment>>Global environment
environment: Rc<RefCell<Environment>>Current environment
types: HashMap<String, TypeDef>Type definitions
variant_constructors: HashMap<String, (String, String, usize)>Variant constructors: qualified_name -> (enum_name, variant_name, arity)
default_structs: HashMap<String, StructDef>Structs with #[derive(Default)]
output: Vec<String>Output buffer (for testing)
program_args: Option<Vec<String>>Program arguments (overrides env::args when set)
current_module: Option<String>Current module prefix for registering definitions
current_self_type: Option<String>Current Self type (when inside an impl block)
generic_type_bindings: HashMap<String, String>Generic type parameter bindings (e.g., T -> “F16” during dtype_info·
current_source_dir: Option<String>Current source directory for resolving relative module paths
loaded_crates: HashSet<String>Loaded crates registry (crate_name -> true if loaded)
loading_crates: HashSet<String>Crates currently being loaded (for circular dependency detection)
project_root: Option<PathBuf>Project root directory (where Sigil.toml is located)
workspace_members: HashMap<String, PathBuf>Workspace members: crate_name -> relative path from project root
drop_types: HashSet<String>Types that implement Drop trait - call drop() when they go out of scope
linear_state: LinearTypeStateLinear type tracking state (for no-cloning theorem enforcement)
mutable_vars: RefCell<HashSet<String>>Variables declared as mutable (let mut)
var_types: RefCell<HashMap<String, (String, Vec<String>)>>Variable type annotations (for generic type checking on Vec
type_context: TypeConstructionContextType-directed construction context (for Tensor
ir_functions: RefCell<Vec<Value>>Function definitions for IR export (with span info)
ir_traits: RefCell<Vec<Value>>Trait definitions for IR export (trait_name -> TraitDef)
ir_modules: RefCell<Vec<Value>>Module definitions for IR export
ir_constants: RefCell<Vec<Value>>Constant definitions for IR export
ir_impls: RefCell<Vec<Value>>Impl block definitions for IR export
source_code: RefCell<String>Source code for span-to-line conversion
user_macros: RefCell<HashMap<String, (Vec<String>, String, HashMap<String, String>)>>User-defined macro registry: name -> (params, body_tokens)
params is a Vec
source_text: Option<String>Source text for span-to-line conversion (used by __export_ir)
function_spans: HashMap<String, Span>Function spans for IR export (function_name -> span)
trait_defs: Vec<TraitDef>Raw trait definitions for IR export
impl_blocks: Vec<ImplBlock>Raw impl blocks for IR export
const_defs: Vec<(String, Span)>Constant definitions for IR export (const_name, span)
crate_modules: HashSet<String>Modules in current crate for IR export
crate_name: Option<String>Current crate name for module resolution
crate_alias: Option<String>Alias for current crate (e.g., “tome” for tome commands)
const_generic_params: HashMap<String, Vec<String>>Maps type name → const generic parameter names e.g., “Shape1” → [“N”], “Shape2” → [“M”, “N”]
const_generic_deferred_consts: HashMap<String, Expr>Deferred associated constants for const-generic impl blocks Maps “TypeName·ConstName” → unevaluated AST expression
Implementations§
Source§impl Interpreter
impl Interpreter
pub fn new() -> Self
Sourcepub fn set_program_args(&mut self, args: Vec<String>)
pub fn set_program_args(&mut self, args: Vec<String>)
Set program arguments (overrides env::args for the running program)
Sourcepub fn set_current_module(&mut self, module: Option<String>)
pub fn set_current_module(&mut self, module: Option<String>)
Set current module for registering definitions (module name, not file stem)
Sourcepub fn set_current_source_dir(&mut self, dir: Option<String>)
pub fn set_current_source_dir(&mut self, dir: Option<String>)
Set current source directory for resolving relative module paths
Sourcepub fn set_source_dir(&mut self, dir: String)
pub fn set_source_dir(&mut self, dir: String)
Set source directory for the current program (for module resolution) This is the directory containing the entry point file
Sourcepub fn set_crate_name(&mut self, name: String)
pub fn set_crate_name(&mut self, name: String)
Set the current crate name (for module prefixing)
Sourcepub fn set_crate_alias(&mut self, alias: String)
pub fn set_crate_alias(&mut self, alias: String)
Set an alias for the current crate (e.g., “tome” for tome commands)
Sourcepub fn register_module(&mut self, name: String)
pub fn register_module(&mut self, name: String)
Register a module in the current crate for IR export
Sourcepub fn get_program_args(&self) -> Vec<String>
pub fn get_program_args(&self) -> Vec<String>
Get program arguments (uses overridden args if set, otherwise env::args)
Sourcepub fn discover_project(&mut self, source_dir: &str) -> Result<(), RuntimeError>
pub fn discover_project(&mut self, source_dir: &str) -> Result<(), RuntimeError>
Find and parse Sigil.toml/Grimoire.toml from a source directory, walking up parent directories Looks for a workspace config (one with [workspace] section and members)
Sourcepub fn load_crate(&mut self, crate_name: &str) -> Result<bool, RuntimeError>
pub fn load_crate(&mut self, crate_name: &str) -> Result<bool, RuntimeError>
Load an external crate by name
Sourcepub fn set_source_code(&mut self, source: String)
pub fn set_source_code(&mut self, source: String)
Set the source code for span-to-line conversion
Sourcepub fn execute(&mut self, file: &SourceFile) -> Result<Value, RuntimeError>
pub fn execute(&mut self, file: &SourceFile) -> Result<Value, RuntimeError>
Execute a source file
Sourcepub fn execute_definitions(
&mut self,
file: &SourceFile,
) -> Result<Value, RuntimeError>
pub fn execute_definitions( &mut self, file: &SourceFile, ) -> Result<Value, RuntimeError>
Execute a file but only register definitions, don’t auto-call main. Use this when loading files as part of a multi-file workspace.
pub fn call_function( &mut self, func: &Function, args: Vec<Value>, ) -> Result<Value, RuntimeError>
Sourcepub fn await_value(&mut self, value: Value) -> Result<Value, RuntimeError>
pub fn await_value(&mut self, value: Value) -> Result<Value, RuntimeError>
Await a value - if it’s a future, resolve it; otherwise return as-is
Sourcepub fn make_future_immediate(&self, value: Value) -> Value
pub fn make_future_immediate(&self, value: Value) -> Value
Create a new future from a value
Sourcepub fn make_future_lazy(&self, func: Rc<Function>, args: Vec<Value>) -> Value
pub fn make_future_lazy(&self, func: Rc<Function>, args: Vec<Value>) -> Value
Create a pending future with lazy computation
Sourcepub fn make_future_timer(&self, duration: Duration) -> Value
pub fn make_future_timer(&self, duration: Duration) -> Value
Create a timer future
Sourcepub fn call_function_by_name(
&mut self,
name: &str,
args: Vec<Value>,
) -> Result<Value, RuntimeError>
pub fn call_function_by_name( &mut self, name: &str, args: Vec<Value>, ) -> Result<Value, RuntimeError>
Call a function by name from the environment
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Interpreter
impl !RefUnwindSafe for Interpreter
impl !Send for Interpreter
impl !Sync for Interpreter
impl Unpin 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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§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>
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);