mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-20 00:50:25 +02:00
Reflection changes - interface info, boxed type
This commit is contained in:
parent
5640e6b074
commit
8def1d4522
11 changed files with 350 additions and 108 deletions
|
@ -251,6 +251,8 @@ namespace System.Reflection
|
|||
}
|
||||
}
|
||||
|
||||
void* funcPtr = null;
|
||||
int ifaceOffset = -1;
|
||||
if (mMethodData.mFlags.HasFlag(.Static))
|
||||
{
|
||||
if (target.HasValue)
|
||||
|
@ -260,9 +262,45 @@ namespace System.Reflection
|
|||
{
|
||||
if (!target.HasValue)
|
||||
return .Err(.TargetExpected);
|
||||
var thisType = mTypeInstance;
|
||||
if (mTypeInstance.IsInterface)
|
||||
{
|
||||
if (target.IsObject)
|
||||
{
|
||||
var targetObject = target.Get<Object>();
|
||||
thisType = targetObject.GetType() as TypeInstance;
|
||||
if (thisType == null)
|
||||
return .Err(.InvalidTarget);
|
||||
}
|
||||
else
|
||||
{
|
||||
TypeInstance.InterfaceData* interfaceData = null;
|
||||
var checkType = thisType;
|
||||
CheckLoop: while (checkType != null)
|
||||
{
|
||||
for (int ifaceIdx < checkType.[Friend]mInterfaceCount)
|
||||
{
|
||||
if (checkType.[Friend]mInterfaceDataPtr[ifaceIdx].mInterfaceType == mTypeInstance.TypeId)
|
||||
{
|
||||
interfaceData = &checkType.[Friend]mInterfaceDataPtr[ifaceIdx];
|
||||
break CheckLoop;
|
||||
}
|
||||
}
|
||||
|
||||
bool splatThis = mTypeInstance.IsSplattable && !mMethodData.mFlags.HasFlag(.Mutating);
|
||||
AddArg!::(-1, ref target, &target, mTypeInstance, splatThis);
|
||||
checkType = checkType.BaseType;
|
||||
}
|
||||
|
||||
if (interfaceData == null)
|
||||
return .Err(.InvalidTarget);
|
||||
|
||||
//funcPtr = *(thisType.[Friend]mInterfaceMethodTable + mMethodData.mVirtualIdx);
|
||||
}
|
||||
|
||||
ifaceOffset = mTypeInstance.[Friend]mMemberDataOffset;
|
||||
}
|
||||
|
||||
bool splatThis = thisType.IsSplattable && !mMethodData.mFlags.HasFlag(.Mutating);
|
||||
AddArg!::(-1, ref target, &target.[Friend]mData, thisType, splatThis);
|
||||
}
|
||||
|
||||
if (args.Length != mMethodData.mParamCount)
|
||||
|
@ -288,7 +326,7 @@ namespace System.Reflection
|
|||
{
|
||||
let paramData = ref mMethodData.mParamData[@arg.Index];
|
||||
let argType = Type.[Friend]GetType(paramData.mType);
|
||||
AddArg!::(@arg.Index, ref arg, &arg, argType, paramData.mParamFlags.HasFlag(.Splat));
|
||||
AddArg!::(@arg.Index, ref arg, &arg.[Friend]mData, argType, paramData.mParamFlags.HasFlag(.Splat));
|
||||
}
|
||||
|
||||
FFICaller caller = .();
|
||||
|
@ -303,24 +341,32 @@ namespace System.Reflection
|
|||
return .Err(.FFIError);
|
||||
}
|
||||
|
||||
void* funcPtr = mMethodData.mFuncPtr;
|
||||
if (mMethodData.mFlags.HasFlag(.Virtual))
|
||||
if (funcPtr == null)
|
||||
{
|
||||
Object objTarget = target.Get<Object>();
|
||||
|
||||
funcPtr = mMethodData.mFuncPtr;
|
||||
if (mMethodData.mFlags.HasFlag(.Virtual))
|
||||
{
|
||||
Object objTarget = target.Get<Object>();
|
||||
|
||||
#if BF_ENABLE_OBJECT_DEBUG_FLAGS
|
||||
void* classVData = (void*)(objTarget.[Friend]mClassVData & ~0xFF);
|
||||
void* classVData = (void*)(objTarget.[Friend]mClassVData & ~0xFF);
|
||||
#else
|
||||
void* classVData = objTarget.[Friend]mClassVData;
|
||||
void* classVData = objTarget.[Friend]mClassVData;
|
||||
#endif
|
||||
if (mMethodData.mVirtualIdx >= 0x100000)
|
||||
{
|
||||
void* extAddr = (void*)*((int*)classVData + (mMethodData.mVirtualIdx>>20 - 1));
|
||||
funcPtr = (void*)*((int*)extAddr + (mMethodData.mVirtualIdx & 0xFFFFF));
|
||||
}
|
||||
else
|
||||
{
|
||||
funcPtr = (void*)*(int*)((uint8*)classVData + mMethodData.mVirtualIdx);
|
||||
if (ifaceOffset >= 0)
|
||||
{
|
||||
void* ifaceVirtualTable = *(void**)((uint8*)classVData + ifaceOffset);
|
||||
funcPtr = (void*)*(int*)((uint8*)ifaceVirtualTable + mMethodData.mVirtualIdx);
|
||||
}
|
||||
else if (mMethodData.mVirtualIdx >= 0x100000)
|
||||
{
|
||||
void* extAddr = (void*)*((int*)classVData + (mMethodData.mVirtualIdx>>20 - 1));
|
||||
funcPtr = (void*)*((int*)extAddr + (mMethodData.mVirtualIdx & 0xFFFFF));
|
||||
}
|
||||
else
|
||||
{
|
||||
funcPtr = (void*)*(int*)((uint8*)classVData + mMethodData.mVirtualIdx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -549,6 +595,9 @@ namespace System.Reflection
|
|||
}
|
||||
}
|
||||
|
||||
void* funcPtr = mMethodData.mFuncPtr;
|
||||
int virtualOffset = 0;
|
||||
int ifaceOffset = -1;
|
||||
if (mMethodData.mFlags.HasFlag(.Static))
|
||||
{
|
||||
if (target != null)
|
||||
|
@ -559,8 +608,38 @@ namespace System.Reflection
|
|||
if (target == null)
|
||||
return .Err(.TargetExpected);
|
||||
|
||||
bool splatThis = mTypeInstance.IsSplattable && !mMethodData.mFlags.HasFlag(.Mutating);
|
||||
AddArg!::(-1, target, &target, mTypeInstance, splatThis);
|
||||
var thisType = mTypeInstance;
|
||||
if (mTypeInstance.IsInterface)
|
||||
{
|
||||
thisType = target.[Friend]RawGetType() as TypeInstance;
|
||||
if (thisType == null)
|
||||
return .Err(.InvalidTarget);
|
||||
|
||||
ifaceOffset = mTypeInstance.[Friend]mMemberDataOffset;
|
||||
|
||||
/*TypeInstance.InterfaceData* interfaceData = null;
|
||||
var checkType = thisType;
|
||||
CheckLoop: while (checkType != null)
|
||||
{
|
||||
for (int ifaceIdx < checkType.[Friend]mInterfaceCount)
|
||||
{
|
||||
if (checkType.[Friend]mInterfaceDataPtr[ifaceIdx].mInterfaceType == mTypeInstance.TypeId)
|
||||
{
|
||||
interfaceData = &checkType.[Friend]mInterfaceDataPtr[ifaceIdx];
|
||||
break CheckLoop;
|
||||
}
|
||||
}
|
||||
|
||||
checkType = checkType.BaseType;
|
||||
}
|
||||
|
||||
if (interfaceData == null)
|
||||
return .Err(.InvalidTarget);
|
||||
virtualOffset = interfaceData.mStartVirtualIdx * sizeof(int);*/
|
||||
}
|
||||
|
||||
bool splatThis = thisType.IsSplattable && !mMethodData.mFlags.HasFlag(.Mutating);
|
||||
AddArg!::(-1, target, &target, thisType, splatThis);
|
||||
}
|
||||
|
||||
if (args.Count != mMethodData.mParamCount)
|
||||
|
@ -601,7 +680,6 @@ namespace System.Reflection
|
|||
return .Err(.FFIError);
|
||||
}
|
||||
|
||||
void* funcPtr = mMethodData.mFuncPtr;
|
||||
if (mMethodData.mFlags.HasFlag(.Virtual))
|
||||
{
|
||||
#if BF_ENABLE_OBJECT_DEBUG_FLAGS
|
||||
|
@ -609,14 +687,19 @@ namespace System.Reflection
|
|||
#else
|
||||
void* classVData = target.[Friend]mClassVData;
|
||||
#endif
|
||||
if (mMethodData.mVirtualIdx >= 0x100000)
|
||||
if (ifaceOffset >= 0)
|
||||
{
|
||||
void* ifaceVirtualTable = *(void**)((uint8*)classVData + ifaceOffset);
|
||||
funcPtr = (void*)*(int*)((uint8*)ifaceVirtualTable + mMethodData.mVirtualIdx + virtualOffset);
|
||||
}
|
||||
else if (mMethodData.mVirtualIdx >= 0x100000)
|
||||
{
|
||||
void* extAddr = (void*)*((int*)classVData + (mMethodData.mVirtualIdx>>20 - 1));
|
||||
funcPtr = (void*)*((int*)extAddr + (mMethodData.mVirtualIdx & 0xFFFFF));
|
||||
funcPtr = (void*)*((int*)extAddr + (mMethodData.mVirtualIdx & 0xFFFFF) + virtualOffset);
|
||||
}
|
||||
else
|
||||
{
|
||||
funcPtr = (void*)*(int*)((uint8*)classVData + mMethodData.mVirtualIdx);
|
||||
funcPtr = (void*)*(int*)((uint8*)classVData + mMethodData.mVirtualIdx + virtualOffset);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ namespace System
|
|||
|
||||
protected int32 mSize;
|
||||
protected TypeId mTypeId;
|
||||
protected TypeId mBoxedType;
|
||||
protected TypeFlags mTypeFlags;
|
||||
protected int32 mMemberDataOffset;
|
||||
protected TypeCode mTypeCode;
|
||||
|
@ -198,6 +199,14 @@ namespace System
|
|||
}
|
||||
}
|
||||
|
||||
public bool IsInterface
|
||||
{
|
||||
get
|
||||
{
|
||||
return (mTypeFlags & TypeFlags.Interface) != 0;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsValueType
|
||||
{
|
||||
get
|
||||
|
@ -630,6 +639,7 @@ namespace System.Reflection
|
|||
public TypeId mReturnType;
|
||||
public int16 mParamCount;
|
||||
public MethodFlags mFlags;
|
||||
public int32 mMethodIdx;
|
||||
public int32 mVirtualIdx;
|
||||
public int32 mCustomAttributesIdx;
|
||||
}
|
||||
|
@ -650,6 +660,13 @@ namespace System.Reflection
|
|||
public int32 mDefaultIdx;
|
||||
}
|
||||
|
||||
public struct InterfaceData
|
||||
{
|
||||
public TypeId mInterfaceType;
|
||||
public int32 mStartInterfaceTableIdx;
|
||||
public int32 mStartVirtualIdx;
|
||||
}
|
||||
|
||||
ClassVData* mTypeClassVData;
|
||||
String mName;
|
||||
String mNamespace;
|
||||
|
@ -658,7 +675,7 @@ namespace System.Reflection
|
|||
int32 mCustomAttributesIdx;
|
||||
TypeId mBaseType;
|
||||
TypeId mUnderlyingType;
|
||||
TypeId mOuterType;
|
||||
TypeId mOuterType;
|
||||
int32 mInheritanceId;
|
||||
int32 mInheritanceCount;
|
||||
|
||||
|
@ -668,11 +685,12 @@ namespace System.Reflection
|
|||
int16 mPropertyDataCount;
|
||||
int16 mFieldDataCount;
|
||||
|
||||
void* mInterfaceDataPtr;
|
||||
MethodData* mMethodDataPtr;
|
||||
void* mPropertyDataPtr;
|
||||
FieldData* mFieldDataPtr;
|
||||
void** mCustomAttrDataPtr;
|
||||
InterfaceData* mInterfaceDataPtr;
|
||||
void** mInterfaceMethodTable;
|
||||
MethodData* mMethodDataPtr;
|
||||
void* mPropertyDataPtr;
|
||||
FieldData* mFieldDataPtr;
|
||||
void** mCustomAttrDataPtr;
|
||||
|
||||
public override int32 InstanceSize
|
||||
{
|
||||
|
@ -1035,13 +1053,14 @@ namespace System.Reflection
|
|||
Boxed = 0x0010,
|
||||
Pointer = 0x0020,
|
||||
Struct = 0x0040,
|
||||
Primitive = 0x0080,
|
||||
TypedPrimitive = 0x0100,
|
||||
Tuple = 0x0200,
|
||||
Nullable = 0x0400,
|
||||
SizedArray = 0x0800,
|
||||
Splattable = 0x1000,
|
||||
Union = 0x2000,
|
||||
Interface = 0x0080,
|
||||
Primitive = 0x0100,
|
||||
TypedPrimitive = 0x0200,
|
||||
Tuple = 0x0400,
|
||||
Nullable = 0x0800,
|
||||
SizedArray = 0x1000,
|
||||
Splattable = 0x2000,
|
||||
Union = 0x4000,
|
||||
//
|
||||
WantsMark = 0x8000,
|
||||
Delegate = 0x10000,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue