refactor: 拆分 class 相关编译逻辑
This commit is contained in:
@@ -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))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user