1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 03:52:19 +02:00

Added ability to dynamically cast delegates with compatible signatures

This commit is contained in:
Brian Fiete 2025-03-22 15:34:59 -04:00
parent f10365c1ad
commit 37f72cd3b6
8 changed files with 217 additions and 76 deletions

View file

@ -8110,16 +8110,28 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8*
{
CE_CHECKADDR(valueAddr, sizeof(int32));
auto ifaceType = GetBfType(ifaceId);
auto wantType = GetBfType(ifaceId);
int32 objTypeId = *(int32*)(memStart + valueAddr);
auto valueType = GetBfType(objTypeId);
if ((ifaceType == NULL) || (valueType == NULL))
if ((wantType == NULL) || (valueType == NULL))
{
_Fail("Invalid type in CeOp_DynamicCastCheck");
return false;
}
if (ceModule->TypeIsSubTypeOf(valueType->ToTypeInstance(), ifaceType->ToTypeInstance(), false))
bool matches = false;
if (ceModule->TypeIsSubTypeOf(valueType->ToTypeInstance(), wantType->ToTypeInstance(), false))
{
matches = true;
}
else if ((valueType->IsDelegate()) && (wantType->IsDelegate()))
{
int valueSignatureId = ceModule->GetDelegateSignatureId(valueType->ToTypeInstance());
int checkSignatureId = ceModule->GetDelegateSignatureId(wantType->ToTypeInstance());
matches = valueSignatureId == checkSignatureId;
}
if (matches)
CeSetAddrVal(&result, valueAddr, ptrSize);
else
CeSetAddrVal(&result, 0, ptrSize);