Skip to content

Truly independent web browser

LibJS: Remove ScopedOperand from the bytecode generator

Shannon Boothd90c6865d2c9
diff --git a/Libraries/LibJS/Rust/src/bytecode/codegen/bindings.rs b/Libraries/LibJS/Rust/src/bytecode/codegen/bindings.rs
index fdadb70682a..f6abc1b4809 100644
--- a/Libraries/LibJS/Rust/src/bytecode/codegen/bindings.rs
+++ b/Libraries/LibJS/Rust/src/bytecode/codegen/bindings.rs
@@ -12,7 +12,6 @@ use crate::bytecode::operand::*;
use super::context::Generator;
use super::environment::BindingLocation;
use super::environment::location_for_instructions;
-use super::registers::ScopedOperand;
pub(super) fn emit_get_binding(
generator: &mut Generator<'_>,
@@ -109,7 +108,7 @@ pub(super) fn emit_get_callee_and_this_from_environment(
let undefined = generator.add_constant_undefined();
generator.emit(op::Mov {
dst: this_value,
- src: undefined.operand(),
+ src: undefined,
});
}
None => {
@@ -198,13 +197,13 @@ pub(super) fn emit_typeof_binding(generator: &mut Generator<'_>, dst: Operand, i
pub(super) enum ResolvedBinding {
/// The environment ResolveBinding found the binding in, or null if the reference is unresolvable.
Environment {
- environment: ScopedOperand,
+ environment: Operand,
identifier: IdentifierTableIndex,
},
/// Whether ResolveGlobalBinding found the binding of an identifier the compiler found no binding of before the
/// global environment, in which case it is stored with SetGlobal.
Global {
- is_resolvable: ScopedOperand,
+ is_resolvable: Operand,
identifier: IdentifierTableIndex,
cache: u32,
},
@@ -213,7 +212,7 @@ pub(super) enum ResolvedBinding {
pub(super) fn emit_set_resolved_binding(
generator: &mut Generator<'_>,
resolved_binding: &ResolvedBinding,
- value: &ScopedOperand,
+ value: Operand,
) {
match resolved_binding {
ResolvedBinding::Environment {
@@ -221,9 +220,9 @@ pub(super) fn emit_set_resolved_binding(
identifier,
} => {
generator.emit(op::SetResolvedBinding {
- environment: environment.operand(),
+ environment: *environment,
identifier: *identifier,
- src: value.operand(),
+ src: value,
});
}
ResolvedBinding::Global {
@@ -234,12 +233,12 @@ pub(super) fn emit_set_resolved_binding(
let set_block = generator.new_label();
let unresolvable_block = generator.new_label();
let end_block = generator.new_label();
- generator.emit_jump_if(is_resolvable, set_block, unresolvable_block);
+ generator.emit_jump_if(*is_resolvable, set_block, unresolvable_block);
generator.bind_reachable_label(set_block);
generator.emit(op::SetGlobal {
identifier: *identifier,
- src: value.operand(),
+ src: value,
cache: *cache,
});
generator.emit(op::Jump { target: end_block });
@@ -248,9 +247,9 @@ pub(super) fn emit_set_resolved_binding(
generator.bind_reachable_label(unresolvable_block);
let null = generator.add_constant_null();
generator.emit(op::SetResolvedBinding {
- environment: null.operand(),
+ environment: null,
identifier: *identifier,
- src: value.operand(),
+ src: value,
});
generator.emit(op::Jump { target: end_block });
diff --git a/Libraries/LibJS/Rust/src/bytecode/codegen/builtins.rs b/Libraries/LibJS/Rust/src/bytecode/codegen/builtins.rs
index 4f7d3f20f7c..eadaf0df6a6 100644
--- a/Libraries/LibJS/Rust/src/bytecode/codegen/builtins.rs
+++ b/Libraries/LibJS/Rust/src/bytecode/codegen/builtins.rs
@@ -17,7 +17,6 @@ use crate::u32_from_usize;
use crate::utf16::Utf16View;
use super::context::Generator;
-use super::registers::ScopedOperand;
/// The abstract operations that are calls of an intrinsic function.
const INTRINSIC_OPERATIONS: &[(&[u16], AbstractOperationKind)] = &[
@@ -118,7 +117,7 @@ impl Generator<'_> {
.iter()
.find(|&&(operation, _)| text == operation)
.expect("a builtin operation takes the arguments it is declared with");
- let callee = self.add_constant_abstract_operation(operation).operand();
+ let callee = self.add_constant_abstract_operation(operation);
let undefined = self.context.constants.add_undefined();
self.put_builtin_call(dst, callee, undefined, arguments);
}
@@ -138,7 +137,7 @@ impl Generator<'_> {
}
/// The constant that the global `name` stands for in the JavaScript of the engine, if it is one.
- pub(super) fn builtin_constant(&mut self, name: Name) -> Option<ScopedOperand> {
+ pub(super) fn builtin_constant(&mut self, name: Name) -> Option<Operand> {
if !self.builtin_abstract_operations_enabled {
return None;
}
diff --git a/Libraries/LibJS/Rust/src/bytecode/codegen/constructs.rs b/Libraries/LibJS/Rust/src/bytecode/codegen/constructs.rs
index d9d9c44c72f..296fe523829 100644
--- a/Libraries/LibJS/Rust/src/bytecode/codegen/constructs.rs
+++ b/Libraries/LibJS/Rust/src/bytecode/codegen/constructs.rs
@@ -38,7 +38,6 @@ use super::generators::generate_await_of_value;
use super::members::*;
use super::nodes::*;
use super::operators::emit_to_primitive_property_key;
-use super::registers::ScopedOperand;
use super::scope::ParameterShape;
use super::scope::ScopeBindings;
use super::stream::ClassPrivateEnvironment;
@@ -461,7 +460,7 @@ impl Generator<'_> {
_ => {
let value = self.sweep_value(first_row, key)?;
// NB: A key is what it is by the time the next one gets evaluated.
- Ok(emit_to_primitive_property_key(self, &ScopedOperand::plain(value)).operand())
+ Ok(emit_to_primitive_property_key(self, value))
}
}
}
@@ -949,7 +948,7 @@ impl Generator<'_> {
body,
row,
catch_position,
- &entry_environment,
+ entry_environment,
first_function,
)?;
self.leave_try_part(finally, end_label);
@@ -960,7 +959,7 @@ impl Generator<'_> {
self.pop_control();
self.set_handler(outer_handler);
let finally = finally as usize;
- let body = self.bind_finally_handler(finally, handler, &entry_environment);
+ let body = self.bind_finally_handler(finally, handler, entry_environment);
self.bind_label(body);
let saved_completion = self.save_completion();
self.sweep_rows(row, finalizer.index() + 1)?;
@@ -982,7 +981,7 @@ impl Generator<'_> {
body: NodeId,
first_row: usize,
position: u32,
- entry_environment: &ScopedOperand,
+ entry_environment: Operand,
first_function: u32,
) -> Result<(), OutOfStack> {
let tree = self.tree;
@@ -1199,10 +1198,7 @@ impl Generator<'_> {
cache,
});
let zero = self.add_constant_i32(0);
- self.put(op::Mov {
- dst: cursor,
- src: zero.operand(),
- });
+ self.put(op::Mov { dst: cursor, src: zero });
self.bind_reachable_label(update_label);
self.put(op::ObjectPropertyIteratorNext {
@@ -1298,19 +1294,19 @@ impl Generator<'_> {
let call_feedback = self.next_call_feedback();
self.emit(op::Call {
call_feedback,
- dst: result.operand(),
+ dst: result,
callee: next,
this_value: object,
argument_count: 0,
arguments: &[],
});
- let awaited = generate_await_of_value(self, &result);
- self.put(op::ThrowIfNotObject { src: awaited.operand() });
+ let awaited = generate_await_of_value(self, result);
+ self.put(op::ThrowIfNotObject { src: awaited });
let done_key = self.intern_property_key_text(crate::utf16::Utf16View::Ascii(b"done"));
- emit_get_by_key(self, &ScopedOperand::plain(done), &awaited, done_key);
+ emit_get_by_key(self, done, awaited, done_key);
self.jump_if(done, end_label);
let value_key = self.intern_property_key_text(crate::utf16::Utf16View::Ascii(b"value"));
- emit_get_by_key(self, &ScopedOperand::plain(value), &awaited, value_key);
+ emit_get_by_key(self, value, awaited, value_key);
self.release_held_registers(held);
} else {
self.put(op::IteratorNextUnpack {
@@ -1332,7 +1328,7 @@ impl Generator<'_> {
self.set_handler(outer_handler);
self.bind_reachable_label(close_handler.label);
- self.close_iterator_after_exception(iterator, &entry_environment);
+ self.close_iterator_after_exception(iterator, entry_environment);
self.bind_label(end_label);
self.context.scope.block_end();
@@ -1342,7 +1338,7 @@ impl Generator<'_> {
}
/// Closes an iterator on the way to whoever handles an exception, which stays what gets thrown.
- fn close_iterator_after_exception(&mut self, iterator: OpenIterator, entry_environment: &ScopedOperand) {
+ fn close_iterator_after_exception(&mut self, iterator: OpenIterator, entry_environment: Operand) {
let error = self.temporary();
let value_feedback = self.next_value_feedback();
self.put(op::Catch {
@@ -1797,7 +1793,7 @@ impl Generator<'_> {
let position = self.current_source_offset;
let key_value = self.sweep_value(row, key)?;
self.current_source_offset = position;
- let converted = emit_to_primitive_property_key(self, &ScopedOperand::plain(key_value)).operand();
+ let converted = emit_to_primitive_property_key(self, key_value);
if has_rest {
excluded_names.push(converted);
// NB: Rest needs this key after the other properties have been bound.
@@ -1822,12 +1818,7 @@ impl Generator<'_> {
self.put_get_by_id(property_value, object, Name(tree.node_a(key)));
} else {
let property_key = self.intern_property_key_text(text.view());
- emit_get_by_key(
- self,
- &ScopedOperand::plain(property_value),
- &ScopedOperand::plain(object),
- property_key,
- );
+ emit_get_by_key(self, property_value, object, property_key);
}
if has_rest {
let name = match &text {
@@ -1993,7 +1984,7 @@ impl Generator<'_> {
});
self.jump(end_label);
self.bind_reachable_label(close_handler.label);
- self.close_iterator_after_exception(iterator, &entry_environment);
+ self.close_iterator_after_exception(iterator, entry_environment);
self.bind_label(end_label);
self.release_held_registers(held);
Ok(())
diff --git a/Libraries/LibJS/Rust/src/bytecode/codegen/context.rs b/Libraries/LibJS/Rust/src/bytecode/codegen/context.rs
index 891da701997..f9866562c12 100644
--- a/Libraries/LibJS/Rust/src/bytecode/codegen/context.rs
+++ b/Libraries/LibJS/Rust/src/bytecode/codegen/context.rs
@@ -38,7 +38,6 @@ use super::environment::EnclosingEnvironmentScope;
use super::environment::EnvironmentCoordinateScope;
use super::names::NameClass;
use super::names::NameTables;
-use super::registers::ScopedOperand;
/// The most entries that a table keeps its memory for when the next compile takes over.
pub(super) const MAXIMUM_SPARE_CAPACITY: usize = 1024;
@@ -58,7 +57,7 @@ pub struct CodegenContext {
pub(super) constants: ConstantTable,
pub(super) names: NameTables,
- pub(super) lexical_environment_register_stack: Vec<ScopedOperand>,
+ pub(super) lexical_environment_register_stack: Vec<Operand>,
pub(super) environment_coordinate_scope_stack: Vec<EnvironmentCoordinateScope>,
pub(super) initialized_locals: Vec<bool>,
pub(super) initialized_arguments: Vec<bool>,
@@ -227,46 +226,40 @@ impl<'t> Generator<'t> {
/// Allocate a new register (or reuse a freed one).
#[inline(always)]
- pub(super) fn allocate_register(&mut self) -> ScopedOperand {
- ScopedOperand::plain(self.held_register())
- }
-
- /// An operand that is not an allocated register, which stays valid for as long as the code runs.
- #[inline(always)]
- pub(super) fn scoped_operand(&mut self, operand: Operand) -> ScopedOperand {
- ScopedOperand::plain(operand)
+ pub(super) fn allocate_register(&mut self) -> Operand {
+ self.held_register()
}
// --- Constant pool ---
#[inline(always)]
- pub(super) fn add_constant_number(&mut self, value: f64) -> ScopedOperand {
- ScopedOperand::plain(self.context.constants.add_number(value))
+ pub(super) fn add_constant_number(&mut self, value: f64) -> Operand {
+ self.context.constants.add_number(value)
}
#[inline(always)]
- pub(super) fn add_constant_i32(&mut self, value: i32) -> ScopedOperand {
+ pub(super) fn add_constant_i32(&mut self, value: i32) -> Operand {
self.add_constant_number(f64::from(value))
}
#[inline(always)]
- pub(super) fn add_constant_boolean(&mut self, value: bool) -> ScopedOperand {
- ScopedOperand::plain(self.context.constants.add_boolean(value))
+ pub(super) fn add_constant_boolean(&mut self, value: bool) -> Operand {
+ self.context.constants.add_boolean(value)
}
#[inline(always)]
- pub(super) fn add_constant_null(&mut self) -> ScopedOperand {
- ScopedOperand::plain(self.context.constants.add_null())
+ pub(super) fn add_constant_null(&mut self) -> Operand {
+ self.context.constants.add_null()
}
#[inline(always)]
- pub(super) fn add_constant_undefined(&mut self) -> ScopedOperand {
- ScopedOperand::plain(self.context.constants.add_undefined())
+ pub(super) fn add_constant_undefined(&mut self) -> Operand {
+ self.context.constants.add_undefined()
}
#[inline(always)]
- pub(super) fn add_constant_string(&mut self, value: Utf16String) -> ScopedOperand {
- ScopedOperand::plain(self.context.constants.add_string(value))
+ pub(super) fn add_constant_string(&mut self, value: Utf16String) -> Operand {
+ self.context.constants.add_string(value)
}
/// A constant of the string `text`.
@@ -276,22 +269,22 @@ impl<'t> Generator<'t> {
context.constants.add_string_view(text, &mut context.names)
}
- pub(super) fn add_constant_bigint(&mut self, value: String) -> ScopedOperand {
- ScopedOperand::plain(self.context.constants.add_bigint(value))
+ pub(super) fn add_constant_bigint(&mut self, value: String) -> Operand {
+ self.context.constants.add_bigint(value)
}
- pub(super) fn add_constant_well_known_symbol(&mut self, symbol: WellKnownSymbolKind) -> ScopedOperand {
- ScopedOperand::plain(self.context.constants.add_well_known_symbol(symbol))
+ pub(super) fn add_constant_well_known_symbol(&mut self, symbol: WellKnownSymbolKind) -> Operand {
+ self.context.constants.add_well_known_symbol(symbol)
}
- pub(super) fn add_constant_abstract_operation(&mut self, operation: AbstractOperationKind) -> ScopedOperand {
- ScopedOperand::plain(self.context.constants.add_abstract_operation(operation))
+ pub(super) fn add_constant_abstract_operation(&mut self, operation: AbstractOperationKind) -> Operand {
+ self.context.constants.add_abstract_operation(operation)
}
/// Get the constant value for a constant operand.
#[inline(always)]
- pub(super) fn get_constant(&self, operand: &ScopedOperand) -> Option<&ConstantValue> {
- self.context.constants.get(operand.operand())
+ pub(super) fn get_constant(&self, operand: Operand) -> Option<&ConstantValue> {
+ self.context.constants.get(operand)
}
// --- Table interning ---
@@ -332,12 +325,9 @@ impl<'t> Generator<'t> {
}
/// If `operand` is a constant string that is not an array index, intern it as a property key and return the index.
- pub(super) fn try_constant_string_to_property_key(
- &mut self,
- operand: &ScopedOperand,
- ) -> Option<PropertyKeyTableIndex> {
+ pub(super) fn try_constant_string_to_property_key(&mut self, operand: Operand) -> Option<PropertyKeyTableIndex> {
let context = &mut *self.context;
- let ConstantValue::String(string) = context.constants.get(operand.operand())? else {
+ let ConstantValue::String(string) = context.constants.get(operand)? else {
return None;
};
if crate::bytecode::constant_fold::is_array_index(&string.to_utf16()) {
@@ -399,19 +389,16 @@ impl<'t> Generator<'t> {
/// Emit a Mov instruction (optimized away if src == dst).
#[inline(always)]
- pub(super) fn emit_mov(&mut self, dst: &ScopedOperand, src: &ScopedOperand) {
+ pub(super) fn emit_mov(&mut self, dst: Operand, src: Operand) {
if dst != src {
- self.emit(op::Mov {
- dst: dst.operand(),
- src: src.operand(),
- });
+ self.emit(op::Mov { dst, src });
}
}
/// Emit a conditional jump, with comparison fusion and constant folding.
- pub(super) fn emit_jump_if(&mut self, condition: &ScopedOperand, true_target: Label, false_target: Label) {
+ pub(super) fn emit_jump_if(&mut self, condition: Operand, true_target: Label, false_target: Label) {
self.emit(op::JumpIf {
- condition: condition.operand(),
+ condition,
true_target,
false_target,
});
@@ -492,25 +479,25 @@ impl<'t> Generator<'t> {
}
impl ConstantPool for Generator<'_> {
- type Operand = ScopedOperand;
+ type Operand = Operand;
- fn get_constant(&self, operand: &ScopedOperand) -> Option<&ConstantValue> {
- Generator::get_constant(self, operand)
+ fn get_constant(&self, operand: &Operand) -> Option<&ConstantValue> {
+ Generator::get_constant(self, *operand)
}
- fn add_constant_number(&mut self, value: f64) -> ScopedOperand {
+ fn add_constant_number(&mut self, value: f64) -> Operand {
Generator::add_constant_number(self, value)
}
- fn add_constant_boolean(&mut self, value: bool) -> ScopedOperand {
+ fn add_constant_boolean(&mut self, value: bool) -> Operand {
Generator::add_constant_boolean(self, value)
}
- fn add_constant_string(&mut self, value: Utf16String) -> ScopedOperand {
+ fn add_constant_string(&mut self, value: Utf16String) -> Operand {
Generator::add_constant_string(self, value)
}
- fn add_constant_bigint(&mut self, value: String) -> ScopedOperand {
+ fn add_constant_bigint(&mut self, value: String) -> Operand {
Generator::add_constant_bigint(self, value)
}
}
diff --git a/Libraries/LibJS/Rust/src/bytecode/codegen/environment.rs b/Libraries/LibJS/Rust/src/bytecode/codegen/environment.rs
index 5d309276ca6..45ff2d09856 100644
--- a/Libraries/LibJS/Rust/src/bytecode/codegen/environment.rs
+++ b/Libraries/LibJS/Rust/src/bytecode/codegen/environment.rs
@@ -19,7 +19,6 @@ use crate::fast_hash::HashMap;
use crate::u32_from_usize;
use super::context::Generator;
-use super::registers::ScopedOperand;
/// What a function closes over of an environment, as of the moment that the function came up.
pub struct EnclosingEnvironmentScope {
@@ -135,18 +134,18 @@ impl Drop for EnvironmentCoordinateScope {
}
impl Generator<'_> {
- pub(super) fn current_lexical_environment(&mut self) -> ScopedOperand {
+ pub(super) fn current_lexical_environment(&mut self) -> Operand {
self.context
.lexical_environment_register_stack
.last()
.cloned()
- .unwrap_or_else(|| self.scoped_operand(Operand::register(Register::SAVED_LEXICAL_ENVIRONMENT)))
+ .unwrap_or_else(|| Operand::register(Register::SAVED_LEXICAL_ENVIRONMENT))
}
pub(super) fn capture_saved_lexical_environment_with_coordinates(&mut self, has_function_environment: bool) {
- let env_reg = self.scoped_operand(Operand::register(Register::SAVED_LEXICAL_ENVIRONMENT));
+ let env_reg = Operand::register(Register::SAVED_LEXICAL_ENVIRONMENT);
if self.creates_environment {
- self.emit(op::GetLexicalEnvironment { dst: env_reg.operand() });
+ self.emit(op::GetLexicalEnvironment { dst: env_reg });
}
if !has_function_environment {
self.push_untracked_lexical_environment(env_reg);
@@ -158,48 +157,46 @@ impl Generator<'_> {
/// Makes `environment` the running one again, on the way out of an environment or at the start of a handler, where
/// exception unwinding left the running environment as it was. Code that never changes it has nothing to restore.
#[inline(always)]
- pub(super) fn restore_lexical_environment(&mut self, environment: &ScopedOperand) {
+ pub(super) fn restore_lexical_environment(&mut self, environment: Operand) {
if self.creates_environment {
- self.emit(op::SetLexicalEnvironment {
- environment: environment.operand(),
- });
+ self.emit(op::SetLexicalEnvironment { environment });
}
}
- pub(super) fn push_new_lexical_environment(&mut self, capacity: u32) -> ScopedOperand {
+ pub(super) fn push_new_lexical_environment(&mut self, capacity: u32) -> Operand {
self.push_new_lexical_environment_impl(capacity, false)
}
- fn push_new_lexical_environment_impl(&mut self, capacity: u32, is_catch_environment: bool) -> ScopedOperand {
+ fn push_new_lexical_environment_impl(&mut self, capacity: u32, is_catch_environment: bool) -> Operand {
let parent = self.current_lexical_environment();
let new_env = self.allocate_register();
let shape_cache = self.next_environment_shape_cache();
self.emit(op::CreateLexicalEnvironment {
- dst: new_env.operand(),
- parent: parent.operand(),
+ dst: new_env,
+ parent,
capacity,
shape_cache,
is_catch_environment,
});
- self.push_static_lexical_environment(new_env.clone());
+ self.push_static_lexical_environment(new_env);
new_env
}
- pub(super) fn push_untracked_lexical_environment(&mut self, environment: ScopedOperand) {
+ pub(super) fn push_untracked_lexical_environment(&mut self, environment: Operand) {
self.context.lexical_environment_register_stack.push(environment);
}
- pub(super) fn push_static_lexical_environment(&mut self, environment: ScopedOperand) {
+ pub(super) fn push_static_lexical_environment(&mut self, environment: Operand) {
self.push_untracked_lexical_environment(environment);
self.push_environment_coordinate_scope(EnvironmentCoordinateScopeKind::Static);
}
- pub(super) fn push_dynamic_lexical_environment(&mut self, environment: ScopedOperand) {
+ pub(super) fn push_dynamic_lexical_environment(&mut self, environment: Operand) {
self.push_untracked_lexical_environment(environment);
self.push_environment_coordinate_scope(EnvironmentCoordinateScopeKind::Dynamic);
}
- pub(super) fn push_static_variable_environment(&mut self, environment: ScopedOperand) {
+ pub(super) fn push_static_variable_environment(&mut self, environment: Operand) {
self.push_static_lexical_environment(environment);
let scope_index = self.context.environment_coordinate_scope_stack.len() - 1;
self.context.environment_coordinate_scope_stack[scope_index].stops_unresolved_lookups =
@@ -207,11 +204,11 @@ impl Generator<'_> {
self.variable_environment_coordinate_scope_index = Some(scope_index);
}
- pub(super) fn pop_untracked_lexical_environment(&mut self) -> Option<ScopedOperand> {
+ pub(super) fn pop_untracked_lexical_environment(&mut self) -> Option<Operand> {
self.context.lexical_environment_register_stack.pop()
}
- pub(super) fn pop_tracked_lexical_environment(&mut self) -> Option<ScopedOperand> {
+ pub(super) fn pop_tracked_lexical_environment(&mut self) -> Option<Operand> {
self.pop_environment_coordinate_scope();
self.pop_untracked_lexical_environment()
}
diff --git a/Libraries/LibJS/Rust/src/bytecode/codegen/generators.rs b/Libraries/LibJS/Rust/src/bytecode/codegen/generators.rs
index e1b65ba6b38..84c60882d52 100644
--- a/Libraries/LibJS/Rust/src/bytecode/codegen/generators.rs
+++ b/Libraries/LibJS/Rust/src/bytecode/codegen/generators.rs
@@ -14,7 +14,6 @@ use crate::bytecode::operand::*;
use crate::utf16::Utf16View;
use super::context::Generator;
-use super::registers::ScopedOperand;
use super::stream::Exit;
#[derive(Clone, Copy, PartialEq, Eq)]
@@ -26,29 +25,24 @@ enum YieldBehavior {
/// The register that a resumed function finds what it was resumed with in.
#[inline(always)]
-fn accumulator(generator: &mut Generator<'_>) -> ScopedOperand {
- generator.scoped_operand(Operand::register(Register::ACCUMULATOR))
+fn accumulator(_generator: &mut Generator<'_>) -> Operand {
+ Operand::register(Register::ACCUMULATOR)
}
/// Emit a property access by a name of the iteration protocol, which is not "length".
-fn emit_get_by_known_name(
- generator: &mut Generator<'_>,
- dst: &ScopedOperand,
- base: &ScopedOperand,
- name: Utf16View<'_>,
-) {
+fn emit_get_by_known_name(generator: &mut Generator<'_>, dst: Operand, base: Operand, name: Utf16View<'_>) {
let key = generator.intern_property_key_text(name);
let cache = generator.next_property_lookup_cache();
generator.emit(op::GetById {
- dst: dst.operand(),
- base: base.operand(),
+ dst,
+ base,
property: key,
cache,
});
}
/// Generate bytecode that awaits `value`.
-pub(super) fn generate_await_of_value(generator: &mut Generator<'_>, value: &ScopedOperand) -> ScopedOperand {
+pub(super) fn generate_await_of_value(generator: &mut Generator<'_>, value: Operand) -> Operand {
// Allocate received_completion registers before the await.
let received_completion = generator.allocate_register();
let received_completion_type = generator.allocate_register();
@@ -56,21 +50,21 @@ pub(super) fn generate_await_of_value(generator: &mut Generator<'_>, value: &Sco
generate_await_with_completions(
generator,
value,
- &received_completion,
- &received_completion_type,
- &received_completion_value,
+ received_completion,
+ received_completion_type,
+ received_completion_value,
)
}
/// Generate bytecode that yields `value`, and goes on with what the generator gets resumed with.
pub(super) fn generate_yield_of_value(
generator: &mut Generator<'_>,
- value: ScopedOperand,
+ value: Operand,
is_yield_from: bool,
- received_completion: &ScopedOperand,
- received_completion_type: &ScopedOperand,
- received_completion_value: &ScopedOperand,
-) -> ScopedOperand {
+ received_completion: Operand,
+ received_completion_type: Operand,
+ received_completion_value: Operand,
+) -> Operand {
if is_yield_from {
return generate_yield_from(
generator,
@@ -88,7 +82,7 @@ pub(super) fn generate_yield_of_value(
generate_yield(
generator,
continuation_block,
- &value,
+ value,
received_completion,
received_completion_type,
received_completion_value,
@@ -104,11 +98,11 @@ pub(super) fn generate_yield_of_value(
// Restore exception register after resuming.
let acc = accumulator(generator);
- generator.emit_mov(received_completion, &acc);
+ generator.emit_mov(received_completion, acc);
generator.emit(op::GetCompletionFields {
- type_dst: received_completion_type.operand(),
- value_dst: received_completion_value.operand(),
- completion: received_completion.operand(),
+ type_dst: received_completion_type,
+ value_dst: received_completion_value,
+ completion: received_completion,
});
let normal_block = generator.new_label();
@@ -118,11 +112,11 @@ pub(super) fn generate_yield_of_value(
let arith_feedback = generator.next_arith_feedback();
generator.emit(op::StrictlyEquals {
arith_feedback,
- dst: type_is_normal.operand(),
- lhs: received_completion_type.operand(),
- rhs: normal_type.operand(),
+ dst: type_is_normal,
+ lhs: received_completion_type,
+ rhs: normal_type,
});
- generator.emit_jump_if(&type_is_normal, normal_block, throw_cont);
+ generator.emit_jump_if(type_is_normal, normal_block, throw_cont);
let throw_value_block = generator.new_label();
let return_value_block = generator.new_label();
@@ -133,56 +127,56 @@ pub(super) fn generate_yield_of_value(
let arith_feedback = generator.next_arith_feedback();
generator.emit(op::StrictlyEquals {
arith_feedback,
- dst: type_is_throw.operand(),
- lhs: received_completion_type.operand(),
- rhs: throw_type.operand(),
+ dst: type_is_throw,
+ lhs: received_completion_type,
+ rhs: throw_type,
});
- generator.emit_jump_if(&type_is_throw, throw_value_block, return_value_block);
+ generator.emit_jump_if(type_is_throw, throw_value_block, return_value_block);
generator.bind_reachable_label(throw_value_block);
generator.emit(op::Throw {
- src: received_completion_value.operand(),
+ src: received_completion_value,
});
generator.bind_reachable_label(return_value_block);
- generator.emit_exit(Exit::Return, received_completion_value.operand());
+ generator.emit_exit(Exit::Return, received_completion_value);
generator.bind_reachable_label(normal_block);
- received_completion_value.clone()
+ received_completion_value
}
/// Await `argument` and capture its completion without propagating a rejection.
fn generate_await_completion(
generator: &mut Generator<'_>,
- argument: &ScopedOperand,
- received_completion: &ScopedOperand,
- received_completion_type: &ScopedOperand,
- received_completion_value: &ScopedOperand,
+ argument: Operand,
+ received_completion: Operand,
+ received_completion_type: Operand,
+ received_completion_value: Operand,
) {
let continuation = generator.new_label();
generator.emit(op::Await {
continuation_label: continuation,
- argument: argument.operand(),
+ argument,
});
generator.bind_reachable_label(continuation);
let acc = accumulator(generator);
- generator.emit_mov(received_completion, &acc);
+ generator.emit_mov(received_completion, acc);
generator.emit(op::GetCompletionFields {
- type_dst: received_completion_type.operand(),
- value_dst: received_completion_value.operand(),
- completion: received_completion.operand(),
+ type_dst: received_completion_type,
+ value_dst: received_completion_value,
+ completion: received_completion,
});
}
/// Await `argument` using caller-provided completion registers, throwing on rejection.
pub(super) fn generate_await_with_completions(
generator: &mut Generator<'_>,
- argument: &ScopedOperand,
- received_completion: &ScopedOperand,
- received_completion_type: &ScopedOperand,
- received_completion_value: &ScopedOperand,
-) -> ScopedOperand {
+ argument: Operand,
+ received_completion: Operand,
+ received_completion_type: Operand,
+ received_completion_value: Operand,
+) -> Operand {
generate_await_completion(
generator,
argument,
@@ -197,19 +191,19 @@ pub(super) fn generate_await_with_completions(
let arith_feedback = generator.next_arith_feedback();
generator.emit(op::JumpStrictlyEquals {
arith_feedback,
- lhs: received_completion_type.operand(),
- rhs: normal_type.operand(),
+ lhs: received_completion_type,
+ rhs: normal_type,
true_target: normal_block,
false_target: throw_block,
});
generator.bind_reachable_label(throw_block);
generator.emit(op::Throw {
- src: received_completion_value.operand(),
+ src: received_completion_value,
});
generator.bind_reachable_label(normal_block);
- received_completion_value.clone()
+ received_completion_value
}
/// Yield* (yield from) delegation.
@@ -220,11 +214,11 @@ pub(super) fn generate_await_with_completions(
/// The delegating generator forwards next/throw/return to the inner iterator.
fn generate_yield_from(
generator: &mut Generator<'_>,
- value: ScopedOperand,
- received_completion: &ScopedOperand,
- received_completion_type: &ScopedOperand,
- received_completion_value: &ScopedOperand,
-) -> ScopedOperand {
+ value: Operand,
+ received_completion: Operand,
+ received_completion_type: Operand,
+ received_completion_value: Operand,
+) -> Operand {
let is_async = generator.is_in_async_generator_function();
// 4. Let iteratorRecord be ? GetIterator(value, generatorKind).
@@ -238,10 +232,10 @@ fn generate_yield_from(
} as u8;
let cache = generator.next_property_lookup_cache();
generator.emit(op::GetIterator {
- dst_iterator_object: iterator.operand(),
- dst_iterator_next: next_method.operand(),
- dst_iterator_done: iterator_done_property.operand(),
- iterable: value.operand(),
+ dst_iterator_object: iterator,
+ dst_iterator_next: next_method,
+ dst_iterator_done: iterator_done_property,
+ iterable: value,
hint,
// NB: yield* passes the iterator to calls of its methods.
fast_array_mode_allowed: false,
@@ -250,9 +244,9 @@ fn generate_yield_from(
// 6. Let received be NormalCompletion(undefined).
let normal_const = generator.add_constant_number(f64::from(CompletionType::Normal as u8));
- generator.emit_mov(received_completion_type, &normal_const);
+ generator.emit_mov(received_completion_type, normal_const);
let undef = generator.add_constant_undefined();
- generator.emit_mov(received_completion_value, &undef);
+ generator.emit_mov(received_completion_value, undef);
// 7. Repeat,
let loop_block = generator.new_label();
@@ -268,11 +262,11 @@ fn generate_yield_from(
let arith_feedback = generator.next_arith_feedback();
generator.emit(op::StrictlyEquals {
arith_feedback,
- dst: is_normal.operand(),
- lhs: received_completion_type.operand(),
- rhs: normal_const.operand(),
+ dst: is_normal,
+ lhs: received_completion_type,
+ rhs: normal_const,
});
- generator.emit_jump_if(&is_normal, type_is_normal_block, is_type_throw_block);
+ generator.emit_jump_if(is_normal, type_is_normal_block, is_type_throw_block);
// =========================================================================
// a. If received.[[Type]] is normal, then
@@ -284,42 +278,40 @@ fn generate_yield_from(
let call_feedback = generator.next_call_feedback();
generator.emit(op::Call {
call_feedback,
- dst: inner_result.operand(),
- callee: next_method.operand(),
- this_value: iterator.operand(),
+ dst: inner_result,
+ callee: next_method,
+ this_value: iterator,
argument_count: 1,
- arguments: &[received_completion_value.operand()],
+ arguments: &[received_completion_value],
});
// ii. If _generatorKind_ is ~async~, set _innerResult_ to ? Await(_innerResult_).
if is_async {
let awaited = generate_await_with_completions(
generator,
- &inner_result,
+ inner_result,
received_completion,
received_completion_type,
received_completion_value,
);
- generator.emit_mov(&inner_result, &awaited);
+ generator.emit_mov(inner_result, awaited);
}
// iii. If _innerResult_ is not an Object, throw a *TypeError* exception.
- generator.emit(op::ThrowIfNotObject {
- src: inner_result.operand(),
- });
+ generator.emit(op::ThrowIfNotObject { src: inner_result });
// iv. Let _done_ be ? IteratorComplete(_innerResult_).
let done = generator.allocate_register();
- emit_get_by_known_name(generator, &done, &inner_result, utf16!("done").into());
+ emit_get_by_known_name(generator, done, inner_result, utf16!("done").into());
// v. If _done_ is *true*, then return ? IteratorValue(_innerResult_).
let type_is_normal_done_block = generator.new_label();
let type_is_normal_not_done_block = generator.new_label();
- generator.emit_jump_if(&done, type_is_normal_done_block, type_is_normal_not_done_block);
+ generator.emit_jump_if(done, type_is_normal_done_block, type_is_normal_not_done_block);
generator.bind_reachable_label(type_is_normal_done_block);
let return_value = generator.allocate_register();
- emit_get_by_known_name(generator, &return_value, &inner_result, utf16!("value").into());
+ emit_get_by_known_name(generator, return_value, inner_result, utf16!("value").into());
generator.emit(op::Jump { target: loop_end_block });
// vi. If _generatorKind_ is ~async~, set _received_ to Completion(AsyncGeneratorYield(? IteratorValue(_innerResult_))).
@@ -328,16 +320,16 @@ fn generate_yield_from(
{
let (yield_value, yield_behavior) = if is_async {
let current_value = generator.allocate_register();
- emit_get_by_known_name(generator, &current_value, &inner_result, utf16!("value").into());
+ emit_get_by_known_name(generator, current_value, inner_result, utf16!("value").into());
(current_value, YieldBehavior::Normal)
} else {
- (inner_result.clone(), YieldBehavior::IteratorResult)
+ (inner_result, YieldBehavior::IteratorResult)
};
generate_yield(
generator,
continuation_block,
- &yield_value,
+ yield_value,
received_completion,
received_completion_type,
received_completion_value,
@@ -356,11 +348,11 @@ fn generate_yield_from(
let arith_feedback = generator.next_arith_feedback();
generator.emit(op::StrictlyEquals {
arith_feedback,
- dst: is_throw.operand(),
- lhs: received_completion_type.operand(),
- rhs: throw_const.operand(),
+ dst: is_throw,
+ lhs: received_completion_type,
+ rhs: throw_const,
});
- generator.emit_jump_if(&is_throw, type_is_throw_block, type_is_return_block);
+ generator.emit_jump_if(is_throw, type_is_throw_block, type_is_return_block);
generator.bind_reachable_label(type_is_throw_block);
@@ -369,8 +361,8 @@ fn generate_yield_from(
let throw_key = generator.intern_property_key_text(utf16!("throw").into());
let cache = generator.next_property_lookup_cache();
generator.emit(op::GetMethod {
- dst: throw_method.operand(),
- object: iterator.operand(),
+ dst: throw_method,
+ object: iterator,
property: throw_key,
cache,
});
@@ -379,7 +371,7 @@ fn generate_yield_from(
let throw_method_defined_block = generator.new_label();
let throw_method_undefined_block = generator.new_label();
generator.emit(op::JumpUndefined {
- condition: throw_method.operand(),
+ condition: throw_method,
true_target: throw_method_undefined_block,
false_target: throw_method_defined_block,
});
@@ -390,40 +382,38 @@ fn generate_yield_from(
let call_feedback = generator.next_call_feedback();
generator.emit(op::Call {
call_feedback,
- dst: inner_result.operand(),
- callee: throw_method.operand(),
- this_value: iterator.operand(),
+ dst: inner_result,
+ callee: throw_method,
+ this_value: iterator,
argument_count: 1,
- arguments: &[received_completion_value.operand()],
+ arguments: &[received_completion_value],
});
// 2. If _generatorKind_ is ~async~, set _innerResult_ to ? Await(_innerResult_).
if is_async {
let awaited = generate_await_with_completions(
generator,
- &inner_result,
+ inner_result,
received_completion,
received_completion_type,
received_completion_value,
);
- generator.emit_mov(&inner_result, &awaited);
+ generator.emit_mov(inner_result, awaited);
}
// 4. If _innerResult_ is not an Object, throw a *TypeError* exception.
- generator.emit(op::ThrowIfNotObject {
- src: inner_result.operand(),
- });
+ generator.emit(op::ThrowIfNotObject { src: inner_result });
// 5. Let _done_ be ? IteratorComplete(_innerResult_).
- emit_get_by_known_name(generator, &done, &inner_result, utf16!("done").into());
+ emit_get_by_known_name(generator, done, inner_result, utf16!("done").into());
// 6. If _done_ is *true*, return ? IteratorValue(_innerResult_).
let type_is_throw_done_block = generator.new_label();
let type_is_throw_not_done_block = generator.new_label();
- generator.emit_jump_if(&done, type_is_throw_done_block, type_is_throw_not_done_block);
+ generator.emit_jump_if(done, type_is_throw_done_block, type_is_throw_not_done_block);
generator.bind_reachable_label(type_is_throw_done_block);
- emit_get_by_known_name(generator, &return_value, &inner_result, utf16!("value").into());
+ emit_get_by_known_name(generator, return_value, inner_result, utf16!("value").into());
generator.emit(op::Jump { target: loop_end_block });
// 7. If _generatorKind_ is ~async~, set _received_ to Completion(AsyncGeneratorYield(? IteratorValue(_innerResult_))).
@@ -432,15 +422,15 @@ fn generate_yield_from(
{
let (yield_value, yield_behavior) = if is_async {
let current_value = generator.allocate_register();
- emit_get_by_known_name(generator, &current_value, &inner_result, utf16!("value").into());
+ emit_get_by_known_name(generator, current_value, inner_result, utf16!("value").into());
(current_value, YieldBehavior::Normal)
} else {
- (inner_result.clone(), YieldBehavior::IteratorResult)
+ (inner_result, YieldBehavior::IteratorResult)
};
generate_yield(
generator,
continuation_block,
- &yield_value,
+ yield_value,
received_completion,
received_completion_type,
received_completion_value,
@@ -457,8 +447,8 @@ fn generate_yield_from(
let return_key = generator.intern_property_key_text(utf16!("return").into());
let cache = generator.next_property_lookup_cache();
generator.emit(op::GetMethod {
- dst: return_method.operand(),
- object: iterator.operand(),
+ dst: return_method,
+ object: iterator,
property: return_key,
cache,
});
@@ -466,7 +456,7 @@ fn generate_yield_from(
let call_return_block = generator.new_label();
let after_close = generator.new_label();
generator.emit(op::JumpUndefined {
- condition: return_method.operand(),
+ condition: return_method,
true_target: after_close,
false_target: call_return_block,
});
@@ -476,21 +466,21 @@ fn generate_yield_from(
let call_feedback = generator.next_call_feedback();
generator.emit(op::Call {
call_feedback,
- dst: close_result.operand(),
- callee: return_method.operand(),
- this_value: iterator.operand(),
+ dst: close_result,
+ callee: return_method,
+ this_value: iterator,
argument_count: 0,
arguments: &[],
});
let awaited = generate_await_with_completions(
generator,
- &close_result,
+ close_result,
received_completion,
received_completion_type,
received_completion_value,
);
- generator.emit(op::ThrowIfNotObject { src: awaited.operand() });
+ generator.emit(op::ThrowIfNotObject { src: awaited });
generator.emit(op::Jump { target: after_close });
generator.bind_reachable_label(after_close);
@@ -499,11 +489,11 @@ fn generate_yield_from(
let undef = generator.add_constant_undefined();
let cache = generator.next_property_lookup_cache();
generator.emit(op::IteratorClose {
- iterator_object: iterator.operand(),
- iterator_next: next_method.operand(),
- iterator_done: iterator_done_property.operand(),
+ iterator_object: iterator,
+ iterator_next: next_method,
+ iterator_done: iterator_done_property,
completion_type: CompletionType::Normal as u8,
- completion_value: undef.operand(),
+ completion_value: undef,
cache,
});
}
@@ -513,12 +503,10 @@ fn generate_yield_from(
let error_string =
generator.intern_string_text(utf16!("yield* protocol violation: iterator must have a throw method").into());
generator.emit(op::NewTypeError {
- dst: exception.operand(),
+ dst: exception,
error_string,
});
- generator.emit(op::Throw {
- src: exception.operand(),
- });
+ generator.emit(op::Throw { src: exception });
// =========================================================================
// c. Else (received.[[Type]] is return)
@@ -530,8 +518,8 @@ fn generate_yield_from(
let return_key = generator.intern_property_key_text(utf16!("return").into());
let cache = generator.next_property_lookup_cache();
generator.emit(op::GetMethod {
- dst: return_method.operand(),
- object: iterator.operand(),
+ dst: return_method,
+ object: iterator,
property: return_key,
cache,
});
@@ -540,7 +528,7 @@ fn generate_yield_from(
let return_is_undefined_block = generator.new_label();
let return_is_defined_block = generator.new_label();
generator.emit(op::JumpUndefined {
- condition: return_method.operand(),
+ condition: return_method,
true_target: return_is_undefined_block,
false_target: return_is_defined_block,
});
@@ -557,7 +545,7 @@ fn generate_yield_from(
);
}
// 2. Return _received_.
- generator.emit_exit(Exit::Return, received_completion_value.operand());
+ generator.emit_exit(Exit::Return, received_completion_value);
generator.bind_reachable_label(return_is_defined_block);
@@ -566,62 +554,62 @@ fn generate_yield_from(
let call_feedback = generator.next_call_feedback();
generator.emit(op::Call {
call_feedback,
- dst: inner_return_result.operand(),
- callee: return_method.operand(),
- this_value: iterator.operand(),
+ dst: inner_return_result,
+ callee: return_method,
+ this_value: iterator,
argument_count: 1,
- arguments: &[received_completion_value.operand()],
+ arguments: &[received_completion_value],
});
// v. If _generatorKind_ is ~async~, set _innerReturnResult_ to ? Await(_innerReturnResult_).
if is_async {
let awaited = generate_await_with_completions(
generator,
- &inner_return_result,
+ inner_return_result,
received_completion,
received_completion_type,
received_completion_value,
);
- generator.emit_mov(&inner_return_result, &awaited);
+ generator.emit_mov(inner_return_result, awaited);
}
// vi. If _innerReturnResult_ is not an Object, throw a *TypeError* exception.
generator.emit(op::ThrowIfNotObject {
- src: inner_return_result.operand(),
+ src: inner_return_result,
});
// vii. Let _done_ be ? IteratorComplete(_innerReturnResult_).
- emit_get_by_known_name(generator, &done, &inner_return_result, utf16!("done").into());
+ emit_get_by_known_name(generator, done, inner_return_result, utf16!("done").into());
// viii. If _done_ is *true*, then
let type_is_return_done_block = generator.new_label();
let type_is_return_not_done_block = generator.new_label();
- generator.emit_jump_if(&done, type_is_return_done_block, type_is_return_not_done_block);
+ generator.emit_jump_if(done, type_is_return_done_block, type_is_return_not_done_block);
generator.bind_reachable_label(type_is_return_done_block);
let inner_return_result_value = generator.allocate_register();
emit_get_by_known_name(
generator,
- &inner_return_result_value,
- &inner_return_result,
+ inner_return_result_value,
+ inner_return_result,
utf16!("value").into(),
);
- generator.emit_exit(Exit::Return, inner_return_result_value.operand());
+ generator.emit_exit(Exit::Return, inner_return_result_value);
// ix. If _generatorKind_ is ~async~, set _received_ to Completion(AsyncGeneratorYield(? IteratorValue(_innerReturnResult_))).
// x. Else, set _received_ to Completion(GeneratorYield(_innerReturnResult_)).
generator.bind_reachable_label(type_is_return_not_done_block);
let (received, yield_behavior) = if is_async {
let current_value = generator.allocate_register();
- emit_get_by_known_name(generator, &current_value, &inner_return_result, utf16!("value").into());
+ emit_get_by_known_name(generator, current_value, inner_return_result, utf16!("value").into());
(current_value, YieldBehavior::Normal)
} else {
- (inner_return_result.clone(), YieldBehavior::IteratorResult)
+ (inner_return_result, YieldBehavior::IteratorResult)
};
generate_yield(
generator,
continuation_block,
- &received,
+ received,
received_completion,
received_completion_type,
received_completion_value,
@@ -633,11 +621,11 @@ fn generate_yield_from(
// =========================================================================
generator.bind_reachable_label(continuation_block);
let acc = accumulator(generator);
- generator.emit_mov(received_completion, &acc);
+ generator.emit_mov(received_completion, acc);
generator.emit(op::GetCompletionFields {
- type_dst: received_completion_type.operand(),
- value_dst: received_completion_value.operand(),
- completion: received_completion.operand(),
+ type_dst: received_completion_type,
+ value_dst: received_completion_value,
+ completion: received_completion,
});
generator.emit(op::Jump { target: loop_block });
@@ -658,22 +646,22 @@ fn generate_yield_from(
fn generate_yield(
generator: &mut Generator<'_>,
continuation_label: Label,
- argument: &ScopedOperand,
- received_completion: &ScopedOperand,
- received_completion_type: &ScopedOperand,
- received_completion_value: &ScopedOperand,
+ argument: Operand,
+ received_completion: Operand,
+ received_completion_type: Operand,
+ received_completion_value: Operand,
yield_behavior: YieldBehavior,
) {
if !generator.is_in_async_generator_function() {
if yield_behavior == YieldBehavior::IteratorResult {
generator.emit(op::YieldIteratorResult {
continuation_label,
- value: argument.operand(),
+ value: argument,
});
} else {
generator.emit(op::Yield {
continuation_label: Some(continuation_label),
- value: argument.operand(),
+ value: argument,
});
}
return;
@@ -688,23 +676,23 @@ fn generate_yield(
received_completion_value,
)
} else {
- argument.clone()
+ argument
};
// Yield, then UnwrapYieldResumption.
let unwrap_block = generator.new_label();
generator.emit(op::Yield {
continuation_label: Some(unwrap_block),
- value: argument.operand(),
+ value: argument,
});
generator.bind_reachable_label(unwrap_block);
let acc = accumulator(generator);
- generator.emit_mov(received_completion, &acc);
+ generator.emit_mov(received_completion, acc);
generator.emit(op::GetCompletionFields {
- type_dst: received_completion_type.operand(),
- value_dst: received_completion_value.operand(),
- completion: received_completion.operand(),
+ type_dst: received_completion_type,
+ value_dst: received_completion_value,
+ completion: received_completion,
});
// If resumptionValue.[[Type]] is not return, jump to continuation.
@@ -714,11 +702,11 @@ fn generate_yield(
let arith_feedback = generator.next_arith_feedback();
generator.emit(op::StrictlyInequals {
arith_feedback,
- dst: is_not_return.operand(),
- lhs: received_completion_type.operand(),
- rhs: return_type.operand(),
+ dst: is_not_return,
+ lhs: received_completion_type,
+ rhs: return_type,
});
- generator.emit_jump_if(&is_not_return, continuation_label, return_block);
+ generator.emit_jump_if(is_not_return, continuation_label, return_block);
// Return path: Await(resumptionValue.[[Value]]).
generator.bind_reachable_label(return_block);
@@ -738,16 +726,16 @@ fn generate_yield(
let arith_feedback = generator.next_arith_feedback();
generator.emit(op::StrictlyEquals {
arith_feedback,
- dst: is_throw.operand(),
- lhs: received_completion_type.operand(),
- rhs: throw_type.operand(),
+ dst: is_throw,
+ lhs: received_completion_type,
+ rhs: throw_type,
});
- generator.emit_jump_if(&is_throw, continuation_label, awaited_normal_block);
+ generator.emit_jump_if(is_throw, continuation_label, awaited_normal_block);
// awaited.[[Type]] is normal: set type to Return and jump to continuation.
generator.bind_reachable_label(awaited_normal_block);
generator.emit(op::SetCompletionType {
- completion: received_completion.operand(),
+ completion: received_completion,
completion_type: CompletionType::Return as u8,
});
generator.emit(op::Jump {
@@ -767,16 +755,16 @@ pub(super) enum DisposalKind {
pub(super) fn emit_dispose_resources(
generator: &mut Generator<'_>,
kind: DisposalKind,
- stack: &ScopedOperand,
- completion_type: &ScopedOperand,
- completion_value: &ScopedOperand,
+ stack: Operand,
+ completion_type: Operand,
+ completion_value: Operand,
) {
match kind {
DisposalKind::Sync => {
generator.emit(op::DisposeResources {
- stack: stack.operand(),
- completion_type: completion_type.operand(),
- completion_value: completion_value.operand(),
+ stack,
+ completion_type,
+ completion_value,
});
}
DisposalKind::Async => {
@@ -789,8 +777,8 @@ pub(super) fn emit_dispose_resources(
let awaited_value = generator.allocate_register();
let normal_type = generator.add_constant_number(f64::from(CompletionType::Normal as u8));
let undefined = generator.add_constant_undefined();
- generator.emit_mov(&await_completion_type, &normal_type);
- generator.emit_mov(&await_completion_value, &undefined);
+ generator.emit_mov(await_completion_type, normal_type);
+ generator.emit_mov(await_completion_value, undefined);
let step_block = generator.new_label();
let await_block = generator.new_label();
@@ -800,29 +788,29 @@ pub(super) fn emit_dispose_resources(
generator.bind_reachable_label(step_block);
generator.emit(op::AsyncDisposeResourcesStep {
- done: done.operand(),
- awaited_value: awaited_value.operand(),
- stack: stack.operand(),
- completion_type: completion_type.operand(),
- completion_value: completion_value.operand(),
- await_completion_type: await_completion_type.operand(),
- await_completion_value: await_completion_value.operand(),
+ done,
+ awaited_value,
+ stack,
+ completion_type,
+ completion_value,
+ await_completion_type,
+ await_completion_value,
});
- generator.emit_jump_if(&done, done_block, await_block);
+ generator.emit_jump_if(done, done_block, await_block);
generator.bind_reachable_label(await_block);
generator.emit(op::Await {
continuation_label: continuation_block,
- argument: awaited_value.operand(),
+ argument: awaited_value,
});
generator.bind_reachable_label(continuation_block);
- let acc = generator.scoped_operand(Operand::register(Register::ACCUMULATOR));
- generator.emit_mov(&await_completion, &acc);
+ let acc = Operand::register(Register::ACCUMULATOR);
+ generator.emit_mov(await_completion, acc);
generator.emit(op::GetCompletionFields {
- type_dst: await_completion_type.operand(),
- value_dst: await_completion_value.operand(),
- completion: await_completion.operand(),
+ type_dst: await_completion_type,
+ value_dst: await_completion_value,
+ completion: await_completion,
});
generator.emit(op::Jump { target: step_block });
diff --git a/Libraries/LibJS/Rust/src/bytecode/codegen/members.rs b/Libraries/LibJS/Rust/src/bytecode/codegen/members.rs
index defd4a6c1a3..98b2d17b3d5 100644
--- a/Libraries/LibJS/Rust/src/bytecode/codegen/members.rs
+++ b/Libraries/LibJS/Rust/src/bytecode/codegen/members.rs
@@ -16,30 +16,24 @@ use crate::bytecode::instruction::typed as op;
use crate::bytecode::operand::*;
use super::context::Generator;
-use super::registers::ScopedOperand;
/// Emit a property access by key, using GetLength for the "length" property.
-pub(super) fn emit_get_by_key(
- generator: &mut Generator<'_>,
- dst: &ScopedOperand,
- base: &ScopedOperand,
- key: PropertyKeyTableIndex,
-) {
+pub(super) fn emit_get_by_key(generator: &mut Generator<'_>, dst: Operand, base: Operand, key: PropertyKeyTableIndex) {
if generator.context.names.is_length_property_key(key) {
generator.length_identifier = Some(key);
let cache = generator.next_property_lookup_cache();
let keyed_feedback = generator.next_keyed_feedback();
generator.emit(op::GetLength {
keyed_feedback,
- dst: dst.operand(),
- base: base.operand(),
+ dst,
+ base,
cache,
});
} else {
let cache = generator.next_property_lookup_cache();
generator.emit(op::GetById {
- dst: dst.operand(),
- base: base.operand(),
+ dst,
+ base,
property: key,
cache,
});
@@ -50,40 +44,35 @@ pub(super) fn emit_get_by_key(
/// for the "length" property.
pub(super) fn emit_get_by_id_with_this(
generator: &mut Generator<'_>,
- dst: &ScopedOperand,
- base: &ScopedOperand,
+ dst: Operand,
+ base: Operand,
property_name: Name,
- this_value: &ScopedOperand,
+ this_value: Operand,
) {
let key = generator.intern_property_key(property_name);
if generator.context.names.is_length_property_key(key) {
generator.length_identifier = Some(key);
let cache = generator.next_property_lookup_cache();
generator.emit(op::GetLengthWithThis {
- dst: dst.operand(),
- base: base.operand(),
- this_value: this_value.operand(),
+ dst,
+ base,
+ this_value,
cache,
});
} else {
let cache = generator.next_property_lookup_cache();
generator.emit(op::GetByIdWithThis {
- dst: dst.operand(),
- base: base.operand(),
+ dst,
+ base,
property: key,
- this_value: this_value.operand(),
+ this_value,
cache,
});
}
}
/// Emit a property read by value, optimizing constant string properties to GetById.
-pub(super) fn emit_get_by_value(
- generator: &mut Generator<'_>,
- dst: &ScopedOperand,
- base: &ScopedOperand,
- property: &ScopedOperand,
-) {
+pub(super) fn emit_get_by_value(generator: &mut Generator<'_>, dst: Operand, base: Operand, property: Operand) {
if let Some(key) = generator.try_constant_string_to_property_key(property) {
if generator.context.names.is_length_property_key(key) {
generator.length_identifier = Some(key);
@@ -91,15 +80,15 @@ pub(super) fn emit_get_by_value(
let keyed_feedback = generator.next_keyed_feedback();
generator.emit(op::GetLength {
keyed_feedback,
- dst: dst.operand(),
- base: base.operand(),
+ dst,
+ base,
cache,
});
} else {
let cache = generator.next_property_lookup_cache();
generator.emit(op::GetById {
- dst: dst.operand(),
- base: base.operand(),
+ dst,
+ base,
property: key,
cache,
});
@@ -110,9 +99,9 @@ pub(super) fn emit_get_by_value(
let cache = generator.next_property_lookup_cache();
generator.emit(op::GetByValue {
keyed_feedback,
- dst: dst.operand(),
- base: base.operand(),
- property: property.operand(),
+ dst,
+ base,
+ property,
cache,
});
}
@@ -120,28 +109,28 @@ pub(super) fn emit_get_by_value(
/// Emit a property read by value with explicit this, optimizing constant string properties.
pub(super) fn emit_get_by_value_with_this(
generator: &mut Generator<'_>,
- dst: &ScopedOperand,
- base: &ScopedOperand,
- property: &ScopedOperand,
- this_value: &ScopedOperand,
+ dst: Operand,
+ base: Operand,
+ property: Operand,
+ this_value: Operand,
) {
if let Some(key) = generator.try_constant_string_to_property_key(property) {
if generator.context.names.is_length_property_key(key) {
generator.length_identifier = Some(key);
let cache = generator.next_property_lookup_cache();
generator.emit(op::GetLengthWithThis {
- dst: dst.operand(),
- base: base.operand(),
- this_value: this_value.operand(),
+ dst,
+ base,
+ this_value,
cache,
});
} else {
let cache = generator.next_property_lookup_cache();
generator.emit(op::GetByIdWithThis {
- dst: dst.operand(),
- base: base.operand(),
+ dst,
+ base,
property: key,
- this_value: this_value.operand(),
+ this_value,
cache,
});
}
@@ -150,26 +139,21 @@ pub(super) fn emit_get_by_value_with_this(
let value_feedback = generator.next_value_feedback();
generator.emit(op::GetByValueWithThis {
value_feedback,
- dst: dst.operand(),
- base: base.operand(),
- property: property.operand(),
- this_value: this_value.operand(),
+ dst,
+ base,
+ property,
+ this_value,
});
}
/// Emit a normal property write by value, optimizing constant string properties to PutNormalById.
-pub(super) fn emit_put_normal_by_value(
- generator: &mut Generator<'_>,
- base: &ScopedOperand,
- property: &ScopedOperand,
- src: &ScopedOperand,
-) {
+pub(super) fn emit_put_normal_by_value(generator: &mut Generator<'_>, base: Operand, property: Operand, src: Operand) {
if let Some(key) = generator.try_constant_string_to_property_key(property) {
let cache = generator.next_property_lookup_cache();
generator.emit(op::PutById {
- base: base.operand(),
+ base,
property: key,
- src: src.operand(),
+ src,
cache,
kind: PutKind::Normal as u8,
});
@@ -179,9 +163,9 @@ pub(super) fn emit_put_normal_by_value(
let cache = generator.next_property_lookup_cache();
generator.emit(op::PutByValue {
keyed_feedback,
- base: base.operand(),
- property: property.operand(),
- src: src.operand(),
+ base,
+ property,
+ src,
kind: PutKind::Normal as u8,
cache,
});
@@ -190,28 +174,28 @@ pub(super) fn emit_put_normal_by_value(
/// Emit a normal property write by value with explicit this, optimizing constant string properties.
pub(super) fn emit_put_normal_by_value_with_this(
generator: &mut Generator<'_>,
- base: &ScopedOperand,
- property: &ScopedOperand,
- this_value: &ScopedOperand,
- src: &ScopedOperand,
+ base: Operand,
+ property: Operand,
+ this_value: Operand,
+ src: Operand,
) {
if let Some(key) = generator.try_constant_string_to_property_key(property) {
let cache = generator.next_property_lookup_cache();
generator.emit(op::PutByIdWithThis {
- base: base.operand(),
- this_value: this_value.operand(),
+ base,
+ this_value,
property: key,
- src: src.operand(),
+ src,
cache,
kind: PutKind::Normal as u8,
});
return;
}
generator.emit(op::PutByValueWithThis {
- base: base.operand(),
- property: property.operand(),
- this_value: this_value.operand(),
- src: src.operand(),
+ base,
+ property,
+ this_value,
+ src,
kind: PutKind::Normal as u8,
});
}
@@ -219,17 +203,17 @@ pub(super) fn emit_put_normal_by_value_with_this(
/// Emit a property write by value, optimizing constant string properties to the ById variant.
pub(super) fn emit_put_by_value(
generator: &mut Generator<'_>,
- base: &ScopedOperand,
- property: &ScopedOperand,
- src: &ScopedOperand,
+ base: Operand,
+ property: Operand,
+ src: Operand,
kind: PutKind,
) {
if let Some(key) = generator.try_constant_string_to_property_key(property) {
let cache = generator.next_property_lookup_cache();
generator.emit(op::PutById {
- base: base.operand(),
+ base,
property: key,
- src: src.operand(),
+ src,
cache,
kind: kind as u8,
});
@@ -239,9 +223,9 @@ pub(super) fn emit_put_by_value(
let cache = generator.next_property_lookup_cache();
generator.emit(op::PutByValue {
keyed_feedback,
- base: base.operand(),
- property: property.operand(),
- src: src.operand(),
+ base,
+ property,
+ src,
kind: kind as u8,
cache,
});
diff --git a/Libraries/LibJS/Rust/src/bytecode/codegen/mod.rs b/Libraries/LibJS/Rust/src/bytecode/codegen/mod.rs
index f88d460b9df..a3d6616f6a9 100644
--- a/Libraries/LibJS/Rust/src/bytecode/codegen/mod.rs
+++ b/Libraries/LibJS/Rust/src/bytecode/codegen/mod.rs
@@ -24,7 +24,6 @@ mod members;
mod names;
mod nodes;
mod operators;
-mod registers;
pub mod scope;
pub mod stream;
mod sweep;
diff --git a/Libraries/LibJS/Rust/src/bytecode/codegen/operators.rs b/Libraries/LibJS/Rust/src/bytecode/codegen/operators.rs
index 3349dafc093..5299959cbba 100644
--- a/Libraries/LibJS/Rust/src/bytecode/codegen/operators.rs
+++ b/Libraries/LibJS/Rust/src/bytecode/codegen/operators.rs
@@ -8,156 +8,147 @@
use crate::ast::BinaryOp;
use crate::bytecode::executable_data::ConstantValue;
+use crate::bytecode::operand::Operand;
use crate::bytecode::instruction::typed as op;
use super::context::Generator;
-use super::registers::ScopedOperand;
-pub(super) fn emit_binary_op(
- generator: &mut Generator<'_>,
- op: BinaryOp,
- dst: &ScopedOperand,
- lhs: &ScopedOperand,
- rhs: &ScopedOperand,
-) {
- let dst_op = dst.operand();
- let lhs_op = lhs.operand();
- let rhs_op = rhs.operand();
+pub(super) fn emit_binary_op(generator: &mut Generator<'_>, op: BinaryOp, dst: Operand, lhs: Operand, rhs: Operand) {
match op {
BinaryOp::Addition => {
let arith_feedback = generator.next_arith_feedback();
generator.emit(op::Add {
arith_feedback,
- dst: dst_op,
- lhs: lhs_op,
- rhs: rhs_op,
+ dst,
+ lhs,
+ rhs,
});
}
BinaryOp::Subtraction => {
let arith_feedback = generator.next_arith_feedback();
generator.emit(op::Sub {
arith_feedback,
- dst: dst_op,
- lhs: lhs_op,
- rhs: rhs_op,
+ dst,
+ lhs,
+ rhs,
});
}
BinaryOp::Multiplication => {
let arith_feedback = generator.next_arith_feedback();
generator.emit(op::Mul {
arith_feedback,
- dst: dst_op,
- lhs: lhs_op,
- rhs: rhs_op,
+ dst,
+ lhs,
+ rhs,
});
}
BinaryOp::Division => {
let arith_feedback = generator.next_arith_feedback();
generator.emit(op::Div {
arith_feedback,
- dst: dst_op,
- lhs: lhs_op,
- rhs: rhs_op,
+ dst,
+ lhs,
+ rhs,
});
}
BinaryOp::Modulo => {
let arith_feedback = generator.next_arith_feedback();
generator.emit(op::Mod {
arith_feedback,
- dst: dst_op,
- lhs: lhs_op,
- rhs: rhs_op,
+ dst,
+ lhs,
+ rhs,
});
}
BinaryOp::Exponentiation => {
let arith_feedback = generator.next_arith_feedback();
generator.emit(op::Exp {
arith_feedback,
- dst: dst_op,
- lhs: lhs_op,
- rhs: rhs_op,
+ dst,
+ lhs,
+ rhs,
});
}
BinaryOp::StrictlyEquals => {
let arith_feedback = generator.next_arith_feedback();
generator.emit(op::StrictlyEquals {
arith_feedback,
- dst: dst_op,
- lhs: lhs_op,
- rhs: rhs_op,
+ dst,
+ lhs,
+ rhs,
});
}
BinaryOp::StrictlyInequals => {
let arith_feedback = generator.next_arith_feedback();
generator.emit(op::StrictlyInequals {
arith_feedback,
- dst: dst_op,
- lhs: lhs_op,
- rhs: rhs_op,
+ dst,
+ lhs,
+ rhs,
});
}
BinaryOp::LooselyEquals => {
let arith_feedback = generator.next_arith_feedback();
generator.emit(op::LooselyEquals {
arith_feedback,
- dst: dst_op,
- lhs: lhs_op,
- rhs: rhs_op,
+ dst,
+ lhs,
+ rhs,
});
}
BinaryOp::LooselyInequals => {
let arith_feedback = generator.next_arith_feedback();
generator.emit(op::LooselyInequals {
arith_feedback,
- dst: dst_op,
- lhs: lhs_op,
- rhs: rhs_op,
+ dst,
+ lhs,
+ rhs,
});
}
BinaryOp::GreaterThan => {
let arith_feedback = generator.next_arith_feedback();
generator.emit(op::GreaterThan {
arith_feedback,
- dst: dst_op,
- lhs: lhs_op,
- rhs: rhs_op,
+ dst,
+ lhs,
+ rhs,
});
}
BinaryOp::GreaterThanEquals => {
let arith_feedback = generator.next_arith_feedback();
generator.emit(op::GreaterThanEquals {
arith_feedback,
- dst: dst_op,
- lhs: lhs_op,
- rhs: rhs_op,
+ dst,
+ lhs,
+ rhs,
});
}
BinaryOp::LessThan => {
let arith_feedback = generator.next_arith_feedback();
generator.emit(op::LessThan {
arith_feedback,
- dst: dst_op,
- lhs: lhs_op,
- rhs: rhs_op,
+ dst,
+ lhs,
+ rhs,
});
}
BinaryOp::LessThanEquals => {
let arith_feedback = generator.next_arith_feedback();
generator.emit(op::LessThanEquals {
arith_feedback,
- dst: dst_op,
- lhs: lhs_op,
- rhs: rhs_op,
+ dst,
+ lhs,
+ rhs,
});
}
BinaryOp::BitwiseAnd => {
let arith_feedback = generator.next_arith_feedback();
generator.emit(op::BitwiseAnd {
arith_feedback,
- dst: dst_op,
- lhs: lhs_op,
- rhs: rhs_op,
+ dst,
+ lhs,
+ rhs,
});
}
BinaryOp::BitwiseOr => {
@@ -167,25 +158,25 @@ pub(super) fn emit_binary_op(
let arith_feedback = generator.next_arith_feedback();
generator.emit(op::ToInt32 {
arith_feedback,
- dst: dst_op,
- value: lhs_op,
+ dst,
+ value: lhs,
});
} else {
let arith_feedback = generator.next_arith_feedback();
generator.emit(op::BitwiseOr {
arith_feedback,
- dst: dst_op,
- lhs: lhs_op,
- rhs: rhs_op,
+ dst,
+ lhs,
+ rhs,
});
}
} else {
let arith_feedback = generator.next_arith_feedback();
generator.emit(op::BitwiseOr {
arith_feedback,
- dst: dst_op,
- lhs: lhs_op,
- rhs: rhs_op,
+ dst,
+ lhs,
+ rhs,
});
}
}
@@ -193,18 +184,18 @@ pub(super) fn emit_binary_op(
let arith_feedback = generator.next_arith_feedback();
generator.emit(op::BitwiseXor {
arith_feedback,
- dst: dst_op,
- lhs: lhs_op,
- rhs: rhs_op,
+ dst,
+ lhs,
+ rhs,
});
}
BinaryOp::LeftShift => {
let arith_feedback = generator.next_arith_feedback();
generator.emit(op::LeftShift {
arith_feedback,
- dst: dst_op,
- lhs: lhs_op,
- rhs: rhs_op,
+ dst,
+ lhs,
+ rhs,
});
}
BinaryOp::RightShift => {
@@ -214,25 +205,25 @@ pub(super) fn emit_binary_op(
let arith_feedback = generator.next_arith_feedback();
generator.emit(op::ToInt32 {
arith_feedback,
- dst: dst_op,
- value: lhs_op,
+ dst,
+ value: lhs,
});
} else {
let arith_feedback = generator.next_arith_feedback();
generator.emit(op::RightShift {
arith_feedback,
- dst: dst_op,
- lhs: lhs_op,
- rhs: rhs_op,
+ dst,
+ lhs,
+ rhs,
});
}
} else {
let arith_feedback = generator.next_arith_feedback();
generator.emit(op::RightShift {
arith_feedback,
- dst: dst_op,
- lhs: lhs_op,
- rhs: rhs_op,
+ dst,
+ lhs,
+ rhs,
});
}
}
@@ -240,38 +231,27 @@ pub(super) fn emit_binary_op(
let arith_feedback = generator.next_arith_feedback();
generator.emit(op::UnsignedRightShift {
arith_feedback,
- dst: dst_op,
- lhs: lhs_op,
- rhs: rhs_op,
+ dst,
+ lhs,
+ rhs,
});
}
- BinaryOp::In => generator.emit(op::In {
- dst: dst_op,
- lhs: lhs_op,
- rhs: rhs_op,
- }),
- BinaryOp::InstanceOf => generator.emit(op::InstanceOf {
- dst: dst_op,
- lhs: lhs_op,
- rhs: rhs_op,
- }),
+ BinaryOp::In => generator.emit(op::In { dst, lhs, rhs }),
+ BinaryOp::InstanceOf => generator.emit(op::InstanceOf { dst, lhs, rhs }),
}
}
/// Convert a property name to the primitive that ToPropertyKey turns into a property key without observable effects,
/// in a register of its own unless it is a constant, which is a primitive already.
-pub(super) fn emit_to_primitive_property_key(
- generator: &mut Generator<'_>,
- property_name: &ScopedOperand,
-) -> ScopedOperand {
- if property_name.operand().is_constant() {
- return property_name.clone();
+pub(super) fn emit_to_primitive_property_key(generator: &mut Generator<'_>, property_name: Operand) -> Operand {
+ if property_name.is_constant() {
+ return property_name;
}
// NB: The name can be the operand of a variable or of `this`, which converting it in place would change.
let property_key = generator.allocate_register();
generator.emit(op::ToPrimitiveWithStringHint {
- dst: property_key.operand(),
- value: property_name.operand(),
+ dst: property_key,
+ value: property_name,
});
property_key
}
diff --git a/Libraries/LibJS/Rust/src/bytecode/codegen/registers.rs b/Libraries/LibJS/Rust/src/bytecode/codegen/registers.rs
deleted file mode 100644
index 265bd3e8666..00000000000
--- a/Libraries/LibJS/Rust/src/bytecode/codegen/registers.rs
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (c) 2026-present, the Ladybird developers.
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-//! What the emission helpers take as operands.
-
-use crate::bytecode::operand::Operand;
-
-/// An operand, whose register belongs to whoever is making use of it.
-#[derive(Clone, Debug, PartialEq)]
-pub struct ScopedOperand {
- operand: Operand,
-}
-
-impl ScopedOperand {
- #[inline(always)]
- pub(super) fn plain(operand: Operand) -> Self {
- Self { operand }
- }
-
- #[inline(always)]
- pub(super) fn operand(&self) -> Operand {
- self.operand
- }
-}
diff --git a/Libraries/LibJS/Rust/src/bytecode/codegen/scope.rs b/Libraries/LibJS/Rust/src/bytecode/codegen/scope.rs
index 34195e32b7a..ba08fe84e27 100644
--- a/Libraries/LibJS/Rust/src/bytecode/codegen/scope.rs
+++ b/Libraries/LibJS/Rust/src/bytecode/codegen/scope.rs
@@ -48,7 +48,6 @@ use super::bindings::*;
use super::context::Generator;
use super::environment::BindingLocation;
use super::nodes::Identifier;
-use super::registers::ScopedOperand;
use super::stream::Control;
use super::stream::HeldRegisters;
use super::stream::ScopeEnvironment;
@@ -684,7 +683,7 @@ impl Generator<'_> {
register: Option<Operand>,
) -> ScopeEnvironment {
self.note_creates_environment();
- let parent = self.current_lexical_environment().operand();
+ let parent = self.current_lexical_environment();
let held = self.hold_registers();
let register = register.unwrap_or_else(|| self.held_register());
let shape_cache = self.next_environment_shape_cache();
@@ -695,7 +694,7 @@ impl Generator<'_> {
shape_cache,
is_catch_environment: is_catch,
});
- self.push_static_lexical_environment(ScopedOperand::plain(register));
+ self.push_static_lexical_environment(register);
self.context.scope.scope_environment_depth += 1;
self.for_each_scope_binding(bindings, |generator, binding| {
if !binding.is_captured {
@@ -718,8 +717,8 @@ impl Generator<'_> {
self.pop_tracked_lexical_environment();
self.context.scope.scope_environment_depth -= 1;
if !self.is_stream_dead() {
- let parent = self.scoped_operand(environment.parent);
- self.restore_lexical_environment(&parent);
+ let parent = environment.parent;
+ self.restore_lexical_environment(parent);
}
self.release_held_registers(environment.held);
}
@@ -727,10 +726,10 @@ impl Generator<'_> {
/// The body of a `with` starts, whose environment is `object`.
pub(super) fn enter_object_environment(&mut self, object: Operand, held: HeldRegisters) -> ScopeEnvironment {
self.note_creates_environment();
- let parent = self.current_lexical_environment().operand();
+ let parent = self.current_lexical_environment();
let register = self.held_register();
self.emit(op::EnterObjectEnvironment { dst: register, object });
- self.push_dynamic_lexical_environment(ScopedOperand::plain(register));
+ self.push_dynamic_lexical_environment(register);
let scope = &mut self.context.scope;
scope.scope_environment_depth += 1;
scope.with_depth += 1;
@@ -755,8 +754,8 @@ impl Generator<'_> {
});
self.pop_tracked_lexical_environment();
self.context.scope.scope_environment_depth -= 1;
- let parent = self.scoped_operand(environment.parent);
- self.restore_lexical_environment(&parent);
+ let parent = environment.parent;
+ self.restore_lexical_environment(parent);
self.enter_scope_environment(bindings, false, Some(environment.register));
for (identifier, value) in names {
emit_initialize_lexical_binding(self, identifier, value);
@@ -1233,14 +1232,12 @@ impl Generator<'_> {
&& (scope.has_function_in_parameters || parameters_have_environment));
if needs_variable_environment {
self.note_creates_environment();
- let environment = ScopedOperand::plain(self.held_register());
+ let environment = self.held_register();
self.in_head(|generator| {
generator.emit(op::CreateVariableEnvironment {
capacity: captured_count,
});
- generator.emit(op::GetLexicalEnvironment {
- dst: environment.operand(),
- });
+ generator.emit(op::GetLexicalEnvironment { dst: environment });
});
self.push_static_variable_environment(environment);
let scope = &mut self.context.scope;
@@ -1627,12 +1624,12 @@ impl Generator<'_> {
let shape_cache = self.next_environment_shape_cache();
self.emit(op::CreateLexicalEnvironment {
dst: register,
- parent: parent.operand(),
+ parent,
capacity: 1,
shape_cache,
is_catch_environment: false,
});
- self.push_static_lexical_environment(ScopedOperand::plain(register));
+ self.push_static_lexical_environment(register);
self.context.scope.scope_environment_depth += 1;
let identifier = self.intern_identifier(name);
self.emit(op::CreateVariable {
@@ -1645,11 +1642,7 @@ impl Generator<'_> {
let shared_function_data_index = self.register_nested_function(row, NestedFunctionName::None);
self.put_new_function(dst, shared_function_data_index);
emit_initialize_lexical_binding(self, identifier, dst);
- self.leave_scope_environment(ScopeEnvironment {
- register,
- parent: parent.operand(),
- held,
- });
+ self.leave_scope_environment(ScopeEnvironment { register, parent, held });
self.push_value(dst, first_temporary);
}
@@ -1790,7 +1783,7 @@ impl Generator<'_> {
/// The scope of a class starts, whose name is a binding of its own that everything in the class sees.
pub(super) fn begin_class_scope(&mut self, name: Option<Name>) -> ScopeEnvironment {
self.note_creates_environment();
- let parent = self.current_lexical_environment().operand();
+ let parent = self.current_lexical_environment();
let held = self.hold_registers();
let register = self.held_register();
let shape_cache = self.next_environment_shape_cache();
@@ -1801,7 +1794,7 @@ impl Generator<'_> {
shape_cache,
is_catch_environment: false,
});
- self.push_static_lexical_environment(ScopedOperand::plain(register));
+ self.push_static_lexical_environment(register);
let scope = &mut self.context.scope;
scope.scope_environment_depth += 1;
scope.block_begin();
@@ -1845,8 +1838,8 @@ impl Generator<'_> {
let scope = &mut self.context.scope;
scope.scope_environment_depth -= 1;
scope.block_end();
- let parent = self.scoped_operand(environment.parent);
- self.restore_lexical_environment(&parent);
+ let parent = environment.parent;
+ self.restore_lexical_environment(parent);
}
/// Finishes the function: what the functions nested in it need, what the function object needs, and the code.
diff --git a/Libraries/LibJS/Rust/src/bytecode/codegen/stream.rs b/Libraries/LibJS/Rust/src/bytecode/codegen/stream.rs
index b92ccb9eb33..4c2e8c1f04f 100644
--- a/Libraries/LibJS/Rust/src/bytecode/codegen/stream.rs
+++ b/Libraries/LibJS/Rust/src/bytecode/codegen/stream.rs
@@ -61,7 +61,6 @@ use super::members::*;
use super::names::NameClass;
use super::nodes::Identifier;
use super::operators::emit_binary_op;
-use super::registers::ScopedOperand;
const UNBOUND: u32 = u32::MAX;
@@ -1124,8 +1123,8 @@ impl Generator<'_> {
Control::Block {
environment: Some(environment),
} => {
- let parent = self.scoped_operand(environment.parent);
- self.restore_lexical_environment(&parent);
+ let parent = environment.parent;
+ self.restore_lexical_environment(parent);
}
Control::Iterator(iterator) => {
self.set_handler(iterator.outer_handler);
@@ -1186,7 +1185,7 @@ impl Generator<'_> {
self.add_constant_i32(Finally::FIRST_EXIT + i32::try_from(position).expect("a function has few exits"));
self.put(op::Mov {
dst: completion_type,
- src: kind.operand(),
+ src: kind,
});
self.jump(body);
}
@@ -1217,7 +1216,7 @@ impl Generator<'_> {
let normal = self.add_constant_i32(Finally::NORMAL);
self.put(op::Mov {
dst: completion_type,
- src: normal.operand(),
+ src: normal,
});
self.jump(body);
}
@@ -1227,7 +1226,7 @@ impl Generator<'_> {
&mut self,
finally: usize,
handler: Handler,
- entry_environment: &ScopedOperand,
+ entry_environment: Operand,
) -> Label {
let finally = &self.context.stream.finallies[finally];
let (completion_type, completion_value, body) =
@@ -1242,7 +1241,7 @@ impl Generator<'_> {
let throw = self.add_constant_i32(Finally::THROW);
self.put(op::Mov {
dst: completion_type,
- src: throw.operand(),
+ src: throw,
});
body
}
@@ -1264,7 +1263,7 @@ impl Generator<'_> {
generator.put(op::JumpStrictlyEquals {
arith_feedback,
lhs: completion_type,
- rhs: kind.operand(),
+ rhs: kind,
true_target: target,
false_target: next,
});
@@ -1301,7 +1300,7 @@ impl Generator<'_> {
label: self.new_label(),
catches: false,
};
- let entry_environment = self.current_lexical_environment().operand();
+ let entry_environment = self.current_lexical_environment();
let stream = &mut self.context.stream;
let index = u32_from_usize(stream.disposals.len());
stream.disposals.push(Disposal {
@@ -1345,8 +1344,8 @@ impl Generator<'_> {
let finally = disposal.finally;
self.leave_finally_part(finally);
self.set_handler(disposal.outer_handler);
- let entry_environment = self.scoped_operand(disposal.entry_environment);
- let body = self.bind_finally_handler(finally as usize, disposal.handler, &entry_environment);
+ let entry_environment = disposal.entry_environment;
+ let body = self.bind_finally_handler(finally as usize, disposal.handler, entry_environment);
self.bind_label(body);
let (completion_type, completion_value) = {
let finally = &self.context.stream.finallies[finally as usize];
@@ -1359,9 +1358,9 @@ impl Generator<'_> {
} else {
DisposalKind::Sync
},
- &ScopedOperand::plain(disposal.stack),
- &ScopedOperand::plain(completion_type),
- &ScopedOperand::plain(completion_value),
+ disposal.stack,
+ completion_type,
+ completion_value,
);
let end_label = self.new_label();
self.finally_dispatch(finally as usize, end_label);
@@ -1371,7 +1370,7 @@ impl Generator<'_> {
/// Calls the `return` method of an async iterator and awaits what that gives, if it has one, and returns what it gave.
pub(super) fn put_async_iterator_return(&mut self, iterator: OpenIterator, after_return: Label) -> Operand {
- let method = self.allocate_register().operand();
+ let method = self.allocate_register();
let key = self.intern_property_key_text(crate::utf16::Utf16View::Ascii(b"return"));
let cache = self.next_property_lookup_cache();
self.put(op::GetMethod {
@@ -1389,7 +1388,7 @@ impl Generator<'_> {
false_target: call,
});
self.bind_label(call);
- let result = self.allocate_register().operand();
+ let result = self.allocate_register();
let call_feedback = self.next_call_feedback();
self.put(op::Call {
call_feedback,
@@ -1399,7 +1398,7 @@ impl Generator<'_> {
argument_count: 0,
arguments: &[],
});
- generate_await_of_value(self, &ScopedOperand::plain(result)).operand()
+ generate_await_of_value(self, result)
}
fn put_iterator_close(&mut self, iterator: OpenIterator) {
@@ -1860,7 +1859,7 @@ impl Generator<'_> {
}
_ => {
if let Some(constant) = self.builtin_constant(ident.name) {
- self.push_value(constant.operand(), first_temporary);
+ self.push_value(constant, first_temporary);
return;
}
}
@@ -1966,12 +1965,7 @@ impl Generator<'_> {
}
pub(super) fn put_get_by_value(&mut self, dst: Operand, base: Operand, key: Operand) {
- emit_get_by_value(
- self,
- &ScopedOperand::plain(dst),
- &ScopedOperand::plain(base),
- &ScopedOperand::plain(key),
- );
+ emit_get_by_value(self, dst, base, key);
}
// --- Properties of `super` and private names ---
@@ -1991,14 +1985,11 @@ impl Generator<'_> {
}
fn put_get_of_super(&mut self, dst: Operand, base: Operand, key: Result<Name, Operand>) {
- let this_value = ScopedOperand::plain(Operand::register(Register::THIS_VALUE));
- let dst = ScopedOperand::plain(dst);
- let base = ScopedOperand::plain(base);
+ let this_value = Operand::register(Register::THIS_VALUE);
match key {
- Ok(name) => emit_get_by_id_with_this(self, &dst, &base, name, &this_value),
+ Ok(name) => emit_get_by_id_with_this(self, dst, base, name, this_value),
Err(key) => {
- let key = ScopedOperand::plain(key);
- emit_get_by_value_with_this(self, &dst, &base, &key, &this_value);
+ emit_get_by_value_with_this(self, dst, base, key, this_value);
}
}
}
@@ -2580,11 +2571,10 @@ impl Generator<'_> {
let (rhs, _) = self.pop_operand();
let (lhs, first_temporary) = self.pop_operand();
if lhs.is_constant() && rhs.is_constant() {
- let folded =
- try_constant_fold_binary(self, operator, &ScopedOperand::plain(lhs), &ScopedOperand::plain(rhs));
+ let folded = try_constant_fold_binary(self, operator, &lhs, &rhs);
if let Some(folded) = folded {
self.release_temporaries_from(first_temporary);
- self.push_value(folded.operand(), first_temporary);
+ self.push_value(folded, first_temporary);
return;
}
}
@@ -2607,13 +2597,7 @@ impl Generator<'_> {
let start = u32_from_usize(stream.current.bytes.len());
let operand_position_count = u32_from_usize(stream.current.operand_positions.len());
let arith_feedback_before = self.next_arith_feedback;
- emit_binary_op(
- self,
- operator,
- &ScopedOperand::plain(dst),
- &ScopedOperand::plain(lhs),
- &ScopedOperand::plain(rhs),
- );
+ emit_binary_op(self, operator, dst, lhs, rhs);
let stream = &mut self.context.stream;
let end = u32_from_usize(stream.current.bytes.len());
if !stream.current.dead {
@@ -2663,10 +2647,10 @@ impl Generator<'_> {
pub(super) fn unary(&mut self, operator: UnaryOp) {
let (value, first_temporary) = self.pop_operand();
if value.is_constant()
- && let Some(folded) = try_constant_fold_unary(self, operator, &ScopedOperand::plain(value))
+ && let Some(folded) = try_constant_fold_unary(self, operator, &value)
{
self.release_temporaries_from(first_temporary);
- self.push_value(folded.operand(), first_temporary);
+ self.push_value(folded, first_temporary);
return;
}
if operator == UnaryOp::Void {
@@ -2741,7 +2725,7 @@ impl Generator<'_> {
}
pub(super) fn value_of_bigint(&mut self, digits: String) {
- let operand = self.add_constant_bigint(digits).operand();
+ let operand = self.add_constant_bigint(digits);
self.value_of_constant(operand);
}
@@ -2843,8 +2827,8 @@ impl Generator<'_> {
pub(super) fn await_value(&mut self) {
let (value, first_temporary) = self.pop_operand();
let held = self.hold_registers();
- let result = generate_await_of_value(self, &ScopedOperand::plain(value));
- self.take_result_of_held_registers(result.operand(), held, first_temporary);
+ let result = generate_await_of_value(self, value);
+ self.take_result_of_held_registers(result, held, first_temporary);
}
/// Yields the value on top of the stack if there is one, or what it iterates over if `is_yield_from`.
@@ -2860,13 +2844,13 @@ impl Generator<'_> {
let received_completion_value = self.allocate_register();
let result = generate_yield_of_value(
self,
- ScopedOperand::plain(value),
+ value,
is_yield_from,
- &received_completion,
- &received_completion_type,
- &received_completion_value,
+ received_completion,
+ received_completion_type,
+ received_completion_value,
);
- self.take_result_of_held_registers(result.operand(), held, first_temporary);
+ self.take_result_of_held_registers(result, held, first_temporary);
}
/// Makes `result` the value of an expression whose code took the registers since `held`.
@@ -3081,17 +3065,17 @@ impl Generator<'_> {
if target.a != Operand::invalid() {
let resolved_binding = if target.is_global {
ResolvedBinding::Global {
- is_resolvable: ScopedOperand::plain(target.a),
+ is_resolvable: target.a,
identifier,
cache: target.cache,
}
} else {
ResolvedBinding::Environment {
- environment: ScopedOperand::plain(target.a),
+ environment: target.a,
identifier,
}
};
- emit_set_resolved_binding(self, &resolved_binding, &ScopedOperand::plain(value));
+ emit_set_resolved_binding(self, &resolved_binding, value);
} else if target.is_global {
let cache = self.next_global_variable_cache();
self.put(op::SetGlobal {
@@ -3117,28 +3101,22 @@ impl Generator<'_> {
});
}
ValKind::IndexTarget => {
- emit_put_normal_by_value(
- self,
- &ScopedOperand::plain(target.a),
- &ScopedOperand::plain(target.b),
- &ScopedOperand::plain(value),
- );
+ emit_put_normal_by_value(self, target.a, target.b, value);
}
ValKind::SuperTarget => {
- let this_value = ScopedOperand::plain(Operand::register(Register::THIS_VALUE));
- let base = ScopedOperand::plain(target.a);
- let value = ScopedOperand::plain(value);
+ let this_value = Operand::register(Register::THIS_VALUE);
+ let base = target.a;
if target.b != Operand::invalid() {
- let key = ScopedOperand::plain(target.b);
- emit_put_normal_by_value_with_this(self, &base, &key, &this_value, &value);
+ let key = target.b;
+ emit_put_normal_by_value_with_this(self, base, key, this_value, value);
} else {
let key = self.intern_property_key(Name(target.name));
let cache = self.next_property_lookup_cache();
self.put(op::PutByIdWithThis {
- base: base.operand(),
- this_value: this_value.operand(),
+ base,
+ this_value,
property: key,
- src: value.operand(),
+ src: value,
cache,
kind: libjs_abi::PutKind::Normal as u8,
});
@@ -3259,15 +3237,14 @@ impl Generator<'_> {
}
ValKind::SuperTarget => {
let dst = self.temporary();
- let this_value = ScopedOperand::plain(Operand::register(Register::THIS_VALUE));
- let base = ScopedOperand::plain(target.a);
+ let this_value = Operand::register(Register::THIS_VALUE);
+ let base = target.a;
if target.b != Operand::invalid() {
let key = self.read_modify_write_key(target.a, target.b);
self.context.stream.values.last_mut().expect("a target was evaluated").b = key;
- let key = ScopedOperand::plain(key);
- emit_get_by_value_with_this(self, &ScopedOperand::plain(dst), &base, &key, &this_value);
+ emit_get_by_value_with_this(self, dst, base, key, this_value);
} else {
- emit_get_by_id_with_this(self, &ScopedOperand::plain(dst), &base, Name(target.name), &this_value);
+ emit_get_by_id_with_this(self, dst, base, Name(target.name), this_value);
}
self.push_value(dst, first_temporary);
}
@@ -3358,13 +3335,7 @@ impl Generator<'_> {
} else {
self.temporary()
};
- emit_binary_op(
- self,
- operator,
- &ScopedOperand::plain(dst),
- &ScopedOperand::plain(lhs),
- &ScopedOperand::plain(rhs),
- );
+ emit_binary_op(self, operator, dst, lhs, rhs);
let target = self.pop_value();
if target.kind != ValKind::LocalTarget || target.is_const {
self.store_to_target(target, dst, false);
@@ -3598,13 +3569,7 @@ impl Generator<'_> {
let (value, _) = self.pop_operand();
let key = self.context.constants.add_number(key);
let object = self.context.stream.values.last().expect("an object is being built").a;
- emit_put_by_value(
- self,
- &ScopedOperand::plain(object),
- &ScopedOperand::plain(key),
- &ScopedOperand::plain(value),
- kind,
- );
+ emit_put_by_value(self, object, key, value, kind);
self.release_temporaries_from(object.index() + 1);
}
@@ -3626,13 +3591,7 @@ impl Generator<'_> {
name: key,
prefix: prefix as u8,
});
- emit_put_by_value(
- self,
- &ScopedOperand::plain(object),
- &ScopedOperand::plain(key),
- &ScopedOperand::plain(value),
- kind,
- );
+ emit_put_by_value(self, object, key, value, kind);
self.release_temporaries_from(object.index() + 1);
}
@@ -3655,13 +3614,7 @@ impl Generator<'_> {
});
}
let object = *self.context.stream.values.last().expect("an object is being built");
- emit_put_by_value(
- self,
- &ScopedOperand::plain(object.a),
- &ScopedOperand::plain(key),
- &ScopedOperand::plain(value),
- libjs_abi::PutKind::Own,
- );
+ emit_put_by_value(self, object.a, key, value, libjs_abi::PutKind::Own);
self.release_temporaries_from(object.a.index() + 1);
}