refactor(compiler): remove class count helpers

This commit is contained in:
爱特每羊队
2026-08-05 01:41:51 +08:00
parent fd4172203e
commit 0f78f341fa
12 changed files with 2 additions and 323 deletions
-63
View File
@@ -170,10 +170,6 @@ pub(crate) struct CompileCtx {
pub(crate) static_block_this_reg: Option<u8>,
pub(crate) after_super_insert: Option<Vec<opcode::Instr>>,
pub(crate) after_super_inserted: bool,
/// Count-pass mirror of `after_super_insert`: the instruction count of a derived
/// constructor's instance-field code, added at the super() call site during body
/// counting so projected_pc matches where the emit pass splices the field bytecode.
pub(crate) after_super_count_words: Option<usize>,
pub(crate) current_upvalue_captures: Vec<UpvalueCapture>,
/// Set when alloc_reg() overflows into the reserved this/new.target range (≥254).
/// Checked after each emit phase to produce a compile error rather than silent corruption.
@@ -250,7 +246,6 @@ impl CompileCtx {
static_block_this_reg: None,
after_super_insert: None,
after_super_inserted: false,
after_super_count_words: None,
current_upvalue_captures: Vec::new(),
reg_overflow: false,
const_overflow: false,
@@ -342,50 +337,6 @@ impl CompileCtx {
});
}
pub(crate) fn count_word(&mut self) {
self.projected_pc += 1;
}
pub(crate) fn count_words(&mut self, words: usize) {
self.projected_pc += words;
}
pub(crate) fn count_instr(&mut self) {
self.count_word();
}
pub(crate) fn count_instr_with_ext(&mut self, ext_words: usize) {
self.count_words(1 + ext_words);
}
pub(crate) fn count_load_const(&mut self) {
self.alloc_reg();
self.count_instr();
}
pub(crate) fn count_load_var(&mut self) {
self.alloc_reg();
self.count_instr();
}
pub(crate) fn count_ic_instr_with_ext(&mut self) {
self.count_instr_with_ext(3);
}
pub(crate) fn count_call_instr_with_arg_ext(&mut self) {
self.count_instr_with_ext(1);
}
pub(crate) fn count_define_accessor(&mut self) {
self.count_instr_with_ext(1);
}
pub(crate) fn count_private_access(&mut self) {
self.count_load_const();
self.alloc_reg();
self.count_instr();
}
pub(crate) fn alloc_reg(&mut self) -> u8 {
let r = self.next_reg;
// Registers 254 (this) and 255 (new.target) are reserved by the VM.
@@ -1273,20 +1224,6 @@ impl Compiler {
})
}
pub(crate) fn count_statement(&self, stmt: &Statement, ctx: &mut CompileCtx) {
let _ = (stmt, ctx);
}
pub(crate) fn count_expression(&self, expr: &Expression, ctx: &mut CompileCtx) {
match expr {
Expression::CallExpression(_) | Expression::NewExpression(_) => self.count_call_domain(expr, ctx),
Expression::ArrowFunctionExpression(_)
| Expression::FunctionExpression(_)
| Expression::ClassExpression(_) => self.count_function_domain(expr, ctx),
_ => {}
}
}
pub(crate) fn emit_statement(&self, stmt: &Statement, ctx: &mut CompileCtx) -> Result<Option<u8>, String> {
match stmt {
Statement::ExpressionStatement(_) | Statement::ReturnStatement(_) | Statement::EmptyStatement(_) => {