Skip to main content

Env

Struct Env 

Source
pub struct Env {
    pub bindings: Rc<RefCell<HashMap<Spur, Value>>>,
    pub parent: Option<Rc<Env>>,
    pub version: Rc<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: Rc<Cell<u64>>

Monotonic mutation counter the VM’s inline global cache is keyed on. Held behind an Rc so it travels with bindings: every Env handle cloned from this one shares this same cell. A mutation through any handle (a set! on a loaded unit’s per-form-VM clone, a different frame’s home-globals handle) is therefore observed by a cache entry keyed on any other handle to the same bindings — a fresh cell per clone would let a recursive reader keep serving a value its own handle’s set! never bumped (issue #82). A distinct bindings map (new/with_parent) still gets its own cell, since it is a genuinely independent scope.

Implementations§

Source§

impl Env

Source

pub fn new() -> Self

Source

pub fn with_parent(parent: Rc<Env>) -> Self

Source

pub fn bump_version(&self)

Bump the version counter shared by every handle to this scope’s bindings. The VM’s inline global cache is keyed on it, so bumping after any mutation makes every VM observing this scope (through any clone) re-read instead of serving a stale cached value.

Source

pub fn get(&self, name: Spur) -> Option<Value>

Source

pub fn get_str(&self, name: &str) -> Option<Value>

Source

pub fn set(&self, name: Spur, val: Value)

Source

pub fn set_str(&self, name: &str, val: Value)

Source

pub fn update(&self, name: Spur, val: Value)

Update a binding that already exists in the current scope.

Source

pub fn take(&self, name: Spur) -> Option<Value>

Remove and return a binding from the current scope only.

Source

pub fn take_anywhere(&self, name: Spur) -> Option<Value>

Remove and return a binding from any scope in the parent chain.

Source

pub fn set_existing(&self, name: Spur, val: Value) -> bool

Set a variable in the scope where it’s defined (for set!).

Source

pub fn all_names(&self) -> Vec<Spur>

Collect all bound variable names across all scopes (for suggestions).

Source

pub fn iter_bindings(&self, f: impl FnMut(Spur, &Value))

Iterate over bindings in the current scope only (not parent scopes).

Source

pub fn get_local(&self, name: Spur) -> Option<Value>

Get a binding from the current scope only (not parent scopes).

Source

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).

Trait Implementations§

Source§

impl Clone for Env

Source§

fn clone(&self) -> Env

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Env

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Env

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Env

§

impl !Send for Env

§

impl !Sync for Env

§

impl !UnwindSafe for Env

§

impl Freeze for Env

§

impl Unpin for Env

§

impl UnsafeUnpin for Env

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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.