1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-07-08 01:05:59 +02:00

Dynamic boxing

This commit is contained in:
Brian Fiete 2020-09-14 11:18:24 -07:00
parent 7036433e5d
commit da5b81f419
14 changed files with 266 additions and 151 deletions

View file

@ -46,9 +46,11 @@ namespace System
Constructors = 0x10,
StaticMethods = 0x20,
Methods = 0x40,
All = 0x7F,
DynamicBoxing = 0x80,
//User = 0x100, // Internal Use
All = 0xFF,
ApplyToInnerTypes = 0x80,
ApplyToInnerTypes = 0x200,
}
public enum AttributeFlags

View file

@ -83,20 +83,23 @@ namespace System.Reflection
return .Err;
MethodInfo methodInfo = default;
for (int methodId < mMethodDataCount)
if (!IsBoxed)
{
let methodData = &mMethodDataPtr[methodId];
if ((!methodData.mFlags.HasFlag(.Constructor)) || (methodData.mFlags.HasFlag(.Static)))
continue;
if (methodData.mParamCount != 0)
continue;
methodInfo = .(this, methodData);
break;
}
for (int methodId < mMethodDataCount)
{
let methodData = &mMethodDataPtr[methodId];
if ((!methodData.mFlags.HasFlag(.Constructor)) || (methodData.mFlags.HasFlag(.Static)))
continue;
if (methodData.mParamCount != 0)
continue;
methodInfo = .(this, methodData);
break;
}
if (!methodInfo.IsInitialized)
return .Err;
if (!methodInfo.IsInitialized)
return .Err;
}
Object obj;
let objType = typeof(Object) as TypeInstance;
@ -109,10 +112,13 @@ namespace System.Reflection
obj.[Friend]mClassVData = (.)(void*)mTypeClassVData;
#endif
Internal.MemSet((uint8*)Internal.UnsafeCastToPtr(obj) + objType.mInstSize, 0, mInstSize - objType.mInstSize);
if (methodInfo.Invoke(obj) case .Err)
if (methodInfo.IsInitialized)
{
delete obj;
return .Err;
if (methodInfo.Invoke(obj) case .Err)
{
delete obj;
return .Err;
}
}
return obj;

View file

@ -304,6 +304,14 @@ namespace System
}
}
public TypeInstance BoxedType
{
get
{
return (TypeInstance)GetType(mBoxedType);
}
}
public bool IsEnum
{
get

View file

@ -296,6 +296,22 @@ namespace System
return *(T*)(void*)mData;
}
public Result<Object> GetBoxed()
{
if (IsObject)
return .Err;
var type = VariantType;
var boxedType = type.BoxedType;
if (boxedType == null)
return .Err;
var self = this;
var object = Try!(boxedType.CreateObject());
Internal.MemCpy((uint8*)Internal.UnsafeCastToPtr(object) + boxedType.[Friend]mMemberDataOffset, self.DataPtr, type.Size);
return object;
}
/*public void Get<T>(ref T val)
{
if (VariantType != typeof(T))