Skip to content

Commit

Permalink
Remove GetAsyncArrowFunction and GetFunctionAsync opcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Oct 30, 2023
1 parent ae95afb commit 7b4273a
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 132 deletions.
5 changes: 0 additions & 5 deletions boa_engine/src/bytecompiler/declarations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -754,11 +754,6 @@ impl ByteCompiler<'_, '_> {
self.emit_with_varying_operand(Opcode::GetGeneratorAsync, index);
} else if generator {
self.emit_with_varying_operand(Opcode::GetGenerator, index);
} else if r#async {
self.emit(
Opcode::GetFunctionAsync,
&[Operand::Varying(index), Operand::Bool(false)],
);
} else {
self.emit(
Opcode::GetFunction,
Expand Down
21 changes: 0 additions & 21 deletions boa_engine/src/bytecompiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1265,13 +1265,6 @@ impl<'ctx, 'host> ByteCompiler<'ctx, 'host> {
self.emit_with_varying_operand(Opcode::GetGeneratorAsync, index);
} else if generator {
self.emit_with_varying_operand(Opcode::GetGenerator, index);
} else if r#async && arrow {
self.emit(Opcode::GetAsyncArrowFunction, &[Operand::Varying(index)]);
} else if r#async {
self.emit(
Opcode::GetFunctionAsync,
&[Operand::Varying(index), Operand::Bool(false)],
);
} else if arrow {
self.emit(Opcode::GetArrowFunction, &[Operand::Varying(index)]);
} else {
Expand Down Expand Up @@ -1342,13 +1335,6 @@ impl<'ctx, 'host> ByteCompiler<'ctx, 'host> {
self.emit_with_varying_operand(Opcode::GetGeneratorAsync, index);
} else if generator {
self.emit_with_varying_operand(Opcode::GetGenerator, index);
} else if r#async && arrow {
self.emit(Opcode::GetAsyncArrowFunction, &[Operand::Varying(index)]);
} else if r#async {
self.emit(
Opcode::GetFunctionAsync,
&[Operand::Varying(index), Operand::Bool(true)],
);
} else if arrow {
self.emit(Opcode::GetArrowFunction, &[Operand::Varying(index)]);
} else {
Expand Down Expand Up @@ -1405,13 +1391,6 @@ impl<'ctx, 'host> ByteCompiler<'ctx, 'host> {
self.emit_with_varying_operand(Opcode::GetGeneratorAsync, index);
} else if generator {
self.emit_with_varying_operand(Opcode::GetGenerator, index);
} else if r#async && arrow {
self.emit(Opcode::GetAsyncArrowFunction, &[Operand::Varying(index)]);
} else if r#async {
self.emit(
Opcode::GetFunctionAsync,
&[Operand::Varying(index), Operand::Bool(true)],
);
} else if arrow {
self.emit(Opcode::GetArrowFunction, &[Operand::Varying(index)]);
} else {
Expand Down
8 changes: 4 additions & 4 deletions boa_engine/src/vm/code_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,7 @@ impl CodeBlock {
Instruction::TemplateCreate { count, site } => {
format!("{}, {site}", count.value())
}
Instruction::GetFunction { index, method }
| Instruction::GetFunctionAsync { index, method } => {
Instruction::GetFunction { index, method } => {
let index = index.value() as usize;
format!(
"{index:04}: '{}' (length: {}), method: {method}",
Expand All @@ -465,7 +464,6 @@ impl CodeBlock {
)
}
Instruction::GetArrowFunction { index }
| Instruction::GetAsyncArrowFunction { index }
| Instruction::GetGenerator { index }
| Instruction::GetGeneratorAsync { index } => {
let index = index.value() as usize;
Expand Down Expand Up @@ -716,7 +714,9 @@ impl CodeBlock {
| Instruction::Reserved53
| Instruction::Reserved54
| Instruction::Reserved55
| Instruction::Reserved56 => unreachable!("Reserved opcodes are unrechable"),
| Instruction::Reserved56
| Instruction::Reserved57
| Instruction::Reserved58 => unreachable!("Reserved opcodes are unrechable"),
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions boa_engine/src/vm/flowgraph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,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::GetArrowFunction { .. }
| Instruction::GetAsyncArrowFunction { .. }
| Instruction::GetFunction { .. }
| Instruction::GetFunctionAsync { .. } => {
Instruction::GetArrowFunction { .. } | Instruction::GetFunction { .. } => {
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 @@ -522,7 +519,9 @@ impl CodeBlock {
| Instruction::Reserved53
| Instruction::Reserved54
| Instruction::Reserved55
| Instruction::Reserved56 => unreachable!("Reserved opcodes are unrechable"),
| Instruction::Reserved56
| Instruction::Reserved57
| Instruction::Reserved58 => unreachable!("Reserved opcodes are unrechable"),
}
}

Expand Down
83 changes: 0 additions & 83 deletions boa_engine/src/vm/opcode/get/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,44 +41,6 @@ impl Operation for GetArrowFunction {
}
}

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

impl GetAsyncArrowFunction {
#[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_function_object_fast(code, false, context);
context.vm.push(function);
Ok(CompletionType::Normal)
}
}

impl Operation for GetAsyncArrowFunction {
const NAME: &'static str = "GetAsyncArrowFunction";
const INSTRUCTION: &'static str = "INST - GetAsyncArrowFunction";
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)
}
}

/// `GetFunction` implements the Opcode Operation for `Opcode::GetFunction`
///
/// Operation:
Expand Down Expand Up @@ -123,48 +85,3 @@ impl Operation for GetFunction {
Self::operation(context, index, method)
}
}

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

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

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

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

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

fn execute_with_u32_operands(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u32>() as usize;
let method = context.vm.read::<u8>() != 0;
Self::operation(context, index, method)
}
}
18 changes: 4 additions & 14 deletions boa_engine/src/vm/opcode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1676,27 +1676,13 @@ generate_opcodes! {
/// Stack: **=>** func
GetArrowFunction { index: VaryingOperand },

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

/// Get function from the pre-compiled inner functions.
///
/// Operands: index: `VaryingOperand`, is_method: `u8`
///
/// Stack: **=>** func
GetFunction { index: VaryingOperand, method: bool },

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

/// Get generator function from the pre-compiled inner functions.
///
/// Operands: index: `VaryingOperand`,
Expand Down Expand Up @@ -2221,6 +2207,10 @@ generate_opcodes! {
Reserved55 => Reserved,
/// Reserved [`Opcode`].
Reserved56 => Reserved,
/// Reserved [`Opcode`].
Reserved57 => Reserved,
/// Reserved [`Opcode`].
Reserved58 => Reserved,
}

/// Specific opcodes for bindings.
Expand Down

0 comments on commit 7b4273a

Please sign in to comment.