feat: 为 Array/String 原型方法添加入口和错误路径结构化日志,编译器添加阶段边界日志

This commit is contained in:
2026-06-26 21:24:18 +08:00
parent fc59505116
commit f2002d6bae
3 changed files with 229 additions and 36 deletions
+5
View File
@@ -830,12 +830,14 @@ impl Compiler {
}
pub fn compile(&self, program: &oxide_parser::Program) -> Result<CompiledModule, String> {
crate::compiler_debug!("compile: starting...");
let mut ctx = CompileCtx::new();
ctx.pre_register_builtins();
for stmt in &program.body {
self.count_statement(stmt, &mut ctx);
}
crate::compiler_debug!("counter: {} instructions estimated", ctx.projected_pc);
ctx.max_regs = ctx.max_regs.max(1);
ctx.reg_overflow = false;
ctx.reset_regs();
@@ -859,6 +861,7 @@ impl Compiler {
None => last_result = None,
}
}
crate::compiler_debug!("emitter: {} bytes emitted", ctx.bytecode.len());
if let Some(r) = last_result {
ctx.emit(opcode::encode(OpCode::LOAD_VAR, 0, r, 0));
@@ -883,6 +886,8 @@ impl Compiler {
return Err("RangeError: jump offset out of range".into());
}
crate::compiler_debug!("compile: done, {} instructions, {} constants", ctx.bytecode.len(), ctx.constants.len());
Ok(CompiledModule {
bytecode: ctx.bytecode,
constants: ctx.constants,