ソースを参照

Merge pull request #782 from xposure/master

Added CreateObject support for Arrays
Brian Fiete 4 年 前
コミット
08f8ccd4d8
2 ファイル変更44 行追加0 行削除
  1. 22 0
      BeefLibs/corlib/src/Type.bf
  2. 22 0
      IDE/mintest/minlib/src/System/Type.bf

+ 22 - 0
BeefLibs/corlib/src/Type.bf

@@ -1103,6 +1103,28 @@ namespace System.Reflection
 				strBuffer.Append(',');
 				strBuffer.Append(',');
 			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
     public enum TypeFlags : uint32

+ 22 - 0
IDE/mintest/minlib/src/System/Type.bf

@@ -985,6 +985,28 @@ namespace System.Reflection
 				strBuffer.Append(',');
 				strBuffer.Append(',');
 			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
     public enum TypeFlags : uint32