From caf81a72e3201ee6957482f5a332fba7c7e92212 Mon Sep 17 00:00:00 2001 From: xposure Date: Fri, 1 Jan 2021 19:29:05 -0500 Subject: [PATCH] Added CreateObject support for Arrays in minlib --- IDE/mintest/minlib/src/System/Type.bf | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/IDE/mintest/minlib/src/System/Type.bf b/IDE/mintest/minlib/src/System/Type.bf index e81ac992..79006491 100644 --- a/IDE/mintest/minlib/src/System/Type.bf +++ b/IDE/mintest/minlib/src/System/Type.bf @@ -985,6 +985,28 @@ namespace System.Reflection strBuffer.Append(','); strBuffer.Append(']'); } + + public Result 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