feat: 重构编译器以支持函数定义和调用,添加新的字节码以支持函数调用
另外,我很高兴地宣布,fib(40) 递归法 在我的平台, i5-13490f,只需要 6600ms, fib(30) 56ms 这是历史性的一刻!
This commit is contained in:
@@ -9,9 +9,8 @@
|
||||
|
||||
namespace Fig
|
||||
{
|
||||
Result<Proto *, Error> Compiler::Compile(Program *program)
|
||||
Result<CompiledModule *, Error> Compiler::Compile(Program *program)
|
||||
{
|
||||
current->proto = new Proto();
|
||||
current->freeReg = 0;
|
||||
|
||||
for (Stmt *stmt : program->nodes)
|
||||
@@ -22,7 +21,16 @@ namespace Fig
|
||||
return std::unexpected(result.error());
|
||||
}
|
||||
}
|
||||
|
||||
if (mainFuncIndex != -1)
|
||||
{
|
||||
std::uint8_t baseReg = AllocReg();
|
||||
Emit(Op::iABC(OpCode::FastCall, mainFuncIndex, baseReg, 0));
|
||||
}
|
||||
|
||||
Emit(Op::iABC(OpCode::Exit, 0, 0, 0)); // 一定要退出,这是虚拟机退出信号,否则ub
|
||||
return current->proto;
|
||||
|
||||
CompiledModule *compiledModule = new CompiledModule(fileName, allProtos);
|
||||
return compiledModule;
|
||||
}
|
||||
}; // namespace Fig
|
||||
Reference in New Issue
Block a user