refactor: 完成语法域入口点迁移,收紧内部方法可见性

This commit is contained in:
2026-06-25 21:53:26 +08:00
parent f7bcfd3846
commit 804a516e38
33 changed files with 403 additions and 222 deletions
@@ -1,7 +1,7 @@
use super::*;
impl Compiler {
pub(in crate::emitter) fn emit_arrow_function_expression(
fn emit_arrow_function_expression(
&self, arrow: &oxide_parser::ArrowFunctionExpression, ctx: &mut CompileCtx,
) -> Result<u8, String> {
// Rest params not yet supported
@@ -42,9 +42,7 @@ impl Compiler {
Ok(r)
}
pub(in crate::emitter) fn emit_function_expression(
&self, fe: &oxide_parser::Function, ctx: &mut CompileCtx,
) -> Result<u8, String> {
fn emit_function_expression(&self, fe: &oxide_parser::Function, ctx: &mut CompileCtx) -> Result<u8, String> {
// FunctionExpression: compile body, emit LOAD_CONST(BytecodeFunc)
let mut param_names = Vec::new();
for (idx, param) in fe.params.items.iter().enumerate() {
@@ -76,13 +74,11 @@ impl Compiler {
Ok(r)
}
pub(in crate::emitter) fn emit_class_expression(&self, class: &Class, ctx: &mut CompileCtx) -> Result<u8, String> {
fn emit_class_expression(&self, class: &Class, ctx: &mut CompileCtx) -> Result<u8, String> {
self.emit_class(class, ctx)
}
pub(in crate::emitter) fn emit_new_expression(
&self, ne: &oxide_parser::NewExpression, ctx: &mut CompileCtx,
) -> Result<u8, String> {
fn emit_new_expression(&self, ne: &oxide_parser::NewExpression, ctx: &mut CompileCtx) -> Result<u8, String> {
let constructor_reg = self.emit_expression(&ne.callee, ctx)?;
let mut arg_regs = Vec::new();
for arg in &ne.arguments {
@@ -96,4 +92,16 @@ impl Compiler {
ctx.emit(arg_regs.len() as u32);
Ok(r)
}
pub(in crate::emitter) fn emit_function_domain(
&self, expr: &Expression, ctx: &mut CompileCtx,
) -> Result<u8, String> {
match expr {
Expression::ArrowFunctionExpression(arrow) => self.emit_arrow_function_expression(arrow, ctx),
Expression::FunctionExpression(fe) => self.emit_function_expression(fe, ctx),
Expression::ClassExpression(class) => self.emit_class_expression(class, ctx),
Expression::NewExpression(ne) => self.emit_new_expression(ne, ctx),
_ => self.emit_unsupported_expression(expr, ctx),
}
}
}