mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-22 09:38:01 +02:00
Comptime updates, start of metaprogramming support
This commit is contained in:
parent
be1c099f19
commit
3bbf2d8313
43 changed files with 1562 additions and 885 deletions
|
@ -274,10 +274,36 @@ namespace System
|
|||
|
||||
}
|
||||
|
||||
[AttributeUsage(.Method | .Invocation)]
|
||||
[AttributeUsage(.Method)]
|
||||
public struct ComptimeAttribute : Attribute
|
||||
{
|
||||
public this()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public bool OnlyFromComptime
|
||||
{
|
||||
set
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public bool ConstEval
|
||||
{
|
||||
set
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage(.Invocation)]
|
||||
public struct ConstEvalAttribute : Attribute
|
||||
{
|
||||
public this()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage(.Method /*2*/)]
|
||||
|
|
|
@ -1,7 +1,38 @@
|
|||
using System.Reflection;
|
||||
namespace System
|
||||
{
|
||||
[AttributeUsage(.Method)]
|
||||
struct OnCompileAttribute : Attribute
|
||||
{
|
||||
public enum Kind
|
||||
{
|
||||
None,
|
||||
TypeInit,
|
||||
TypeDone
|
||||
}
|
||||
|
||||
public this(Kind kind)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
static class Compiler
|
||||
{
|
||||
public struct MethodBuilder
|
||||
{
|
||||
void* mNative;
|
||||
|
||||
public void Emit(String str)
|
||||
{
|
||||
Comptime_MethodBuilder_EmitStr(mNative, str);
|
||||
}
|
||||
|
||||
public void Emit(Type type)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[LinkName("#CallerLineNum")]
|
||||
public static extern int CallerLineNum;
|
||||
|
||||
|
@ -32,8 +63,8 @@ namespace System
|
|||
[LinkName("#TimeLocal")]
|
||||
public static extern String TimeLocal;
|
||||
|
||||
[LinkName("#IsConstEval")]
|
||||
public static extern bool IsConstEval;
|
||||
[LinkName("#IsComptime")]
|
||||
public static extern bool IsComptime;
|
||||
|
||||
[LinkName("#IsBuilding")]
|
||||
public static extern bool IsBuilding;
|
||||
|
@ -44,11 +75,39 @@ namespace System
|
|||
[LinkName("#CompileRev")]
|
||||
public static extern int32 CompileRev;
|
||||
|
||||
[ConstEval]
|
||||
[Comptime]
|
||||
public static void Assert(bool cond)
|
||||
{
|
||||
if (!cond)
|
||||
Runtime.FatalError("Assert failed");
|
||||
}
|
||||
|
||||
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_EmitDefinition(int32 typeId, StringView text);
|
||||
|
||||
[Comptime(OnlyFromComptime=true)]
|
||||
public static MethodBuilder CreateMethod(Type owner, StringView methodName, Type returnType, MethodFlags methodFlags)
|
||||
{
|
||||
MethodBuilder builder = .();
|
||||
builder.[Friend]mNative = Comptime_CreateMethod((.)owner.TypeId, methodName, returnType, methodFlags);
|
||||
return builder;
|
||||
}
|
||||
|
||||
[Comptime(OnlyFromComptime=true)]
|
||||
public static void EmitDefinition(Type owner, StringView text)
|
||||
{
|
||||
Comptime_EmitDefinition((.)owner.TypeId, text);
|
||||
}
|
||||
|
||||
interface IComptimeTypeApply
|
||||
{
|
||||
void ApplyToType(Type type);
|
||||
}
|
||||
|
||||
interface IComptimeMethodApply
|
||||
{
|
||||
void ApplyToMethod(Type type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ namespace System.Globalization
|
|||
{
|
||||
get
|
||||
{
|
||||
if (Compiler.IsConstEval)
|
||||
if (Compiler.IsComptime)
|
||||
return InitUserDefaultCulture();
|
||||
if (tlCurrentCulture == null)
|
||||
tlCurrentCulture = CultureInfo.DefaultThreadCurrentCulture ?? CultureInfo.UserDefaultCulture;
|
||||
|
|
|
@ -131,7 +131,7 @@ namespace System
|
|||
public static T* AllocRawArrayUnmarked<T>(int size)
|
||||
{
|
||||
#if BF_ENABLE_REALTIME_LEAK_CHECK
|
||||
if (Compiler.IsConstEval)
|
||||
if (Compiler.IsComptime)
|
||||
return new T[size]*(?);
|
||||
// We don't want to use the default mark function because the GC will mark the entire array,
|
||||
// whereas we have a custom marking routine because we only want to mark up to mSize
|
||||
|
|
|
@ -1235,7 +1235,7 @@ namespace System
|
|||
// _isCustomFormat, _specifierIsUpper, _specifier & _precision.
|
||||
this(CultureInfo cultureInfo)
|
||||
{
|
||||
if (Compiler.IsConstEval)
|
||||
if (Compiler.IsComptime)
|
||||
_cbuf = new char8[0];
|
||||
else
|
||||
_cbuf = sEmtpyBuf;
|
||||
|
|
|
@ -40,12 +40,12 @@ namespace System
|
|||
return false;
|
||||
}
|
||||
#endif
|
||||
extern Type ConstEval_GetType();
|
||||
extern Type Comptime_GetType();
|
||||
|
||||
public Type GetType()
|
||||
{
|
||||
if (Compiler.IsConstEval)
|
||||
return ConstEval_GetType();
|
||||
if (Compiler.IsComptime)
|
||||
return Comptime_GetType();
|
||||
|
||||
Type type;
|
||||
#if BF_ENABLE_OBJECT_DEBUG_FLAGS
|
||||
|
@ -65,8 +65,8 @@ namespace System
|
|||
[NoShow]
|
||||
Type RawGetType()
|
||||
{
|
||||
if (Compiler.IsConstEval)
|
||||
return ConstEval_GetType();
|
||||
if (Compiler.IsComptime)
|
||||
return Comptime_GetType();
|
||||
|
||||
Type type;
|
||||
#if BF_ENABLE_OBJECT_DEBUG_FLAGS
|
||||
|
|
|
@ -35,6 +35,11 @@ namespace System
|
|||
return .Ok(matched);
|
||||
}
|
||||
|
||||
public virtual Result<MethodInfo, MethodError> GetMethod(int methodIdx)
|
||||
{
|
||||
return .Err(.NoResults);
|
||||
}
|
||||
|
||||
public virtual Result<Object> CreateObject()
|
||||
{
|
||||
return .Err;
|
||||
|
@ -61,6 +66,13 @@ namespace System.Reflection
|
|||
return MethodInfo.Enumerator(this, bindingFlags);
|
||||
}
|
||||
|
||||
public override Result<MethodInfo, MethodError> GetMethod(int methodIdx)
|
||||
{
|
||||
if ((methodIdx < 0) || (methodIdx >= mMethodDataCount))
|
||||
return .Err(.NoResults);
|
||||
return MethodInfo(this, &mMethodDataPtr[methodIdx]);
|
||||
}
|
||||
|
||||
public override Result<Object> CreateObject()
|
||||
{
|
||||
if (mTypeClassVData == null)
|
||||
|
|
|
@ -471,19 +471,19 @@ namespace System
|
|||
return (int32)mTypeId;
|
||||
}
|
||||
|
||||
static extern Type ConstEval_GetTypeById(int32 typeId);
|
||||
static extern Type Comptime_GetTypeById(int32 typeId);
|
||||
|
||||
protected static Type GetType(TypeId typeId)
|
||||
{
|
||||
if (Compiler.IsConstEval)
|
||||
return ConstEval_GetTypeById((.)typeId);
|
||||
if (Compiler.IsComptime)
|
||||
return Comptime_GetTypeById((.)typeId);
|
||||
return sTypes[(int32)typeId];
|
||||
}
|
||||
|
||||
protected static Type GetType_(int32 typeId)
|
||||
{
|
||||
if (Compiler.IsConstEval)
|
||||
return ConstEval_GetTypeById(typeId);
|
||||
if (Compiler.IsComptime)
|
||||
return Comptime_GetTypeById(typeId);
|
||||
return sTypes[typeId];
|
||||
}
|
||||
|
||||
|
@ -547,6 +547,11 @@ namespace System
|
|||
return .Err;
|
||||
}
|
||||
|
||||
public virtual Result<FieldInfo> GetField(int idx)
|
||||
{
|
||||
return .Err;
|
||||
}
|
||||
|
||||
public virtual FieldInfo.Enumerator GetFields(BindingFlags bindingFlags = cDefaultLookup)
|
||||
{
|
||||
return FieldInfo.Enumerator(null, bindingFlags);
|
||||
|
@ -912,6 +917,13 @@ namespace System.Reflection
|
|||
return .Err;
|
||||
}
|
||||
|
||||
public override Result<FieldInfo> GetField(int fieldIdx)
|
||||
{
|
||||
if ((fieldIdx < 0) || (fieldIdx >= mFieldDataCount))
|
||||
return .Err;
|
||||
return FieldInfo(this, &mFieldDataPtr[fieldIdx]);
|
||||
}
|
||||
|
||||
public override FieldInfo.Enumerator GetFields(BindingFlags bindingFlags = cDefaultLookup)
|
||||
{
|
||||
return FieldInfo.Enumerator(this, bindingFlags);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue