refactor: 完成语法域入口点迁移,收紧内部方法可见性
This commit is contained in:
@@ -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),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user