refactor: 移除语句跳转计数辅助

This commit is contained in:
2026-08-05 01:17:22 +08:00
parent dfc14cfce9
commit fd978b7ef8
9 changed files with 28 additions and 175 deletions
-27
View File
@@ -4,27 +4,6 @@ use oxide_bytecode::opcode::{self, OpCode};
use oxide_parser::Statement;
impl Compiler {
fn count_if_statement(&self, stmt: &oxide_parser::IfStatement<'_>, ctx: &mut CompileCtx) {
let id = ctx.next_label_id();
let else_label = Label::IfElse(id);
let end_label = Label::IfEnd(id);
self.count_expression(&stmt.test, ctx);
ctx.projected_pc += 1;
self.count_statement(&stmt.consequent, ctx);
ctx.alloc_reg();
ctx.projected_pc += 1;
if stmt.alternate.is_some() {
ctx.projected_pc += 1;
}
ctx.labels.label_map.insert(else_label, ctx.projected_pc);
if let Some(alt_stmt) = &stmt.alternate {
self.count_statement(alt_stmt, ctx);
ctx.projected_pc += 1;
}
ctx.labels.label_map.insert(end_label, ctx.projected_pc);
}
fn emit_if_statement(&self, stmt: &Statement, ctx: &mut CompileCtx) -> Result<Option<u8>, String> {
let Statement::IfStatement(ifs) = stmt else {
return Ok(None);
@@ -66,12 +45,6 @@ impl Compiler {
Ok(Some(result_reg))
}
pub(crate) fn count_control_domain(&self, stmt: &Statement, ctx: &mut CompileCtx) {
if let Statement::IfStatement(ifs) = stmt {
self.count_if_statement(ifs, ctx);
}
}
pub(crate) fn emit_control_domain(&self, stmt: &Statement, ctx: &mut CompileCtx) -> Result<Option<u8>, String> {
match stmt {
Statement::IfStatement(_) => self.emit_if_statement(stmt, ctx),