mirror of
https://github.com/beefytech/Beef.git
synced 2025-07-04 15:26:00 +02:00
Added Compiler.Align
This commit is contained in:
parent
ec4ccb2e9c
commit
8aef7275d0
5 changed files with 55 additions and 13 deletions
|
@ -300,6 +300,7 @@ namespace System
|
|||
}
|
||||
|
||||
static extern void Comptime_SetReturnType(int32 typeId);
|
||||
static extern void Comptime_Align(int32 typeId, int32 align);
|
||||
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);
|
||||
|
@ -328,6 +329,12 @@ namespace System
|
|||
Comptime_SetReturnType((.)type.TypeId);
|
||||
}
|
||||
|
||||
[Comptime(OnlyFromComptime=true)]
|
||||
public static void Align(Type type, int align)
|
||||
{
|
||||
Comptime_Align((.)type.TypeId, (.)align);
|
||||
}
|
||||
|
||||
[Comptime(OnlyFromComptime=true)]
|
||||
public static void EmitAddInterface(Type owner, Type iface)
|
||||
{
|
||||
|
|
|
@ -108,6 +108,7 @@ namespace System
|
|||
if ((field.FieldType == null) || (!field.FieldType.IsSizedArray) || (field.FieldType.Size != 0))
|
||||
Runtime.FatalError("Type must end in a zero-sized array");
|
||||
var elementType = (field.FieldType as SizedArrayType).UnderlyingType;
|
||||
Compiler.Align(type, elementType.Align);
|
||||
Compiler.EmitTypeBody(type, scope $"""
|
||||
public {elementType}* {mName} mut => (({elementType}*)((uint8*)&this + Math.Align(typeof(Self).Size, typeof({elementType}).Align)));
|
||||
public static int GetAllocSize(int arrayCount) => Math.Align(typeof(Self).Size, typeof({elementType}).Align) + typeof({elementType}).Size*arrayCount;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue