From 8ab27429e98d47a5f85696799519aa3cede1a25b Mon Sep 17 00:00:00 2001 From: Haled Odat <8566042+HalidOdat@users.noreply.github.com> Date: Sun, 9 Jul 2023 14:26:57 +0200 Subject: [PATCH] Remove TryStart opcode --- boa_engine/src/bytecompiler/statement/try.rs | 2 +- boa_engine/src/vm/code_block.rs | 4 +-- boa_engine/src/vm/flowgraph/mod.rs | 4 +-- boa_engine/src/vm/opcode/control_flow/mod.rs | 2 -- .../src/vm/opcode/control_flow/return.rs | 32 ------------------- boa_engine/src/vm/opcode/control_flow/try.rs | 20 ------------ boa_engine/src/vm/opcode/mod.rs | 9 ++---- 7 files changed, 7 insertions(+), 66 deletions(-) delete mode 100644 boa_engine/src/vm/opcode/control_flow/try.rs diff --git a/boa_engine/src/bytecompiler/statement/try.rs b/boa_engine/src/bytecompiler/statement/try.rs index 3cae09551fc..f26eed4f9cb 100644 --- a/boa_engine/src/bytecompiler/statement/try.rs +++ b/boa_engine/src/bytecompiler/statement/try.rs @@ -18,7 +18,7 @@ impl ByteCompiler<'_, '_> { let has_finally = t.finally().is_some(); self.push_try_control_info(has_finally, try_start, use_expr); - self.emit_opcode(Opcode::TryStart); + // Compile try block self.compile_block(t.block(), use_expr); let end_address = self.next_opcode_location(); diff --git a/boa_engine/src/vm/code_block.rs b/boa_engine/src/vm/code_block.rs index 12897a839b3..34f177a1651 100644 --- a/boa_engine/src/vm/code_block.rs +++ b/boa_engine/src/vm/code_block.rs @@ -472,7 +472,6 @@ impl CodeBlock { format!("done: {done}") } Opcode::Pop - | Opcode::TryStart | Opcode::Dup | Opcode::Swap | Opcode::PushZero @@ -651,7 +650,8 @@ impl CodeBlock { | Opcode::Reserved57 | Opcode::Reserved58 | Opcode::Reserved59 - | Opcode::Reserved60 => unreachable!("Reserved opcodes are unrechable"), + | Opcode::Reserved60 + | Opcode::Reserved61 => unreachable!("Reserved opcodes are unrechable"), } } } diff --git a/boa_engine/src/vm/flowgraph/mod.rs b/boa_engine/src/vm/flowgraph/mod.rs index 985f2dbc180..4913ca2a931 100644 --- a/boa_engine/src/vm/flowgraph/mod.rs +++ b/boa_engine/src/vm/flowgraph/mod.rs @@ -479,7 +479,6 @@ impl CodeBlock { graph.add_edge(previous_pc, pc, None, Color::None, EdgeStyle::Line); } Opcode::Pop - | Opcode::TryStart | Opcode::Dup | Opcode::Swap | Opcode::PushZero @@ -672,7 +671,8 @@ impl CodeBlock { | Opcode::Reserved57 | Opcode::Reserved58 | Opcode::Reserved59 - | Opcode::Reserved60 => unreachable!("Reserved opcodes are unrechable"), + | Opcode::Reserved60 + | Opcode::Reserved61 => unreachable!("Reserved opcodes are unrechable"), } } diff --git a/boa_engine/src/vm/opcode/control_flow/mod.rs b/boa_engine/src/vm/opcode/control_flow/mod.rs index 961180b0e10..a3ac8d1488f 100644 --- a/boa_engine/src/vm/opcode/control_flow/mod.rs +++ b/boa_engine/src/vm/opcode/control_flow/mod.rs @@ -1,7 +1,5 @@ pub(crate) mod r#return; pub(crate) mod throw; -pub(crate) mod r#try; pub(crate) use r#return::*; -pub(crate) use r#try::*; pub(crate) use throw::*; diff --git a/boa_engine/src/vm/opcode/control_flow/return.rs b/boa_engine/src/vm/opcode/control_flow/return.rs index 114fa4eea82..17e88983906 100644 --- a/boa_engine/src/vm/opcode/control_flow/return.rs +++ b/boa_engine/src/vm/opcode/control_flow/return.rs @@ -15,38 +15,6 @@ impl Operation for Return { const INSTRUCTION: &'static str = "INST - Return"; fn execute(_context: &mut Context<'_>) -> JsResult { - // let current_address = context.vm.frame().pc; - // let mut env_to_pop = 0; - // let mut finally_address = None; - // while let Some(env_entry) = context.vm.frame().env_stack.last() { - // if env_entry.is_finally_env() { - // if env_entry.start_address() < current_address { - // finally_address = Some(env_entry.exit_address()); - // } else { - // finally_address = Some(env_entry.start_address()); - // } - // break; - // } - - // env_to_pop += env_entry.env_num(); - // if env_entry.is_global_env() { - // break; - // } - - // context.vm.frame_mut().env_stack.pop(); - // } - - // let env_truncation_len = context.vm.environments.len().saturating_sub(env_to_pop); - // context.vm.environments.truncate(env_truncation_len); - - // let record = AbruptCompletionRecord::new_return(); - // context.vm.frame_mut().abrupt_completion = Some(record); - - // if let Some(finally) = finally_address { - // context.vm.frame_mut().pc = finally; - // return Ok(CompletionType::Normal); - // } - Ok(CompletionType::Return) } } diff --git a/boa_engine/src/vm/opcode/control_flow/try.rs b/boa_engine/src/vm/opcode/control_flow/try.rs deleted file mode 100644 index 1922df03f73..00000000000 --- a/boa_engine/src/vm/opcode/control_flow/try.rs +++ /dev/null @@ -1,20 +0,0 @@ -use crate::{ - vm::{opcode::Operation, CompletionType}, - Context, JsResult, -}; - -/// `TryStart` implements the Opcode Operation for `Opcode::TryStart` -/// -/// Operation: -/// - Start of a try block. -#[derive(Debug, Clone, Copy)] -pub(crate) struct TryStart; - -impl Operation for TryStart { - const NAME: &'static str = "TryStart"; - const INSTRUCTION: &'static str = "INST - TryStart"; - - fn execute(_context: &mut Context<'_>) -> JsResult { - Ok(CompletionType::Normal) - } -} diff --git a/boa_engine/src/vm/opcode/mod.rs b/boa_engine/src/vm/opcode/mod.rs index ecb702be84b..717e4239e14 100644 --- a/boa_engine/src/vm/opcode/mod.rs +++ b/boa_engine/src/vm/opcode/mod.rs @@ -1152,13 +1152,6 @@ generate_impl! { /// Stack: **=>** ThrowNewTypeError, - /// TODO: doc - /// - /// Operands: - /// - /// Stack: **=>** - TryStart, - /// Pops value converts it to boolean and pushes it back. /// /// Operands: @@ -1770,6 +1763,8 @@ generate_impl! { Reserved59 => Reserved, /// Reserved [`Opcode`]. Reserved60 => Reserved, + /// Reserved [`Opcode`]. + Reserved61 => Reserved, } }