Skip to main content

Slot

Struct Slot 

Source
pub(crate) struct Slot {
    hops: Cell<u32>,
    index: Cell<u32>,
    key: Cell<*const u8>,
}
Expand description

変数の場所の覚え(A1 の段階 1)。何段外のスコープの何番目か。

スコープの連なりは字句の構造で決まるので、同じ命令なら場所は変わらない。名前の検索を省くのが 目的で、圧縮された JS の深い閉包では外側の変数の検索が実行時間の約 1 割を占めていた。key は 束縛の名前の番地で、その場所に同じ束縛があることの確認に使う。 外れるのは、読んだ後で内側に同名の let が宣言される場合だけで、これは本来 TDZ のエラーになる。

Fields§

§hops: Cell<u32>§index: Cell<u32>§key: Cell<*const u8>

Implementations§

Source§

impl Slot

Source

fn with<R>( &self, scope: &Rc<RefCell<Scope>>, f: impl FnOnce(&mut Value) -> R, ) -> Option<R>

覚えた場所の値を読み書きする。

Source

fn with_is_global<R>( &self, scope: &Rc<RefCell<Scope>>, f: impl FnOnce(&mut Value) -> R, ) -> Option<(R, bool)>

覚えた場所の値を読み書きし、そのスコープがグローバルルート(parent.is_none())かも返す。

Source

fn learn(&self, name: &str, scope: &Rc<RefCell<Scope>>)

場所を探して覚える。

Auto Trait Implementations§

§

impl !Freeze for Slot

§

impl !RefUnwindSafe for Slot

§

impl !Send for Slot

§

impl !Sync for Slot

§

impl Unpin for Slot

§

impl UnsafeUnpin for Slot

§

impl UnwindSafe for Slot

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<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> Same for T

Source§

type Output = T

Should always be Self
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, !>

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.