mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-16 23:34:10 +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
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue