diff --git a/crates/oxide_compiler/src/compiler.rs b/crates/oxide_compiler/src/compiler.rs
index 30c6811..86d5c5a 100644
--- a/crates/oxide_compiler/src/compiler.rs
+++ b/crates/oxide_compiler/src/compiler.rs
@@ -331,6 +331,17 @@ impl CompileCtx {
});
}
+ pub(crate) fn emit_try_finally_begin_labeled(&mut self, label: Label) {
+ let pc = self.bytecode.len();
+ self.emit(opcode::encode_try_finally_begin(0));
+ self.fixups.push(JumpFixup {
+ pc,
+ label,
+ opcode: OpCode::TRY_FINALLY_BEGIN,
+ rd: 0,
+ });
+ }
+
pub(crate) fn count_word(&mut self) {
self.projected_pc += 1;
}
@@ -481,6 +492,7 @@ impl CompileCtx {
OpCode::JMP_IF_TRUE => opcode::encode_jmp_if_true(fixup.rd, offset),
OpCode::JMP_IF_NULLISH => opcode::encode_jmp_if_nullish(fixup.rd, offset),
OpCode::TRY_BEGIN => opcode::encode_try_begin(offset),
+ OpCode::TRY_FINALLY_BEGIN => opcode::encode_try_finally_begin(offset),
_ => return Err(format!("Unsupported fixup opcode {:?}", fixup.opcode)),
};
}
@@ -1275,17 +1287,11 @@ impl Compiler {
pub(crate) fn count_statement(&self, stmt: &Statement, ctx: &mut CompileCtx) {
match stmt {
- Statement::BreakStatement(_) | Statement::ContinueStatement(_) | Statement::LabeledStatement(_) => {
- self.count_basic(stmt, ctx)
- }
- Statement::IfStatement(_) => self.count_control_domain(stmt, ctx),
Statement::WhileStatement(_)
| Statement::DoWhileStatement(_)
| Statement::ForStatement(_)
| Statement::ForInStatement(_)
| Statement::ForOfStatement(_) => self.count_iteration_domain(stmt, ctx),
- Statement::SwitchStatement(_) => self.count_switch_domain(stmt, ctx),
- Statement::TryStatement(_) => self.count_exception_domain(stmt, ctx),
_ => {}
}
}
diff --git a/crates/oxide_compiler/src/stmt/basic/break_continue.rs b/crates/oxide_compiler/src/stmt/basic/break_continue.rs
index d9f4bd3..1536144 100644
--- a/crates/oxide_compiler/src/stmt/basic/break_continue.rs
+++ b/crates/oxide_compiler/src/stmt/basic/break_continue.rs
@@ -1,14 +1,6 @@
use crate::compiler::{CompileCtx, Compiler};
impl Compiler {
- pub(super) fn count_break_statement(&self, ctx: &mut CompileCtx) {
- ctx.projected_pc += 1;
- }
-
- pub(super) fn count_continue_statement(&self, ctx: &mut CompileCtx) {
- ctx.projected_pc += 1;
- }
-
pub(crate) fn emit_break_statement(
&self, stmt: &oxide_parser::BreakStatement, ctx: &mut CompileCtx,
) -> Result