pub struct Scope {
locals: Vec<Local>,
pub upvalues: Vec<Upvalue>,
by_name: FxHashMap<String, ByName>,
scope_depth: usize,
with_stack_size: usize,
}
Expand description
Represents a scope known during compilation, which can be resolved directly to stack indices.
Fields§
§locals: Vec<Local>
§upvalues: Vec<Upvalue>
§by_name: FxHashMap<String, ByName>
Secondary by-name index over locals.
scope_depth: usize
How many scopes “deep” are these locals?
with_stack_size: usize
Current size of the with
-stack at runtime.
Implementations§
source§impl Scope
impl Scope
sourcepub fn inherit(&self) -> Self
pub fn inherit(&self) -> Self
Inherit scope details from a parent scope (required for correctly nesting scopes in lambdas and thunks when special scope features like dynamic resolution are present).
sourcepub fn has_with(&self) -> bool
pub fn has_with(&self) -> bool
Does this scope currently require dynamic runtime resolution of identifiers that could not be found?
sourcepub fn resolve_local(&mut self, name: &str) -> LocalPosition
pub fn resolve_local(&mut self, name: &str) -> LocalPosition
Resolve the stack index of a statically known local.
sourcepub fn declare_phantom(&mut self, span: Span, initialised: bool) -> LocalIdx
pub fn declare_phantom(&mut self, span: Span, initialised: bool) -> LocalIdx
Declare a local variable that occupies a stack slot and should
be accounted for, but is not directly accessible by users
(e.g. attribute sets used for with
).
sourcepub fn declare_local(
&mut self,
name: String,
span: Span,
) -> (LocalIdx, Option<LocalIdx>)
pub fn declare_local( &mut self, name: String, span: Span, ) -> (LocalIdx, Option<LocalIdx>)
Declare an uninitialised, named local variable.
Returns the LocalIdx
of the new local, and optionally the
index of a previous local shadowed by this one.
pub fn declare_constant(&mut self, name: String) -> LocalIdx
sourcepub fn mark_initialised(&mut self, idx: LocalIdx)
pub fn mark_initialised(&mut self, idx: LocalIdx)
Mark local as initialised after compiling its expression.
sourcepub fn mark_needs_finaliser(&mut self, idx: LocalIdx)
pub fn mark_needs_finaliser(&mut self, idx: LocalIdx)
Mark local as needing a finaliser.
sourcepub fn mark_must_thunk(&mut self, idx: LocalIdx)
pub fn mark_must_thunk(&mut self, idx: LocalIdx)
Mark local as must be wrapped in a thunk. This happens if the local has a reference to itself in its upvalues.
sourcepub fn stack_index(&self, idx: LocalIdx) -> StackIdx
pub fn stack_index(&self, idx: LocalIdx) -> StackIdx
Compute the runtime stack index for a given local by accounting for uninitialised variables at scopes below this one.
sourcepub fn begin_scope(&mut self)
pub fn begin_scope(&mut self)
Increase the current scope depth (e.g. within a new bindings
block, or with
-scope).
sourcepub fn end_scope(&mut self) -> (usize, Vec<Span>)
pub fn end_scope(&mut self) -> (usize, Vec<Span>)
Decrease the scope depth and remove all locals still tracked for the current scope.
Returns the count of locals that were dropped while marked as initialised (used by the compiler to determine whether to emit scope cleanup operations), as well as the spans of the definitions of unused locals (used by the compiler to emit unused binding warnings).
sourcepub fn scope_depth(&self) -> usize
pub fn scope_depth(&self) -> usize
Access the current scope depth.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Scope
impl RefUnwindSafe for Scope
impl Send for Scope
impl Sync for Scope
impl Unpin for Scope
impl UnwindSafe for Scope
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 more