mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-21 01:18:02 +02:00
Support System.Compiler values in comptime, SetReturnType, Enum helpers
This commit is contained in:
parent
0e86b5c49d
commit
2a55b5c7bb
14 changed files with 341 additions and 63 deletions
|
@ -259,6 +259,9 @@ namespace System
|
|||
[LinkName("#CallerExpression")]
|
||||
public static extern String[0x00FFFFFF] CallerExpression;
|
||||
|
||||
[LinkName("#OrigCalleeType")]
|
||||
public static extern Type OrigCalleeType;
|
||||
|
||||
[LinkName("#ProjectName")]
|
||||
public static extern String ProjectName;
|
||||
|
||||
|
@ -287,6 +290,7 @@ namespace System
|
|||
Runtime.FatalError("Assert failed");
|
||||
}
|
||||
|
||||
static extern void Comptime_SetReturnType(int32 typeId);
|
||||
static extern void* Comptime_MethodBuilder_EmitStr(void* native, StringView str);
|
||||
static extern void* Comptime_CreateMethod(int32 typeId, StringView methodName, Type returnType, MethodFlags methodFlags);
|
||||
static extern void Comptime_EmitTypeBody(int32 typeId, StringView text);
|
||||
|
@ -309,6 +313,12 @@ namespace System
|
|||
Comptime_EmitTypeBody((.)owner.TypeId, text);
|
||||
}
|
||||
|
||||
[Comptime(OnlyFromComptime=true)]
|
||||
public static void SetReturnType(Type type)
|
||||
{
|
||||
Comptime_SetReturnType((.)type.TypeId);
|
||||
}
|
||||
|
||||
[Comptime(OnlyFromComptime=true)]
|
||||
public static void EmitAddInterface(Type owner, Type iface)
|
||||
{
|
||||
|
|
|
@ -5,6 +5,67 @@ namespace System
|
|||
{
|
||||
struct Enum
|
||||
{
|
||||
public static int Count
|
||||
{
|
||||
[Comptime(ConstEval=true)]
|
||||
get
|
||||
{
|
||||
int count = 0;
|
||||
for (var field in Compiler.OrigCalleeType.GetFields())
|
||||
{
|
||||
if (field.IsEnumCase)
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
public static var MinValue
|
||||
{
|
||||
[Comptime(ConstEval=true)]
|
||||
get
|
||||
{
|
||||
Compiler.SetReturnType(Compiler.OrigCalleeType);
|
||||
|
||||
int? minValue = null;
|
||||
for (var field in Compiler.OrigCalleeType.GetFields())
|
||||
{
|
||||
if (field.IsEnumCase)
|
||||
{
|
||||
if (minValue == null)
|
||||
minValue = field.[Friend]mFieldData.mData;
|
||||
else
|
||||
minValue = Math.Min(minValue.Value, field.[Friend]mFieldData.mData);
|
||||
}
|
||||
}
|
||||
return minValue.ValueOrDefault;
|
||||
}
|
||||
}
|
||||
|
||||
public static var MaxValue
|
||||
{
|
||||
[Comptime(ConstEval=true)]
|
||||
get
|
||||
{
|
||||
Compiler.SetReturnType(Compiler.OrigCalleeType);
|
||||
|
||||
int? maxValue = null;
|
||||
for (var field in Compiler.OrigCalleeType.GetFields())
|
||||
{
|
||||
if (field.IsEnumCase)
|
||||
{
|
||||
if (maxValue == null)
|
||||
maxValue = field.[Friend]mFieldData.mData;
|
||||
else
|
||||
maxValue = Math.Max(maxValue.Value, field.[Friend]mFieldData.mData);
|
||||
}
|
||||
}
|
||||
if (maxValue == null)
|
||||
return -1;
|
||||
return maxValue.ValueOrDefault;
|
||||
}
|
||||
}
|
||||
|
||||
public static void EnumToString(Type type, String strBuffer, int64 iVal)
|
||||
{
|
||||
for (var field in type.GetFields())
|
||||
|
|
|
@ -24,6 +24,7 @@ namespace System.Reflection
|
|||
public int32 MemberOffset => (int32)mFieldData.mData;
|
||||
public Type FieldType => Type.[Friend]GetType(mFieldData.mFieldTypeId);
|
||||
public bool IsConst => mFieldData.mFlags.HasFlag(.Const);
|
||||
public bool IsEnumCase => mFieldData.mFlags.HasFlag(.EnumCase);
|
||||
public bool IsReadOnly => mFieldData.mFlags.HasFlag(.ReadOnly);
|
||||
public bool IsStatic => mFieldData.mFlags.HasFlag(.Static);
|
||||
public bool IsPublic => (mFieldData.mFlags & .FieldAccessMask) == .Public;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue