Skip to content

Commit

Permalink
Remove some opcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Jun 27, 2023
1 parent 73d4577 commit a087128
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 235 deletions.
8 changes: 1 addition & 7 deletions boa_engine/src/bytecompiler/statement/labelled.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::{
bytecompiler::{ByteCompiler, NodeKind},
vm::Opcode,
};
use crate::bytecompiler::{ByteCompiler, NodeKind};
use boa_ast::{
statement::{Labelled, LabelledItem},
Statement,
Expand All @@ -11,7 +8,6 @@ impl ByteCompiler<'_, '_> {
/// Compile a [`Labelled`] `boa_ast` node
pub(crate) fn compile_labelled(&mut self, labelled: &Labelled, use_expr: bool) {
let labelled_loc = self.next_opcode_location();
let end_label = self.emit_opcode_with_operand(Opcode::LabelledStart);
self.push_labelled_control_info(labelled.label(), labelled_loc, use_expr);

match labelled.item() {
Expand All @@ -38,8 +34,6 @@ impl ByteCompiler<'_, '_> {
}
}

let labelled_end = self.next_opcode_location();
self.patch_jump_with_target(end_label, labelled_end);
self.pop_labelled_control_info();
}
}
15 changes: 4 additions & 11 deletions boa_engine/src/bytecompiler/statement/try.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
bytecompiler::{jump_control::JumpControlInfoFlags, ByteCompiler, Label},
bytecompiler::{jump_control::JumpControlInfoFlags, ByteCompiler},
vm::{BindingOpcode, Opcode},
};
use boa_ast::{
Expand All @@ -25,6 +25,7 @@ impl ByteCompiler<'_, '_> {

self.emit_opcode(Opcode::TryEnd);

// TODO: simplify when there is finally but no catch.
if has_finally {
self.emit_opcode(Opcode::PushZero);
if has_catch {
Expand All @@ -50,15 +51,14 @@ impl ByteCompiler<'_, '_> {
// Pop and push control loops post FinallyStart, as FinallyStart resets flow control variables.
// Handle finally header operations
let finally_start = self.next_opcode_location();
let finally_end = self.emit_opcode_with_operand(Opcode::FinallyStart);

self.jump_info
.last_mut()
.expect("there should be a try block")
.flags |= JumpControlInfoFlags::IN_FINALLY;
self.patch_jump_with_target(finally_loc, finally_start);
// Compile finally statement body
self.compile_finally_stmt(finally, finally_end, has_catch);
self.compile_finally_stmt(finally, has_catch);

self.pop_try_control_info(finally_start);
} else {
Expand Down Expand Up @@ -103,12 +103,7 @@ impl ByteCompiler<'_, '_> {
}
}

pub(crate) fn compile_finally_stmt(
&mut self,
finally: &Finally,
finally_end_label: Label,
has_catch: bool,
) {
pub(crate) fn compile_finally_stmt(&mut self, finally: &Finally, has_catch: bool) {
// TODO: We could probably remove the Get/SetReturnValue if we check that there is no break/continues statements.
self.emit_opcode(Opcode::GetReturnValue);
self.compile_block(finally.block(), true);
Expand All @@ -122,7 +117,5 @@ impl ByteCompiler<'_, '_> {
// Rethrow error if error happend!
self.emit_opcode(Opcode::ReThrow);
self.patch_jump(has_throw_exit);

self.patch_jump(finally_end_label);
}
}
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 @@ -315,8 +315,6 @@ impl CodeBlock {
| Opcode::JumpIfFalse
| Opcode::JumpIfNotUndefined
| Opcode::JumpIfNullOrUndefined
| Opcode::FinallyStart
| Opcode::LabelledStart
| Opcode::Case
| Opcode::Default
| Opcode::LogicalAnd
Expand Down Expand Up @@ -539,7 +537,6 @@ impl CodeBlock {
| Opcode::LoopContinue
| Opcode::LoopStart
| Opcode::IteratorLoopStart
| Opcode::LabelledEnd
| Opcode::CreateForInIterator
| Opcode::GetIterator
| Opcode::GetAsyncIterator
Expand Down Expand Up @@ -637,7 +634,10 @@ impl CodeBlock {
| Opcode::Reserved51
| Opcode::Reserved52
| Opcode::Reserved53
| Opcode::Reserved54 => unreachable!("Reserved opcodes are unrechable"),
| Opcode::Reserved54
| Opcode::Reserved55
| Opcode::Reserved56
| Opcode::Reserved57 => unreachable!("Reserved opcodes are unrechable"),
}
}
}
Expand Down
17 changes: 5 additions & 12 deletions boa_engine/src/vm/flowgraph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,6 @@ impl CodeBlock {
EdgeStyle::Line,
);
}
Opcode::LabelledStart => {
let end_address = self.read::<u32>(pc);
pc += size_of::<u32>();

let label = format!("{opcode_str} {end_address}");
graph.add_node(previous_pc, NodeShape::None, label.into(), Color::Red);
graph.add_edge(previous_pc, pc, None, Color::None, EdgeStyle::Line);
}
Opcode::TemplateLookup | Opcode::TemplateCreate => {
let start_address = self.read::<u32>(pc);
pc += size_of::<u32>();
Expand Down Expand Up @@ -272,8 +264,7 @@ impl CodeBlock {
| Opcode::Call
| Opcode::New
| Opcode::SuperCall
| Opcode::ConcatToString
| Opcode::FinallyStart => {
| Opcode::ConcatToString => {
pc += size_of::<u32>();
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 @@ -584,7 +575,6 @@ impl CodeBlock {
| Opcode::LoopContinue
| Opcode::LoopStart
| Opcode::IteratorLoopStart
| Opcode::LabelledEnd
| Opcode::CreateForInIterator
| Opcode::GetIterator
| Opcode::GetAsyncIterator
Expand Down Expand Up @@ -707,7 +697,10 @@ impl CodeBlock {
| Opcode::Reserved51
| Opcode::Reserved52
| Opcode::Reserved53
| Opcode::Reserved54 => unreachable!("Reserved opcodes are unrechable"),
| Opcode::Reserved54
| Opcode::Reserved55
| Opcode::Reserved56
| Opcode::Reserved57 => unreachable!("Reserved opcodes are unrechable"),
}
}

Expand Down
139 changes: 0 additions & 139 deletions boa_engine/src/vm/opcode/control_flow/finally.rs

This file was deleted.

37 changes: 0 additions & 37 deletions boa_engine/src/vm/opcode/control_flow/labelled.rs

This file was deleted.

4 changes: 0 additions & 4 deletions boa_engine/src/vm/opcode/control_flow/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
pub(crate) mod r#break;
pub(crate) mod r#continue;
pub(crate) mod finally;
pub(crate) mod labelled;
pub(crate) mod r#return;
pub(crate) mod throw;
pub(crate) mod r#try;

pub(crate) use finally::*;
pub(crate) use labelled::*;
pub(crate) use r#break::*;
pub(crate) use r#continue::*;
pub(crate) use r#return::*;
Expand Down
27 changes: 6 additions & 21 deletions boa_engine/src/vm/opcode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1166,13 +1166,6 @@ generate_impl! {
/// Stack: **=>**
TryEnd,

/// Start of a finally block.
///
/// Operands:
///
/// Stack: **=>**
FinallyStart,

/// Unconditional Jump
///
/// Operands: Jump Address: u32
Expand Down Expand Up @@ -1410,20 +1403,6 @@ generate_impl! {
/// Stack: **=>** value
LoopEnd,

/// Push labelled start marker.
///
/// Operands: Exit Address: u32,
///
/// Stack: **=>**
LabelledStart,

/// Clean up environments at the end of a labelled block.
///
/// Operands:
///
/// Stack: **=>**
LabelledEnd,

/// Creates the ForInIterator of an object.
///
/// Stack: object **=>**
Expand Down Expand Up @@ -1802,6 +1781,12 @@ generate_impl! {
Reserved53 => Reserved,
/// Reserved [`Opcode`].
Reserved54 => Reserved,
/// Reserved [`Opcode`].
Reserved55 => Reserved,
/// Reserved [`Opcode`].
Reserved56 => Reserved,
/// Reserved [`Opcode`].
Reserved57 => Reserved,
}
}

Expand Down

0 comments on commit a087128

Please sign in to comment.