Skip to content

Commit

Permalink
Remove GetGeneratorAsync opcode
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Oct 30, 2023
1 parent 7b4273a commit 1d1e441
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 68 deletions.
4 changes: 1 addition & 3 deletions boa_engine/src/bytecompiler/declarations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,9 +750,7 @@ impl ByteCompiler<'_, '_> {
else {
// b. Let fo be InstantiateFunctionObject of f with arguments lexEnv and privateEnv.
let index = self.push_function_to_constants(code);
if r#async && generator {
self.emit_with_varying_operand(Opcode::GetGeneratorAsync, index);
} else if generator {
if generator {
self.emit_with_varying_operand(Opcode::GetGenerator, index);
} else {
self.emit(
Expand Down
18 changes: 4 additions & 14 deletions boa_engine/src/bytecompiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1253,17 +1253,11 @@ impl<'ctx, 'host> ByteCompiler<'ctx, 'host> {
use_expr: bool,
) {
let name = function.name;
let (generator, r#async, arrow) = (
function.kind.is_generator(),
function.kind.is_async(),
function.kind.is_arrow(),
);
let (generator, arrow) = (function.kind.is_generator(), function.kind.is_arrow());

let index = self.function(function);

if r#async && generator {
self.emit_with_varying_operand(Opcode::GetGeneratorAsync, index);
} else if generator {
if generator {
self.emit_with_varying_operand(Opcode::GetGenerator, index);
} else if arrow {
self.emit(Opcode::GetArrowFunction, &[Operand::Varying(index)]);
Expand Down Expand Up @@ -1331,9 +1325,7 @@ impl<'ctx, 'host> ByteCompiler<'ctx, 'host> {

let index = self.push_function_to_constants(code);

if r#async && generator {
self.emit_with_varying_operand(Opcode::GetGeneratorAsync, index);
} else if generator {
if generator {
self.emit_with_varying_operand(Opcode::GetGenerator, index);
} else if arrow {
self.emit(Opcode::GetArrowFunction, &[Operand::Varying(index)]);
Expand Down Expand Up @@ -1387,9 +1379,7 @@ impl<'ctx, 'host> ByteCompiler<'ctx, 'host> {

let index = self.push_function_to_constants(code);

if r#async && generator {
self.emit_with_varying_operand(Opcode::GetGeneratorAsync, index);
} else if generator {
if generator {
self.emit_with_varying_operand(Opcode::GetGenerator, index);
} else if arrow {
self.emit(Opcode::GetArrowFunction, &[Operand::Varying(index)]);
Expand Down
7 changes: 3 additions & 4 deletions boa_engine/src/vm/code_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,7 @@ impl CodeBlock {
self.constant_function(index).length
)
}
Instruction::GetArrowFunction { index }
| Instruction::GetGenerator { index }
| Instruction::GetGeneratorAsync { index } => {
Instruction::GetArrowFunction { index } | Instruction::GetGenerator { index } => {
let index = index.value() as usize;
format!(
"{index:04}: '{}' (length: {})",
Expand Down Expand Up @@ -716,7 +714,8 @@ impl CodeBlock {
| Instruction::Reserved55
| Instruction::Reserved56
| Instruction::Reserved57
| Instruction::Reserved58 => unreachable!("Reserved opcodes are unrechable"),
| Instruction::Reserved58
| Instruction::Reserved59 => unreachable!("Reserved opcodes are unrechable"),
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions boa_engine/src/vm/flowgraph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ impl CodeBlock {
graph.add_node(previous_pc, NodeShape::None, label.into(), Color::None);
graph.add_edge(previous_pc, pc, None, Color::None, EdgeStyle::Line);
}
Instruction::GetGenerator { .. } | Instruction::GetGeneratorAsync { .. } => {
Instruction::GetGenerator { .. } => {
graph.add_node(previous_pc, NodeShape::None, label.into(), Color::None);
graph.add_edge(previous_pc, pc, None, Color::None, EdgeStyle::Line);
}
Expand Down Expand Up @@ -521,7 +521,8 @@ impl CodeBlock {
| Instruction::Reserved55
| Instruction::Reserved56
| Instruction::Reserved57
| Instruction::Reserved58 => unreachable!("Reserved opcodes are unrechable"),
| Instruction::Reserved58
| Instruction::Reserved59 => unreachable!("Reserved opcodes are unrechable"),
}
}

Expand Down
38 changes: 0 additions & 38 deletions boa_engine/src/vm/opcode/get/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,41 +40,3 @@ impl Operation for GetGenerator {
Self::operation(context, index)
}
}

/// `GetGeneratorAsync` implements the Opcode Operation for `Opcode::GetGeneratorAsync`
///
/// Operation:
/// - Get async generator function from the pre-compiled inner functions.
#[derive(Debug, Clone, Copy)]
pub(crate) struct GetGeneratorAsync;

impl GetGeneratorAsync {
#[allow(clippy::unnecessary_wraps)]
fn operation(context: &mut Context<'_>, index: usize) -> JsResult<CompletionType> {
let code = context.vm.frame().code_block().constant_function(index);
let function = create_generator_function_object(code, None, context);
context.vm.push(function);
Ok(CompletionType::Normal)
}
}

impl Operation for GetGeneratorAsync {
const NAME: &'static str = "GetGeneratorAsync";
const INSTRUCTION: &'static str = "INST - GetGeneratorAsync";
const COST: u8 = 3;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u8>() as usize;
Self::operation(context, index)
}

fn execute_with_u16_operands(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u16>() as usize;
Self::operation(context, index)
}

fn execute_with_u32_operands(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u32>() as usize;
Self::operation(context, index)
}
}
9 changes: 2 additions & 7 deletions boa_engine/src/vm/opcode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1690,13 +1690,6 @@ generate_opcodes! {
/// Stack: **=>** func
GetGenerator { index: VaryingOperand },

/// Get async generator function from the pre-compiled inner functions.
///
/// Operands: index: `VaryingOperand`,
///
/// Stack: **=>** func
GetGeneratorAsync { index: VaryingOperand },

/// Call a function named "eval".
///
/// Operands: argument_count: `VaryingOperand`
Expand Down Expand Up @@ -2211,6 +2204,8 @@ generate_opcodes! {
Reserved57 => Reserved,
/// Reserved [`Opcode`].
Reserved58 => Reserved,
/// Reserved [`Opcode`].
Reserved59 => Reserved,
}

/// Specific opcodes for bindings.
Expand Down

0 comments on commit 1d1e441

Please sign in to comment.