pub struct Interpreter {Show 19 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 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,
/* 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)
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
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 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 from a source directory, walking up parent directories Looks for a workspace Sigil.toml (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 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> 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);