feat: 重构编译器以支持函数定义和调用,添加新的字节码以支持函数调用

另外,我很高兴地宣布,fib(40) 递归法 在我的平台, i5-13490f,只需要 6600ms, fib(30) 56ms
这是历史性的一刻!
This commit is contained in:
2026-03-07 00:34:52 +08:00
parent 1fe9ccf7ea
commit 6dbecbbdc0
13 changed files with 477 additions and 127 deletions

View File

@@ -20,9 +20,17 @@ namespace Fig
enum class OpCode : std::uint8_t
{
Exit, // 结束运行
LoadK, // iABx 模式: R[A] = Constants[Bx]
Return, // iA 模式: 返回 R[A] 的值
Exit, // 结束运行
LoadK, // iABx 模式: R[A] = Constants[Bx]
LoadTrue, // iABC: R[A] = true
LoadFalse, // iABC: R[A] = false
LoadNull, // iABC: R[A] = null
FastCall, // iABC: A: ProtoIdx, B: 函数起始寄存器
Call, // 动态派发 iABC: A: 函数体对象寄存器 B: 函数起始寄存器
Return, // iABC 模式: 返回 R[A] 的值
LoadFn, // 惰性装修, iABx: R[A] = new FunctionObject...
Jmp, // iAsBx: ip += sBx 无条件跳转
JmpIfFalse, // iAsBx: 如果 R[A] 为假, ip += sBx