feat: 实现控制流语句并优化类型解析

- 新增了 ReturnStmt、BreakStmt 和 ContinueStmt 结构,以支持 AST 中的控制流。
- 引入了 TypeInfo 和 TypeContext 以实现更好的类型管理和解析。
- 对分析器进行了增强,能够处理函数定义和返回语句,包括类型检查和错误处理。
- 更新了编译器和解析器以适应新的控制流语句和类型解析逻辑。
- 重构了现有代码以提高清晰度和可维护性,包括对表达式和语句中的类型处理的更改。
- 删除了过时的 String 和 Struct 定义,代之以 StringObject 和 StructObject 以实现更好的对象表示。
This commit is contained in:
2026-02-28 20:42:15 +08:00
parent bb23ddf9fa
commit 1fe9ccf7ea
18 changed files with 642 additions and 137 deletions

View File

@@ -0,0 +1,54 @@
/*!
@file src/Object/StructObject.hpp
@brief 结构体类型 StructObject 定义
@author PuqiAR (im@puqiar.top)
@date 2026-02-19
*/
#pragma once
#include <Ast/Operator.hpp>
#include <Object/ObjectBase.hpp>
namespace Fig
{
/*
// Total 24 bytes size
struct Object
{
Object *next; // 8 bytes: gc链表
Struct *klass; // 8 bytes: 一切皆对象,父类指针
ObjectType type; // 1 byte : 类型
bool isMarked = false; // 1 byte : gc标记
// + 6 bytes padding
};
*/
struct StructObject final : public Object
{
String name; // 元信息(仅供调试/打印/反射)
// 内存布局信息
std::uint8_t fieldCount;
Object *operators[GetOperatorsSize()];
/*
运算符重载nullptr代表无重载
一般为 NativeFunction / Function
排列:
[unary operators ]( binary operators]
0 - UnaryOperators::Count BinaryOperators::Count
*/
Object *GetUnaryOperator(UnaryOperator _op)
{
std::uint8_t idx = static_cast<std::uint8_t>(_op);
return operators[idx];
}
Object *GetBinaryOperator(BinaryOperator _op)
{
std::uint16_t idx = static_cast<std::uint8_t>(UnaryOperator::Count) + static_cast<std::uint8_t>(_op);
return operators[idx];
}
};
}; // namespace Fig