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 aa47f34 commit ab575f7
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 350 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();
}
}
5 changes: 0 additions & 5 deletions boa_engine/src/bytecompiler/statement/loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ impl ByteCompiler<'_, '_> {
if env_labels.is_some() {
self.emit_opcode(Opcode::PopEnvironment);
}
self.emit_opcode(Opcode::LoopEnd);

if let Some(env_labels) = env_labels {
let env_index = self.pop_compile_environment();
Expand Down Expand Up @@ -233,7 +232,6 @@ impl ByteCompiler<'_, '_> {

self.patch_jump(exit);
self.pop_loop_control_info();
self.emit_opcode(Opcode::LoopEnd);

self.iterator_close(false);

Expand Down Expand Up @@ -379,7 +377,6 @@ impl ByteCompiler<'_, '_> {

self.patch_jump(exit);
self.pop_loop_control_info();
self.emit_opcode(Opcode::LoopEnd);

self.iterator_close(for_of_loop.r#await());
}
Expand All @@ -404,7 +401,6 @@ impl ByteCompiler<'_, '_> {

self.patch_jump(exit);
self.pop_loop_control_info();
self.emit_opcode(Opcode::LoopEnd);
}

pub(crate) fn compile_do_while_loop(
Expand Down Expand Up @@ -433,6 +429,5 @@ impl ByteCompiler<'_, '_> {
self.patch_jump(exit);

self.pop_loop_control_info();
self.emit_opcode(Opcode::LoopEnd);
}
}
1 change: 0 additions & 1 deletion boa_engine/src/bytecompiler/statement/switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ impl ByteCompiler<'_, '_> {
}

self.pop_switch_control_info();
self.emit_opcode(Opcode::LoopEnd);

let env_index = self.pop_compile_environment();
self.patch_jump_with_target(push_env, env_index);
Expand Down
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);
}
}
17 changes: 7 additions & 10 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 @@ -346,11 +344,6 @@ impl CodeBlock {
*pc += size_of::<u32>();
format!("{operand1}, {operand2}")
}
Opcode::Break | Opcode::Continue => {
let operand = self.read::<u32>(*pc);
*pc += size_of::<u32>();
format!("{operand}")
}
Opcode::TemplateLookup | Opcode::TemplateCreate => {
let operand1 = self.read::<u32>(*pc);
*pc += size_of::<u32>();
Expand Down Expand Up @@ -535,11 +528,9 @@ impl CodeBlock {
| Opcode::Super
| Opcode::Return
| Opcode::PopEnvironment
| Opcode::LoopEnd
| Opcode::LoopContinue
| Opcode::LoopStart
| Opcode::IteratorLoopStart
| Opcode::LabelledEnd
| Opcode::CreateForInIterator
| Opcode::GetIterator
| Opcode::GetAsyncIterator
Expand Down Expand Up @@ -637,7 +628,13 @@ impl CodeBlock {
| Opcode::Reserved51
| Opcode::Reserved52
| Opcode::Reserved53
| Opcode::Reserved54 => unreachable!("Reserved opcodes are unrechable"),
| Opcode::Reserved54
| Opcode::Reserved55
| Opcode::Reserved56
| Opcode::Reserved57
| Opcode::Reserved58
| Opcode::Reserved59
| Opcode::Reserved60 => unreachable!("Reserved opcodes are unrechable"),
}
}
}
Expand Down
49 changes: 8 additions & 41 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 All @@ -148,34 +140,6 @@ impl CodeBlock {
graph.add_node(previous_pc, NodeShape::None, label.into(), Color::Red);
graph.add_edge(previous_pc, pc, None, Color::None, EdgeStyle::Line);
}
Opcode::Break => {
let jump_operand = self.read::<u32>(pc);
pc += size_of::<u32>();

let label = format!("{opcode_str} {jump_operand}");
graph.add_node(previous_pc, NodeShape::None, label.into(), Color::Red);
graph.add_edge(
previous_pc,
jump_operand as usize,
Some("BREAK".into()),
Color::Red,
EdgeStyle::Line,
);
}
Opcode::Continue => {
let jump_operand = self.read::<u32>(pc);
pc += size_of::<u32>();

let label = format!("{opcode_str} {jump_operand}");
graph.add_node(previous_pc, NodeShape::None, label.into(), Color::Red);
graph.add_edge(
previous_pc,
jump_operand as usize,
Some("CONTINUE".into()),
Color::Red,
EdgeStyle::Line,
);
}
Opcode::LogicalAnd | Opcode::LogicalOr | Opcode::Coalesce => {
let exit = self.read::<u32>(pc);
pc += size_of::<u32>();
Expand Down Expand Up @@ -272,8 +236,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 @@ -580,11 +543,9 @@ impl CodeBlock {
| Opcode::ToBoolean
| Opcode::This
| Opcode::Super
| Opcode::LoopEnd
| Opcode::LoopContinue
| Opcode::LoopStart
| Opcode::IteratorLoopStart
| Opcode::LabelledEnd
| Opcode::CreateForInIterator
| Opcode::GetIterator
| Opcode::GetAsyncIterator
Expand Down Expand Up @@ -707,7 +668,13 @@ impl CodeBlock {
| Opcode::Reserved51
| Opcode::Reserved52
| Opcode::Reserved53
| Opcode::Reserved54 => unreachable!("Reserved opcodes are unrechable"),
| Opcode::Reserved54
| Opcode::Reserved55
| Opcode::Reserved56
| Opcode::Reserved57
| Opcode::Reserved58
| Opcode::Reserved59
| Opcode::Reserved60 => unreachable!("Reserved opcodes are unrechable"),
}
}

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

This file was deleted.

26 changes: 0 additions & 26 deletions boa_engine/src/vm/opcode/control_flow/continue.rs

This file was deleted.

Loading

0 comments on commit ab575f7

Please sign in to comment.