51a939ac45
- 去除了不再使用的结构,并更新了编译器以处理新的闭包语义。 - 改进了 Compiler,使其能够生成带有源位置跟踪的指令。 - 在 FunctionObject 和 VM 中引入了作用域变量管理,以支持动态闭包。 - 实现了使用标记-扫描(Mark-And-Sweep) (Tri-Color tracing) 算法的垃圾回收机制,包括对作用域变量的处理。 - 在 VM 中增加了函数加载和作用域变量检索的支持。 - 更新了对象模型,包括引入 InstanceObject 并改进内存管理。 - 添加了用于调试的全局变量打印功能。
55 lines
1.6 KiB
C++
55 lines
1.6 KiB
C++
/*!
|
|
@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
|