pub struct Env {
pub bindings: Rc<RefCell<HashMap<Spur, Value>>>,
pub parent: Option<Rc<Env>>,
pub version: Cell<u64>,
}Expand description
A Sema environment: a chain of scopes with bindings.
Fields§
§bindings: Rc<RefCell<HashMap<Spur, Value>>>§parent: Option<Rc<Env>>§version: Cell<u64>Implementations§
Source§impl Env
impl Env
pub fn new() -> Self
pub fn with_parent(parent: Rc<Env>) -> Self
Sourcepub fn bump_version(&self)
pub fn bump_version(&self)
Bump the environment’s version counter. The VM’s inline global cache is
keyed on this version, so call this after mutating bindings through a
different Env handle that shares the same bindings Rc but has its own
version cell (e.g. a loaded module body run on a cloned-Env VM), so a
VM observing this Env re-reads instead of serving a stale cached value.
pub fn get(&self, name: Spur) -> Option<Value>
pub fn get_str(&self, name: &str) -> Option<Value>
pub fn set(&self, name: Spur, val: Value)
pub fn set_str(&self, name: &str, val: Value)
Sourcepub fn update(&self, name: Spur, val: Value)
pub fn update(&self, name: Spur, val: Value)
Update a binding that already exists in the current scope.
Sourcepub fn take(&self, name: Spur) -> Option<Value>
pub fn take(&self, name: Spur) -> Option<Value>
Remove and return a binding from the current scope only.
Sourcepub fn take_anywhere(&self, name: Spur) -> Option<Value>
pub fn take_anywhere(&self, name: Spur) -> Option<Value>
Remove and return a binding from any scope in the parent chain.
Sourcepub fn set_existing(&self, name: Spur, val: Value) -> bool
pub fn set_existing(&self, name: Spur, val: Value) -> bool
Set a variable in the scope where it’s defined (for set!).
Sourcepub fn all_names(&self) -> Vec<Spur>
pub fn all_names(&self) -> Vec<Spur>
Collect all bound variable names across all scopes (for suggestions).
Sourcepub fn iter_bindings(&self, f: impl FnMut(Spur, &Value))
pub fn iter_bindings(&self, f: impl FnMut(Spur, &Value))
Iterate over bindings in the current scope only (not parent scopes).
Sourcepub fn get_local(&self, name: Spur) -> Option<Value>
pub fn get_local(&self, name: Spur) -> Option<Value>
Get a binding from the current scope only (not parent scopes).
Sourcepub fn replace_bindings(
&self,
new_bindings: impl IntoIterator<Item = (Spur, Value)>,
)
pub fn replace_bindings( &self, new_bindings: impl IntoIterator<Item = (Spur, Value)>, )
Replace all bindings in the current scope with the given iterator. Used for bulk restore (e.g., undo/rollback).