refactor: 完成语法域入口点迁移,收紧内部方法可见性

This commit is contained in:
爱特每羊队
2026-06-25 21:53:26 +08:00
parent db0444dabd
commit 3596fc3430
33 changed files with 403 additions and 222 deletions
@@ -1,9 +1,7 @@
use super::*;
impl Compiler {
pub(in crate::counter) fn count_while_statement(
&self, stmt: &oxide_parser::WhileStatement<'_>, ctx: &mut CompileCtx,
) {
fn count_while_statement(&self, stmt: &oxide_parser::WhileStatement<'_>, ctx: &mut CompileCtx) {
let id = ctx.next_label_id();
let start_label = Label::WhileStart(id);
let end_label = Label::WhileEnd(id);
@@ -16,9 +14,7 @@ impl Compiler {
ctx.labels.label_map.insert(end_label, ctx.projected_pc);
}
pub(in crate::counter) fn count_do_while_statement(
&self, stmt: &oxide_parser::DoWhileStatement<'_>, ctx: &mut CompileCtx,
) {
fn count_do_while_statement(&self, stmt: &oxide_parser::DoWhileStatement<'_>, ctx: &mut CompileCtx) {
let id = ctx.next_label_id();
let start_label = Label::DoWhileStart(id);
let end_label = Label::DoWhileEnd(id);
@@ -30,7 +26,7 @@ impl Compiler {
ctx.labels.label_map.insert(end_label, ctx.projected_pc);
}
pub(in crate::counter) fn count_for_statement(&self, stmt: &oxide_parser::ForStatement<'_>, ctx: &mut CompileCtx) {
fn count_for_statement(&self, stmt: &oxide_parser::ForStatement<'_>, ctx: &mut CompileCtx) {
let id = ctx.next_label_id();
let start_label = Label::ForStart(id);
let update_label = Label::ForUpdate(id);
@@ -65,9 +61,7 @@ impl Compiler {
ctx.labels.label_map.insert(end_label, ctx.projected_pc);
}
pub(in crate::counter) fn count_for_in_statement(
&self, stmt: &oxide_parser::ForInStatement<'_>, ctx: &mut CompileCtx,
) {
fn count_for_in_statement(&self, stmt: &oxide_parser::ForInStatement<'_>, ctx: &mut CompileCtx) {
let id = ctx.next_label_id();
let start_label = Label::ForInStart(id);
let end_label = Label::ForInEnd(id);
@@ -102,9 +96,7 @@ impl Compiler {
ctx.count_instr(); // FOR_IN_CLEANUP
}
pub(in crate::counter) fn count_for_of_statement(
&self, stmt: &oxide_parser::ForOfStatement<'_>, ctx: &mut CompileCtx,
) {
fn count_for_of_statement(&self, stmt: &oxide_parser::ForOfStatement<'_>, ctx: &mut CompileCtx) {
let id = ctx.next_label_id();
let start_label = Label::ForOfStart(id);
let end_label = Label::ForOfEnd(id);
@@ -140,4 +132,15 @@ impl Compiler {
ctx.labels.label_map.insert(end_label, ctx.projected_pc);
ctx.count_instr(); // FOR_OF_CLOSE
}
pub(in crate::counter) fn count_iteration_domain(&self, stmt: &Statement, ctx: &mut CompileCtx) {
match stmt {
Statement::WhileStatement(wh) => self.count_while_statement(wh, ctx),
Statement::DoWhileStatement(dw) => self.count_do_while_statement(dw, ctx),
Statement::ForStatement(fr) => self.count_for_statement(fr, ctx),
Statement::ForInStatement(fi) => self.count_for_in_statement(fi, ctx),
Statement::ForOfStatement(fo) => self.count_for_of_statement(fo, ctx),
_ => {}
}
}
}