qamp/Qrakhen.Qamp.Core/Values/Objects/Obj.cs

43 lines
1.1 KiB
C#

using Qrakhen.Qamp.Core.Collections;
namespace Qrakhen.Qamp.Core.Values.Objects;
public class ObjTable(int size = 4096)
{
public static readonly ObjTable Global = new ObjTable(4096);
private readonly Table<Obj> _table = new Table<Obj>(size);
public IEnumerable<KeyValuePair<Address, Obj>> Entries => _table;
public Obj? Get(Address address) => _table[address];
public T? Get<T>(Address address) where T : Obj => _table[address] as T;
public bool TryGet(Address address, out Obj? obj) => _table.TryGet(address, out obj);
public void Free(Address address) => _table.Free(address);
public Address Register(Obj obj) => _table.Add(obj);
}
public class Obj : ITypedValue
{
internal bool __GC_Marked = false;
internal int __GC_Count = 1;
internal readonly Address __Address; // unsure lol
public readonly ValueType Type;
public ValueType ValueType => Type;
public Obj(ValueType type)
{
Type = type;
__Address = ObjTable.Global.Register(this);
}
public static Value Create(Obj obj)
{
return new Value(Ptr.Create(obj));
}
public override string ToString() => "Obj<undefined>";
}