fix: 对齐 counter/emitter 指令条数,修解构参数、数组赋值元素、解构catch、for-init 无初始化的跳转漂移
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
use super::super::*;
|
||||
|
||||
impl Compiler {
|
||||
pub(in crate::counter) fn count_binding_pattern(
|
||||
&self, pattern: &oxide_parser::BindingPattern, ctx: &mut CompileCtx,
|
||||
) {
|
||||
pub(crate) fn count_binding_pattern(&self, pattern: &oxide_parser::BindingPattern, ctx: &mut CompileCtx) {
|
||||
match pattern {
|
||||
oxide_parser::BindingPattern::BindingIdentifier(_) => {
|
||||
ctx.alloc_reg();
|
||||
@@ -72,9 +70,11 @@ impl Compiler {
|
||||
ctx.count_instr(); // FOR_OF_DONE
|
||||
ctx.alloc_reg();
|
||||
ctx.count_instr(); // FOR_OF_NEXT
|
||||
if elem.is_some() {
|
||||
ctx.alloc_reg();
|
||||
ctx.count_instr(); // STORE_VAR
|
||||
if let Some(elem) = elem {
|
||||
// Mirror emit_array_assignment: an element may be a default (`[a = 1]`) or a
|
||||
// nested pattern (`[[a], b]`), not just an identifier — recurse through the
|
||||
// shared dispatch instead of hard-coding one STORE_VAR.
|
||||
self.count_assignment_maybe_default(elem, ctx);
|
||||
}
|
||||
}
|
||||
if let Some(rest) = &ap.rest {
|
||||
|
||||
@@ -40,9 +40,14 @@ impl Compiler {
|
||||
ctx.labels.label_map.insert(catch_label, ctx.projected_pc);
|
||||
if let Some(catch) = &stmt.handler {
|
||||
ctx.push_scope();
|
||||
if let Some(_param) = &catch.param {
|
||||
if let Some(param) = &catch.param {
|
||||
// Mirror the emitter: the catch register is always allocated, but STORE_VAR is
|
||||
// emitted only for an identifier binding — a destructuring catch param emits no
|
||||
// store (that binding form is not implemented yet).
|
||||
ctx.alloc_reg();
|
||||
ctx.projected_pc += 1; // STORE_VAR
|
||||
if let oxide_parser::BindingPattern::BindingIdentifier(_) = ¶m.pattern {
|
||||
ctx.projected_pc += 1; // STORE_VAR
|
||||
}
|
||||
}
|
||||
for cs in &catch.body.body {
|
||||
self.count_statement(cs, ctx);
|
||||
|
||||
@@ -41,7 +41,8 @@ impl Compiler {
|
||||
self.count_expression(init_expr, ctx);
|
||||
self.count_binding_pattern(&d.id, ctx);
|
||||
} else {
|
||||
ctx.alloc_reg();
|
||||
ctx.alloc_reg(); // tmp holding undefined
|
||||
ctx.alloc_reg(); // var register
|
||||
ctx.count_words(2); // LOAD_CONST(undefined) + STORE_VAR
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user