重构类型系统并改进诊断功能
- 更新了类型系统,新增了类型并优化了结构。 - 引入了基类型和派生类,用于函数、结构体和接口类型。 - 实现了类型上下文,用于管理内置类型和类型解析。 - 添加了诊断类,用于收集和报告警告和错误。 - 通过改进错误处理增强了虚拟机执行,以应对递归限制问题。 - 实现了反汇编器,将字节码转换为代码,以改善调试和分析。 - 添加了新的抽象语法树节点,用于成员表达式、对象初始化、接口和结构体定义。 - 引入了语义错误测试,包括重定义、未声明的变量和无效的结构字段。
This commit is contained in:
@@ -31,13 +31,20 @@ namespace Fig
|
||||
class VM
|
||||
{
|
||||
private:
|
||||
static constexpr unsigned int MAX_REGISTERS = 1024;
|
||||
static constexpr unsigned int MAX_REGISTERS = 1024;
|
||||
static constexpr unsigned int MAX_GLOBALS = 65536;
|
||||
static constexpr unsigned int MAX_RECURSION_DEPTH = 2233;
|
||||
|
||||
Instruction POISON_MAX_RECURSION_DEPTH_EXCEED_INST;
|
||||
|
||||
// 一次性分配
|
||||
Value registers[MAX_REGISTERS];
|
||||
Value globals[MAX_GLOBALS];
|
||||
|
||||
DynArray<CallFrame> frames;
|
||||
CallFrame frames[MAX_RECURSION_DEPTH];
|
||||
CallFrame *currentFrame;
|
||||
CallFrame *frameLimit;
|
||||
|
||||
public:
|
||||
VM()
|
||||
{
|
||||
@@ -45,27 +52,36 @@ namespace Fig
|
||||
{
|
||||
registers[i] = Value::GetNullInstance();
|
||||
}
|
||||
for (unsigned int i = 0; i < MAX_GLOBALS; ++i)
|
||||
{
|
||||
globals[i] = Value::GetNullInstance();
|
||||
}
|
||||
|
||||
currentFrame = frames;
|
||||
frameLimit = frames + MAX_RECURSION_DEPTH - 1;
|
||||
|
||||
POISON_MAX_RECURSION_DEPTH_EXCEED_INST =
|
||||
Op::iAsBx(OpCode::Exit_MaxRecursionDepthExceeded, 0, 0);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void pushFrame(Proto *proto, Value *base)
|
||||
[[nodiscard]]
|
||||
inline Instruction *pushFrame(Proto *proto, Value *base)
|
||||
{
|
||||
frames.push_back({
|
||||
proto,
|
||||
proto->code.data(),
|
||||
base
|
||||
});
|
||||
currentFrame = &frames.back();
|
||||
if (++currentFrame >= frameLimit) [[unlikely]] // 达到最大递归层数
|
||||
{
|
||||
POISON_MAX_RECURSION_DEPTH_EXCEED_INST =
|
||||
Op::iAsBx(OpCode::Exit_MaxRecursionDepthExceeded, 0, 0);
|
||||
return &POISON_MAX_RECURSION_DEPTH_EXCEED_INST;
|
||||
}
|
||||
|
||||
*currentFrame = CallFrame{proto, proto->code.data(), base};
|
||||
return currentFrame->ip;
|
||||
}
|
||||
|
||||
void popFrame()
|
||||
inline void popFrame()
|
||||
{
|
||||
frames.pop_back();
|
||||
if (!frames.empty())
|
||||
{
|
||||
currentFrame = &frames.back();
|
||||
}
|
||||
--currentFrame;
|
||||
}
|
||||
|
||||
inline OpCode decodeOpCode(Instruction inst)
|
||||
|
||||
Reference in New Issue
Block a user