feat: 实现 SequenceExpression + 带标签 break/continue + EmptyStatement
This commit is contained in:
@@ -23,4 +23,27 @@ impl Compiler {
|
||||
pub(in crate::counter) fn count_continue_statement(&self, ctx: &mut CompileCtx) {
|
||||
ctx.projected_pc += 1; // JMP
|
||||
}
|
||||
|
||||
pub(in crate::counter) fn count_labeled_statement(
|
||||
&self, stmt: &oxide_parser::LabeledStatement<'_>, ctx: &mut CompileCtx,
|
||||
) {
|
||||
let body_is_loop = matches!(
|
||||
stmt.body,
|
||||
Statement::WhileStatement(_)
|
||||
| Statement::DoWhileStatement(_)
|
||||
| Statement::ForStatement(_)
|
||||
| Statement::ForInStatement(_)
|
||||
| Statement::ForOfStatement(_)
|
||||
);
|
||||
if body_is_loop {
|
||||
// Loop body owns its labels; labeled break/continue reuse them.
|
||||
self.count_statement(&stmt.body, ctx);
|
||||
} else {
|
||||
// Non-loop label: consume one id (parity with emit) and place the
|
||||
// LabeledEnd target right after the body for `break label`.
|
||||
let id = ctx.next_label_id();
|
||||
self.count_statement(&stmt.body, ctx);
|
||||
ctx.label_map.insert(Label::LabeledEnd(id), ctx.projected_pc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ impl Compiler {
|
||||
Statement::ClassDeclaration(class) => self.count_class_declaration(class, ctx),
|
||||
Statement::ThrowStatement(ts) => self.count_throw_statement(ts, ctx),
|
||||
Statement::TryStatement(ts) => self.count_try_statement(ts, ctx),
|
||||
Statement::LabeledStatement(ls) => self.count_labeled_statement(ls, ctx),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user