refactor: 拆分 class 相关编译逻辑

This commit is contained in:
爱特每羊队
2026-07-05 19:13:58 +08:00
parent 13cf9127e3
commit 3389fe40ef
8 changed files with 290 additions and 219 deletions
+24
View File
@@ -0,0 +1,24 @@
use crate::compiler::{CompileCtx, Compiler};
impl Compiler {
pub(crate) fn count_class_header(&self, class: &oxide_parser::Class, ctx: &mut CompileCtx) {
ctx.alloc_reg();
ctx.alloc_reg();
if let Some(super_class) = &class.super_class {
self.count_expression(super_class, ctx);
}
}
pub(crate) fn emit_class_header(
&self, class: &oxide_parser::Class, ctx: &mut CompileCtx,
) -> Result<(u8, u8, Option<u8>), String> {
let ctor_reg = ctx.alloc_reg();
let proto_reg = ctx.alloc_reg();
let super_reg = if let Some(super_expr) = &class.super_class {
Some(self.emit_expression(super_expr, ctx)?)
} else {
None
};
Ok((ctor_reg, proto_reg, super_reg))
}
}