mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-24 18:51:13 +08:00
refactor: 控制流跳转改经 fixup 延迟发射
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
use crate::compiler::{CompileCtx, Compiler};
|
||||
use oxide_bytecode::opcode;
|
||||
|
||||
impl Compiler {
|
||||
pub(super) fn count_break_statement(&self, ctx: &mut CompileCtx) {
|
||||
@@ -25,10 +24,7 @@ impl Compiler {
|
||||
let (bl, _) = ctx.current_loop().ok_or("break outside switch or loop".to_string())?;
|
||||
*bl
|
||||
};
|
||||
let break_pos = ctx.resolve_label(break_label)?;
|
||||
let offset = (break_pos as isize) - (ctx.bytecode.len() as isize);
|
||||
let offset = ctx.checked_jump_offset(offset);
|
||||
ctx.emit(opcode::encode_jmp(offset));
|
||||
ctx.emit_jmp_labeled(break_label);
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
@@ -47,10 +43,7 @@ impl Compiler {
|
||||
let (_, cl) = ctx.current_loop().ok_or("continue outside loop".to_string())?;
|
||||
*cl
|
||||
};
|
||||
let continue_pos = ctx.resolve_label(continue_label)?;
|
||||
let offset = (continue_pos as isize) - (ctx.bytecode.len() as isize);
|
||||
let offset = ctx.checked_jump_offset(offset);
|
||||
ctx.emit(opcode::encode_jmp(offset));
|
||||
ctx.emit_jmp_labeled(continue_label);
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ impl Compiler {
|
||||
let id = ctx.next_label_id();
|
||||
ctx.push_label_scope(name, Label::LabeledEnd(id), None)?;
|
||||
self.emit_statement(&stmt.body, ctx)?;
|
||||
ctx.labels.label_map.insert(Label::LabeledEnd(id), ctx.bytecode.len());
|
||||
ctx.pop_label_scope();
|
||||
}
|
||||
Ok(None)
|
||||
|
||||
Reference in New Issue
Block a user