|
|
@ -89,12 +89,11 @@ impl EnvironmentStack { |
|
|
|
.rev() |
|
|
|
.rev() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if let DeclarativeEnvironmentKind::Function(fun) = &env.kind() { |
|
|
|
if let DeclarativeEnvironmentKind::Function(fun) = &env.kind() { |
|
|
|
let compile_bindings_number = env.compile_env().borrow().num_bindings(); |
|
|
|
let compile_bindings_number = env.compile_env().borrow().num_bindings() as usize; |
|
|
|
let mut bindings_mut = fun.poisonable_environment().bindings().borrow_mut(); |
|
|
|
let mut bindings = fun.poisonable_environment().bindings().borrow_mut(); |
|
|
|
|
|
|
|
|
|
|
|
if compile_bindings_number > bindings_mut.len() { |
|
|
|
if compile_bindings_number > bindings.len() { |
|
|
|
let diff = compile_bindings_number - bindings_mut.len(); |
|
|
|
bindings.resize(compile_bindings_number, None); |
|
|
|
bindings_mut.extend(vec![None; diff]); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -223,9 +222,9 @@ impl EnvironmentStack { |
|
|
|
#[track_caller] |
|
|
|
#[track_caller] |
|
|
|
pub(crate) fn push_lexical( |
|
|
|
pub(crate) fn push_lexical( |
|
|
|
&mut self, |
|
|
|
&mut self, |
|
|
|
num_bindings: usize, |
|
|
|
num_bindings: u32, |
|
|
|
compile_environment: Gc<GcRefCell<CompileTimeEnvironment>>, |
|
|
|
compile_environment: Gc<GcRefCell<CompileTimeEnvironment>>, |
|
|
|
) -> usize { |
|
|
|
) -> u32 { |
|
|
|
let (poisoned, with) = { |
|
|
|
let (poisoned, with) = { |
|
|
|
let with = self |
|
|
|
let with = self |
|
|
|
.stack |
|
|
|
.stack |
|
|
@ -243,7 +242,7 @@ impl EnvironmentStack { |
|
|
|
(environment.poisoned(), with || environment.with()) |
|
|
|
(environment.poisoned(), with || environment.with()) |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
let index = self.stack.len(); |
|
|
|
let index = self.stack.len() as u32; |
|
|
|
|
|
|
|
|
|
|
|
self.stack.push(Environment::Declarative(Gc::new( |
|
|
|
self.stack.push(Environment::Declarative(Gc::new( |
|
|
|
DeclarativeEnvironment::new( |
|
|
|
DeclarativeEnvironment::new( |
|
|
@ -267,7 +266,7 @@ impl EnvironmentStack { |
|
|
|
#[track_caller] |
|
|
|
#[track_caller] |
|
|
|
pub(crate) fn push_function( |
|
|
|
pub(crate) fn push_function( |
|
|
|
&mut self, |
|
|
|
&mut self, |
|
|
|
num_bindings: usize, |
|
|
|
num_bindings: u32, |
|
|
|
compile_environment: Gc<GcRefCell<CompileTimeEnvironment>>, |
|
|
|
compile_environment: Gc<GcRefCell<CompileTimeEnvironment>>, |
|
|
|
function_slots: FunctionSlots, |
|
|
|
function_slots: FunctionSlots, |
|
|
|
) { |
|
|
|
) { |
|
|
@ -310,11 +309,11 @@ impl EnvironmentStack { |
|
|
|
#[track_caller] |
|
|
|
#[track_caller] |
|
|
|
pub(crate) fn push_function_inherit( |
|
|
|
pub(crate) fn push_function_inherit( |
|
|
|
&mut self, |
|
|
|
&mut self, |
|
|
|
num_bindings: usize, |
|
|
|
num_bindings: u32, |
|
|
|
compile_environment: Gc<GcRefCell<CompileTimeEnvironment>>, |
|
|
|
compile_environment: Gc<GcRefCell<CompileTimeEnvironment>>, |
|
|
|
) { |
|
|
|
) { |
|
|
|
debug_assert!( |
|
|
|
debug_assert!( |
|
|
|
self.stack.len() == compile_environment.borrow().environment_index(), |
|
|
|
self.stack.len() as u32 == compile_environment.borrow().environment_index(), |
|
|
|
"tried to push an invalid compile environment" |
|
|
|
"tried to push an invalid compile environment" |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
@ -434,13 +433,13 @@ impl EnvironmentStack { |
|
|
|
#[track_caller] |
|
|
|
#[track_caller] |
|
|
|
pub(crate) fn put_lexical_value( |
|
|
|
pub(crate) fn put_lexical_value( |
|
|
|
&mut self, |
|
|
|
&mut self, |
|
|
|
environment_index: usize, |
|
|
|
environment_index: u32, |
|
|
|
binding_index: usize, |
|
|
|
binding_index: u32, |
|
|
|
value: JsValue, |
|
|
|
value: JsValue, |
|
|
|
) { |
|
|
|
) { |
|
|
|
let env = self |
|
|
|
let env = self |
|
|
|
.stack |
|
|
|
.stack |
|
|
|
.get(environment_index) |
|
|
|
.get(environment_index as usize) |
|
|
|
.expect("environment index must be in range") |
|
|
|
.expect("environment index must be in range") |
|
|
|
.declarative_expect(); |
|
|
|
.declarative_expect(); |
|
|
|
env.set(binding_index, value); |
|
|
|
env.set(binding_index, value); |
|
|
@ -454,13 +453,13 @@ impl EnvironmentStack { |
|
|
|
#[track_caller] |
|
|
|
#[track_caller] |
|
|
|
pub(crate) fn put_value_if_uninitialized( |
|
|
|
pub(crate) fn put_value_if_uninitialized( |
|
|
|
&mut self, |
|
|
|
&mut self, |
|
|
|
environment_index: usize, |
|
|
|
environment_index: u32, |
|
|
|
binding_index: usize, |
|
|
|
binding_index: u32, |
|
|
|
value: JsValue, |
|
|
|
value: JsValue, |
|
|
|
) { |
|
|
|
) { |
|
|
|
let env = self |
|
|
|
let env = self |
|
|
|
.stack |
|
|
|
.stack |
|
|
|
.get(environment_index) |
|
|
|
.get(environment_index as usize) |
|
|
|
.expect("environment index must be in range") |
|
|
|
.expect("environment index must be in range") |
|
|
|
.declarative_expect(); |
|
|
|
.declarative_expect(); |
|
|
|
if env.get(binding_index).is_none() { |
|
|
|
if env.get(binding_index).is_none() { |
|
|
@ -520,8 +519,8 @@ impl EnvironmentStack { |
|
|
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Finalize)] |
|
|
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Finalize)] |
|
|
|
pub(crate) struct BindingLocator { |
|
|
|
pub(crate) struct BindingLocator { |
|
|
|
name: Identifier, |
|
|
|
name: Identifier, |
|
|
|
environment_index: usize, |
|
|
|
environment_index: u32, |
|
|
|
binding_index: usize, |
|
|
|
binding_index: u32, |
|
|
|
global: bool, |
|
|
|
global: bool, |
|
|
|
mutate_immutable: bool, |
|
|
|
mutate_immutable: bool, |
|
|
|
silent: bool, |
|
|
|
silent: bool, |
|
|
@ -535,8 +534,8 @@ impl BindingLocator { |
|
|
|
/// Creates a new declarative binding locator that has knows indices.
|
|
|
|
/// Creates a new declarative binding locator that has knows indices.
|
|
|
|
pub(crate) const fn declarative( |
|
|
|
pub(crate) const fn declarative( |
|
|
|
name: Identifier, |
|
|
|
name: Identifier, |
|
|
|
environment_index: usize, |
|
|
|
environment_index: u32, |
|
|
|
binding_index: usize, |
|
|
|
binding_index: u32, |
|
|
|
) -> Self { |
|
|
|
) -> Self { |
|
|
|
Self { |
|
|
|
Self { |
|
|
|
name, |
|
|
|
name, |
|
|
@ -596,12 +595,12 @@ impl BindingLocator { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Returns the environment index of the binding.
|
|
|
|
/// Returns the environment index of the binding.
|
|
|
|
pub(crate) const fn environment_index(&self) -> usize { |
|
|
|
pub(crate) const fn environment_index(&self) -> u32 { |
|
|
|
self.environment_index |
|
|
|
self.environment_index |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Returns the binding index of the binding.
|
|
|
|
/// Returns the binding index of the binding.
|
|
|
|
pub(crate) const fn binding_index(&self) -> usize { |
|
|
|
pub(crate) const fn binding_index(&self) -> u32 { |
|
|
|
self.binding_index |
|
|
|
self.binding_index |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -644,7 +643,8 @@ impl Context<'_> { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for env_index in (locator.environment_index..self.vm.environments.stack.len()).rev() { |
|
|
|
for env_index in (locator.environment_index..self.vm.environments.stack.len() as u32).rev() |
|
|
|
|
|
|
|
{ |
|
|
|
match self.environment_expect(env_index) { |
|
|
|
match self.environment_expect(env_index) { |
|
|
|
Environment::Declarative(env) => { |
|
|
|
Environment::Declarative(env) => { |
|
|
|
if env.poisoned() { |
|
|
|
if env.poisoned() { |
|
|
@ -814,11 +814,11 @@ impl Context<'_> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Return the environment at the given index. Panics if the index is out of range.
|
|
|
|
/// Return the environment at the given index. Panics if the index is out of range.
|
|
|
|
pub(crate) fn environment_expect(&self, index: usize) -> &Environment { |
|
|
|
pub(crate) fn environment_expect(&self, index: u32) -> &Environment { |
|
|
|
self.vm |
|
|
|
self.vm |
|
|
|
.environments |
|
|
|
.environments |
|
|
|
.stack |
|
|
|
.stack |
|
|
|
.get(index) |
|
|
|
.get(index as usize) |
|
|
|
.expect("environment index must be in range") |
|
|
|
.expect("environment index must be in range") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|