mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 11:38:21 +02:00
Added System.Interop.FlexibleArrayAttribute
This commit is contained in:
parent
0b162c0ebd
commit
9ba19e4cd7
1 changed files with 31 additions and 0 deletions
|
@ -70,6 +70,7 @@ namespace System
|
||||||
public ref T Value => ref *mVal;
|
public ref T Value => ref *mVal;
|
||||||
public T* Ptr => mVal;
|
public T* Ptr => mVal;
|
||||||
|
|
||||||
|
/// Initialize for creating
|
||||||
[AllowAppend]
|
[AllowAppend]
|
||||||
public this(int count)
|
public this(int count)
|
||||||
{
|
{
|
||||||
|
@ -79,6 +80,36 @@ namespace System
|
||||||
(void)data;
|
(void)data;
|
||||||
mCount = (.)count;
|
mCount = (.)count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Initialize for reading
|
||||||
|
public this(T* ptr, int count)
|
||||||
|
{
|
||||||
|
mVal = ptr;
|
||||||
|
mCount = (.)count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[AttributeUsage(.Struct)]
|
||||||
|
struct FlexibleArrayAttribute : Attribute, IOnTypeInit
|
||||||
|
{
|
||||||
|
String mName;
|
||||||
|
|
||||||
|
public this(String name)
|
||||||
|
{
|
||||||
|
mName = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Comptime]
|
||||||
|
public void OnTypeInit(Type type, Self* prev)
|
||||||
|
{
|
||||||
|
if (type.IsGenericParam)
|
||||||
|
return;
|
||||||
|
var field = type.GetField(type.FieldCount - 1).GetValueOrDefault();
|
||||||
|
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.EmitTypeBody(type, scope $"public {elementType}* {mName} mut => (({elementType}*)((uint8*)&this + Math.Align(typeof(Self).Size, typeof({elementType}).Align)));");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue