1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 20:42:21 +02:00

Merge pull request #782 from xposure/master

Added CreateObject support for Arrays
This commit is contained in:
Brian Fiete 2021-01-02 04:49:59 -08:00 committed by GitHub
commit 08f8ccd4d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 0 deletions

View file

@ -985,6 +985,28 @@ namespace System.Reflection
strBuffer.Append(',');
strBuffer.Append(']');
}
public Result<Object> CreateObject(int32 count)
{
if ([Friend]mTypeClassVData == null)
return .Err;
Object obj;
let genericType = GetGenericArg(0);
let arraySize = [Friend]mInstSize - genericType.Size + genericType.Stride * count;
#if BF_ENABLE_OBJECT_DEBUG_FLAGS
obj = Internal.Dbg_ObjectAlloc([Friend]mTypeClassVData, arraySize, [Friend]mInstAlign, 1);
#else
void* mem = new [Align(16)] uint8[arraySize]* (?);
obj = Internal.UnsafeCastToObject(mem);
obj.[Friend]mClassVData = (.)(void*)[Friend]mTypeClassVData;
#endif
Internal.MemSet((uint8*)Internal.UnsafeCastToPtr(obj) + [Friend]mInstSize, 0, [Friend]arraySize - [Friend]mInstSize);
var array = (Array)obj;
array.[Friend]mLength = count;
return obj;
}
}
public enum TypeFlags : uint32