1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 20:42:21 +02:00

Extensive runtime refactor to reduce generated executable sizes

This commit is contained in:
Brian Fiete 2024-03-16 07:23:29 -04:00
parent 4e750a7e1a
commit ddd9b1b218
74 changed files with 2514 additions and 717 deletions

View file

@ -110,13 +110,13 @@ namespace System
[AttributeUsage(.Method | .Constructor | .Invocation)]
public struct InlineAttribute : Attribute
{
}
[AttributeUsage(.Invocation)]
public struct UnboundAttribute : Attribute
{
}
[AttributeUsage(.Class | .Struct | .Interface | .Method | .Constructor)]
@ -136,13 +136,13 @@ namespace System
[AttributeUsage(.MemberAccess | .Alloc)]
public struct FriendAttribute : Attribute
{
}
[AttributeUsage(.MemberAccess)]
public struct NoExtensionAttribute : Attribute
{
}
[AttributeUsage(.Block)]
@ -161,13 +161,13 @@ namespace System
[AttributeUsage(.Method | .Class | .Struct | .Enum)]
public struct OptimizeAttribute : Attribute
{
}
[AttributeUsage(.Method | .Class | .Struct | .Enum)]
public struct UseLLVMAttribute : Attribute
{
}
[AttributeUsage(.Method /*2*/ | .StaticField)]
@ -344,7 +344,7 @@ namespace System
[AttributeUsage(.Enum)]
public struct AllowDuplicatesAttribute : Attribute
{
}
[AttributeUsage(.Class | .Struct)]
@ -409,7 +409,7 @@ namespace System
public struct ExportAttribute : Attribute
{
}
[AttributeUsage(.StaticField | .Field, .NotInherited)]
@ -420,6 +420,12 @@ namespace System
}
}
[AttributeUsage(.MemberAccess)]
public struct NoStaticCtorAttribute : Attribute
{
}
/// The [Checked] attribute is used to mark a method or a method invocation as being "checked", meaning
/// that the method applies extra runtime checks such as bounds checking or other parameter or state validation.
[AttributeUsage(.Invocation | .Method | .Property)]

View file

@ -92,8 +92,15 @@ namespace System
[CallingConvention(.Cdecl)]
public static extern void Dbg_RawFree(void* ptr);
[CallingConvention(.Cdecl)]
static extern void Shutdown_Internal();
[CallingConvention(.Cdecl), AlwaysInclude]
static extern void Shutdown();
static void Shutdown()
{
Shutdown_Internal();
}
[CallingConvention(.Cdecl)]
static extern void Test_Init(char8* testData);
[CallingConvention(.Cdecl)]

View file

@ -48,63 +48,122 @@ namespace System
class Object : IHashable
{
#if BF_ENABLE_OBJECT_DEBUG_FLAGS
int mClassVData;
int mDbgAllocInfo;
#else
ClassVData* mClassVData;
#endif
public virtual ~this()
{
#if BF_ENABLE_OBJECT_DEBUG_FLAGS
int mClassVData;
int mDbgAllocInfo;
#else
ClassVData* mClassVData;
#endif
public virtual ~this()
{
#if BF_ENABLE_OBJECT_DEBUG_FLAGS
mClassVData = ((mClassVData & ~0x08) | 0x80);
#endif
}
#endif
}
int IHashable.GetHashCode()
{
return (int)(void*)this;
}
public Type GetType()
{
Type type;
#if BF_ENABLE_OBJECT_DEBUG_FLAGS
ClassVData* maskedVData = (ClassVData*)(void*)(mClassVData & ~(int)0xFF);
type = maskedVData.mType;
#else
type = mClassVData.mType;
#endif
if ((type.[Friend]mTypeFlags & TypeFlags.Boxed) != 0)
{
//int32 underlyingType = (int32)((TypeInstance)type).mUnderlyingType;
type = Type.[Friend]GetType(((TypeInstance)type).[Friend]mUnderlyingType);
}
[NoShow]
int32 GetFlags()
{
return (int32)mClassVData & 0xFF;
}
[DisableObjectAccessChecks, NoShow]
public bool IsDeleted()
{
return (int32)mClassVData & 0x80 != 0;
}
#else
[SkipCall]
public bool IsDeleted()
{
return false;
}
#endif
extern Type Comptime_GetType();
public Type GetType()
{
if (Compiler.IsComptime)
return Comptime_GetType();
ClassVData* classVData;
#if BF_ENABLE_OBJECT_DEBUG_FLAGS
classVData = (ClassVData*)(void*)(mClassVData & ~(int)0xFF);
#else
classVData = mClassVData;
#endif
#if BF_32_BIT
Type type = Type.[Friend]GetType_((.)(classVData.mType2));
#else
Type type = Type.[Friend]GetType_((.)(classVData.mType >> 32));
#endif
return type;
}
TypeId GetTypeId()
{
ClassVData* classVData;
#if BF_ENABLE_OBJECT_DEBUG_FLAGS
classVData = (ClassVData*)(void*)(mClassVData & ~(int)0xFF);
#else
classVData = mClassVData;
#endif
#if BF_32_BIT
return (.)classVData.mType2;
#else
return (.)(classVData.mType >> 32);
#endif
}
[NoShow]
Type RawGetType()
{
Type type;
if (Compiler.IsComptime)
return Comptime_GetType();
ClassVData* classVData;
#if BF_ENABLE_OBJECT_DEBUG_FLAGS
ClassVData* maskedVData = (ClassVData*)(void*)(mClassVData & ~(int)0xFF);
type = maskedVData.mType;
#else
type = mClassVData.mType;
#endif
return type;
classVData = (ClassVData*)(void*)(mClassVData & ~(int)0xFF);
#else
classVData = mClassVData;
#endif
#if BF_32_BIT
Type type = Type.[Friend]GetType_((.)(classVData.mType));
#else
Type type = Type.[Friend]GetType_((.)(classVData.mType & 0xFFFFFFFF));
#endif
return type;
}
TypeId RawGetTypeId()
{
ClassVData* classVData;
#if BF_ENABLE_OBJECT_DEBUG_FLAGS
classVData = (ClassVData*)(void*)(mClassVData & ~(int)0xFF);
#else
classVData = mClassVData;
#endif
#if BF_32_BIT
return (.)classVData.mType;
#else
return (.)(classVData.mType & 0xFFFFFFFF);
#endif
}
#if BF_DYNAMIC_CAST_CHECK || BF_ENABLE_REALTIME_LEAK_CHECK
[NoShow]
public virtual Object DynamicCastToTypeId(int32 typeId)
{
if (typeId == (int32)RawGetType().[Friend]mTypeId)
return this;
return null;
}
public virtual Object DynamicCastToTypeId(int32 typeId)
{
if (typeId == (.)RawGetTypeId())
return this;
return null;
}
[NoShow]
public virtual Object DynamicCastToInterface(int32 typeId)
@ -112,13 +171,18 @@ namespace System
return null;
}
#endif
int IHashable.GetHashCode()
{
return (int)Internal.UnsafeCastToPtr(this);
}
public virtual void ToString(String strBuffer)
{
//strBuffer.Set(stack string(GetType().mName));
RawGetType().GetName(strBuffer);
strBuffer.Append("Type#");
GetTypeId().ToString(strBuffer);
}
/*public virtual int GetHashCode()
{
return (int)(intptr)(void*)this;
@ -138,12 +202,12 @@ namespace System
obj.ToString(strBuffer);
}
}
interface IResult<T>
{
T GetBaseResult();
}
struct ValueType
{
public static extern bool Equals<T>(T val1, T val2);
@ -197,7 +261,7 @@ namespace System
{
return CSize;
}
}
}
public explicit static operator T[CSize] (Self val)
{
@ -226,11 +290,11 @@ namespace System
struct Void : void
{
}
struct Boolean : bool
{
{
}
struct Char8 : char8
{
public bool IsWhiteSpace
@ -248,7 +312,7 @@ namespace System
struct Char16 : char16
{
}
struct Char32 : char32
@ -258,15 +322,15 @@ namespace System
get;
}
}
struct Int8 : int8
{
{
}
struct UInt8 : uint8
{
{
}
struct Int16 : int16, IOpComparable, IIsNaN
{
public static int operator<=>(Int16 a, Int16 b)
@ -283,11 +347,11 @@ namespace System
}
}
}
struct UInt16 : uint16
{
{
}
struct UInt32 : uint32, IHashable, IOpComparable, IIsNaN, IOpNegatable
{
public const int32 MaxValue = 0x7FFFFFFF;
@ -307,7 +371,7 @@ namespace System
public this()
{
}
bool IIsNaN.IsNaN
@ -324,12 +388,12 @@ namespace System
return (.)this;
}
}
struct Int64 : int64
{
public const int64 MaxValue = 0x7FFFFFFFFFFFFFFFL;
public const int64 MinValue = -0x8000000000000000L;
public override void ToString(String strBuffer)
{
// Dumb, make better.
@ -344,11 +408,11 @@ namespace System
}
if (charIdx == 14)
strChars[charIdx--] = '0';
char8* charPtr = &strChars[charIdx + 1];
char8* charPtr = &strChars[charIdx + 1];
strBuffer.Append(scope:: String(charPtr));
}
}
struct UInt64 : uint64
{
}
@ -405,7 +469,7 @@ namespace System
}
struct UInt : uint, IOpComparable, IIsNaN
{
{
public static int operator<=>(UInt a, UInt b)
{
return (uint)a <=> (uint)b;
@ -469,11 +533,11 @@ namespace System
}
if (charIdx == 14)
strChars[charIdx--] = '0';
char8* charPtr = &strChars[charIdx + 1];
char8* charPtr = &strChars[charIdx + 1];
strBuffer.Append(scope:: String(charPtr));
}
}
struct Enum
{
public static Result<T> Parse<T>(String str) where T : Enum
@ -528,7 +592,7 @@ namespace System
{
public int64 mMethodId;
public DeferredCall* mNext;
public void Cancel() mut
{
mMethodId = 0;

View file

@ -7,7 +7,10 @@ namespace System
{
struct ClassVData
{
public Type mType;
public int mType;
#if BF_32_BIT
public int mType2;
#endif
// The rest of this structured is generated by the compiler,
// including the vtable and interface slots
}
@ -757,6 +760,7 @@ namespace System.Reflection
public int32 mCustomAttributesIdx;
}
[CRepr, AlwaysInclude]
public struct InterfaceData
{
public TypeId mInterfaceType;