mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-23 18:21:13 +08:00
fix: 修复无 else 块时冗余指令跳转问题
This commit is contained in:
@@ -33,7 +33,9 @@ impl Compiler {
|
||||
self.count_statement(&ifs.consequent, ctx);
|
||||
ctx.alloc_reg(); // result register
|
||||
ctx.projected_pc += 1; // LOAD_VAR result <- consequent
|
||||
ctx.projected_pc += 1; // JMP (skip else)
|
||||
if ifs.alternate.is_some() {
|
||||
ctx.projected_pc += 1; // JMP (skip else)
|
||||
}
|
||||
ctx.label_map.insert(else_label, ctx.projected_pc);
|
||||
if let Some(alt_stmt) = &ifs.alternate {
|
||||
self.count_statement(alt_stmt, ctx);
|
||||
@@ -173,7 +175,7 @@ impl Compiler {
|
||||
LogicalOperator::And => Label::TernaryEnd(id),
|
||||
LogicalOperator::Or => Label::TernaryElse(id),
|
||||
LogicalOperator::Coalesce => {
|
||||
return;
|
||||
unreachable!()
|
||||
}
|
||||
};
|
||||
ctx.label_map.insert(skip_label, ctx.projected_pc);
|
||||
|
||||
@@ -93,9 +93,12 @@ impl Compiler {
|
||||
));
|
||||
}
|
||||
|
||||
let end_pos = ctx.label_map[&end_label];
|
||||
let offset = (end_pos as isize) - (ctx.bytecode.len() as isize);
|
||||
ctx.emit(opcode::encode_jmp(offset as i16));
|
||||
let has_alt = ifs.alternate.is_some();
|
||||
if has_alt {
|
||||
let end_pos = ctx.label_map[&end_label];
|
||||
let offset = (end_pos as isize) - (ctx.bytecode.len() as isize);
|
||||
ctx.emit(opcode::encode_jmp(offset as i16));
|
||||
}
|
||||
|
||||
if let Some(alt) = &ifs.alternate {
|
||||
let alt_reg = self.emit_statement(alt, ctx)?;
|
||||
|
||||
Reference in New Issue
Block a user