Skip to content

Commit a087128

Browse files
committed
Remove some opcodes
1 parent 73d4577 commit a087128

File tree

8 files changed

+20
-235
lines changed

8 files changed

+20
-235
lines changed

boa_engine/src/bytecompiler/statement/labelled.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use crate::{
2-
bytecompiler::{ByteCompiler, NodeKind},
3-
vm::Opcode,
4-
};
1+
use crate::bytecompiler::{ByteCompiler, NodeKind};
52
use boa_ast::{
63
statement::{Labelled, LabelledItem},
74
Statement,
@@ -11,7 +8,6 @@ impl ByteCompiler<'_, '_> {
118
/// Compile a [`Labelled`] `boa_ast` node
129
pub(crate) fn compile_labelled(&mut self, labelled: &Labelled, use_expr: bool) {
1310
let labelled_loc = self.next_opcode_location();
14-
let end_label = self.emit_opcode_with_operand(Opcode::LabelledStart);
1511
self.push_labelled_control_info(labelled.label(), labelled_loc, use_expr);
1612

1713
match labelled.item() {
@@ -38,8 +34,6 @@ impl ByteCompiler<'_, '_> {
3834
}
3935
}
4036

41-
let labelled_end = self.next_opcode_location();
42-
self.patch_jump_with_target(end_label, labelled_end);
4337
self.pop_labelled_control_info();
4438
}
4539
}

boa_engine/src/bytecompiler/statement/try.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
bytecompiler::{jump_control::JumpControlInfoFlags, ByteCompiler, Label},
2+
bytecompiler::{jump_control::JumpControlInfoFlags, ByteCompiler},
33
vm::{BindingOpcode, Opcode},
44
};
55
use boa_ast::{
@@ -25,6 +25,7 @@ impl ByteCompiler<'_, '_> {
2525

2626
self.emit_opcode(Opcode::TryEnd);
2727

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

5555
self.jump_info
5656
.last_mut()
5757
.expect("there should be a try block")
5858
.flags |= JumpControlInfoFlags::IN_FINALLY;
5959
self.patch_jump_with_target(finally_loc, finally_start);
6060
// Compile finally statement body
61-
self.compile_finally_stmt(finally, finally_end, has_catch);
61+
self.compile_finally_stmt(finally, has_catch);
6262

6363
self.pop_try_control_info(finally_start);
6464
} else {
@@ -103,12 +103,7 @@ impl ByteCompiler<'_, '_> {
103103
}
104104
}
105105

106-
pub(crate) fn compile_finally_stmt(
107-
&mut self,
108-
finally: &Finally,
109-
finally_end_label: Label,
110-
has_catch: bool,
111-
) {
106+
pub(crate) fn compile_finally_stmt(&mut self, finally: &Finally, has_catch: bool) {
112107
// TODO: We could probably remove the Get/SetReturnValue if we check that there is no break/continues statements.
113108
self.emit_opcode(Opcode::GetReturnValue);
114109
self.compile_block(finally.block(), true);
@@ -122,7 +117,5 @@ impl ByteCompiler<'_, '_> {
122117
// Rethrow error if error happend!
123118
self.emit_opcode(Opcode::ReThrow);
124119
self.patch_jump(has_throw_exit);
125-
126-
self.patch_jump(finally_end_label);
127120
}
128121
}

boa_engine/src/vm/code_block.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,6 @@ impl CodeBlock {
315315
| Opcode::JumpIfFalse
316316
| Opcode::JumpIfNotUndefined
317317
| Opcode::JumpIfNullOrUndefined
318-
| Opcode::FinallyStart
319-
| Opcode::LabelledStart
320318
| Opcode::Case
321319
| Opcode::Default
322320
| Opcode::LogicalAnd
@@ -539,7 +537,6 @@ impl CodeBlock {
539537
| Opcode::LoopContinue
540538
| Opcode::LoopStart
541539
| Opcode::IteratorLoopStart
542-
| Opcode::LabelledEnd
543540
| Opcode::CreateForInIterator
544541
| Opcode::GetIterator
545542
| Opcode::GetAsyncIterator
@@ -637,7 +634,10 @@ impl CodeBlock {
637634
| Opcode::Reserved51
638635
| Opcode::Reserved52
639636
| Opcode::Reserved53
640-
| Opcode::Reserved54 => unreachable!("Reserved opcodes are unrechable"),
637+
| Opcode::Reserved54
638+
| Opcode::Reserved55
639+
| Opcode::Reserved56
640+
| Opcode::Reserved57 => unreachable!("Reserved opcodes are unrechable"),
641641
}
642642
}
643643
}

boa_engine/src/vm/flowgraph/mod.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,6 @@ impl CodeBlock {
130130
EdgeStyle::Line,
131131
);
132132
}
133-
Opcode::LabelledStart => {
134-
let end_address = self.read::<u32>(pc);
135-
pc += size_of::<u32>();
136-
137-
let label = format!("{opcode_str} {end_address}");
138-
graph.add_node(previous_pc, NodeShape::None, label.into(), Color::Red);
139-
graph.add_edge(previous_pc, pc, None, Color::None, EdgeStyle::Line);
140-
}
141133
Opcode::TemplateLookup | Opcode::TemplateCreate => {
142134
let start_address = self.read::<u32>(pc);
143135
pc += size_of::<u32>();
@@ -272,8 +264,7 @@ impl CodeBlock {
272264
| Opcode::Call
273265
| Opcode::New
274266
| Opcode::SuperCall
275-
| Opcode::ConcatToString
276-
| Opcode::FinallyStart => {
267+
| Opcode::ConcatToString => {
277268
pc += size_of::<u32>();
278269
graph.add_node(previous_pc, NodeShape::None, label.into(), Color::None);
279270
graph.add_edge(previous_pc, pc, None, Color::None, EdgeStyle::Line);
@@ -584,7 +575,6 @@ impl CodeBlock {
584575
| Opcode::LoopContinue
585576
| Opcode::LoopStart
586577
| Opcode::IteratorLoopStart
587-
| Opcode::LabelledEnd
588578
| Opcode::CreateForInIterator
589579
| Opcode::GetIterator
590580
| Opcode::GetAsyncIterator
@@ -707,7 +697,10 @@ impl CodeBlock {
707697
| Opcode::Reserved51
708698
| Opcode::Reserved52
709699
| Opcode::Reserved53
710-
| Opcode::Reserved54 => unreachable!("Reserved opcodes are unrechable"),
700+
| Opcode::Reserved54
701+
| Opcode::Reserved55
702+
| Opcode::Reserved56
703+
| Opcode::Reserved57 => unreachable!("Reserved opcodes are unrechable"),
711704
}
712705
}
713706

boa_engine/src/vm/opcode/control_flow/finally.rs

Lines changed: 0 additions & 139 deletions
This file was deleted.

boa_engine/src/vm/opcode/control_flow/labelled.rs

Lines changed: 0 additions & 37 deletions
This file was deleted.

boa_engine/src/vm/opcode/control_flow/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
pub(crate) mod r#break;
22
pub(crate) mod r#continue;
3-
pub(crate) mod finally;
4-
pub(crate) mod labelled;
53
pub(crate) mod r#return;
64
pub(crate) mod throw;
75
pub(crate) mod r#try;
86

9-
pub(crate) use finally::*;
10-
pub(crate) use labelled::*;
117
pub(crate) use r#break::*;
128
pub(crate) use r#continue::*;
139
pub(crate) use r#return::*;

boa_engine/src/vm/opcode/mod.rs

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,13 +1166,6 @@ generate_impl! {
11661166
/// Stack: **=>**
11671167
TryEnd,
11681168

1169-
/// Start of a finally block.
1170-
///
1171-
/// Operands:
1172-
///
1173-
/// Stack: **=>**
1174-
FinallyStart,
1175-
11761169
/// Unconditional Jump
11771170
///
11781171
/// Operands: Jump Address: u32
@@ -1410,20 +1403,6 @@ generate_impl! {
14101403
/// Stack: **=>** value
14111404
LoopEnd,
14121405

1413-
/// Push labelled start marker.
1414-
///
1415-
/// Operands: Exit Address: u32,
1416-
///
1417-
/// Stack: **=>**
1418-
LabelledStart,
1419-
1420-
/// Clean up environments at the end of a labelled block.
1421-
///
1422-
/// Operands:
1423-
///
1424-
/// Stack: **=>**
1425-
LabelledEnd,
1426-
14271406
/// Creates the ForInIterator of an object.
14281407
///
14291408
/// Stack: object **=>**
@@ -1802,6 +1781,12 @@ generate_impl! {
18021781
Reserved53 => Reserved,
18031782
/// Reserved [`Opcode`].
18041783
Reserved54 => Reserved,
1784+
/// Reserved [`Opcode`].
1785+
Reserved55 => Reserved,
1786+
/// Reserved [`Opcode`].
1787+
Reserved56 => Reserved,
1788+
/// Reserved [`Opcode`].
1789+
Reserved57 => Reserved,
18051790
}
18061791
}
18071792

0 commit comments

Comments
 (0)