mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-25 11:11:11 +08:00
refactor: 移除语句跳转计数辅助
This commit is contained in:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user