mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-14 14:24:10 +02:00
Fixed generic interface methods with default impls, comptime attribs
This commit is contained in:
parent
79e2ff5165
commit
88121831e2
3 changed files with 65 additions and 22 deletions
|
@ -5489,7 +5489,7 @@ void BfModule::EncodeAttributeData(BfTypeInstance* typeInstance, BfType* argType
|
||||||
|
|
||||||
BfIRValue BfModule::CreateFieldData(BfFieldInstance* fieldInstance, int customAttrIdx)
|
BfIRValue BfModule::CreateFieldData(BfFieldInstance* fieldInstance, int customAttrIdx)
|
||||||
{
|
{
|
||||||
bool isComptime = mBfIRBuilder->mIgnoreWrites;
|
bool isComptimeArg = mBfIRBuilder->mIgnoreWrites;
|
||||||
BfFieldDef* fieldDef = fieldInstance->GetFieldDef();
|
BfFieldDef* fieldDef = fieldInstance->GetFieldDef();
|
||||||
|
|
||||||
auto typeInstance = fieldInstance->mOwner;
|
auto typeInstance = fieldInstance->mOwner;
|
||||||
|
@ -5564,7 +5564,7 @@ BfIRValue BfModule::CreateFieldData(BfFieldInstance* fieldInstance, int customAt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((refVal.IsAddr()) && (!isComptime))
|
if ((refVal.IsAddr()) && (!isComptimeArg))
|
||||||
constValue = mBfIRBuilder->CreatePtrToInt(refVal.mValue, BfTypeCode_IntPtr);
|
constValue = mBfIRBuilder->CreatePtrToInt(refVal.mValue, BfTypeCode_IntPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5585,10 +5585,10 @@ BfIRValue BfModule::CreateFieldData(BfFieldInstance* fieldInstance, int customAt
|
||||||
constValue, // mData
|
constValue, // mData
|
||||||
constValue2, // mDataHi
|
constValue2, // mDataHi
|
||||||
GetConstValue(fieldFlags, shortType), // mFlags
|
GetConstValue(fieldFlags, shortType), // mFlags
|
||||||
GetConstValue(customAttrIdx, intType), // mCustomAttributesIdx
|
GetConstValue((isComptimeArg || mIsComptimeModule) ? fieldInstance->mFieldIdx : customAttrIdx, intType), // mCustomAttributesIdx
|
||||||
};
|
};
|
||||||
FixConstValueParams(reflectFieldDataType, fieldVals, isComptime);
|
FixConstValueParams(reflectFieldDataType, fieldVals, isComptimeArg);
|
||||||
result = isComptime ?
|
result = isComptimeArg ?
|
||||||
mBfIRBuilder->CreateConstAgg(mBfIRBuilder->MapTypeInst(reflectFieldDataType, BfIRPopulateType_Full), fieldVals) :
|
mBfIRBuilder->CreateConstAgg(mBfIRBuilder->MapTypeInst(reflectFieldDataType, BfIRPopulateType_Full), fieldVals) :
|
||||||
mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(reflectFieldDataType, BfIRPopulateType_Full), fieldVals);
|
mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(reflectFieldDataType, BfIRPopulateType_Full), fieldVals);
|
||||||
}
|
}
|
||||||
|
@ -5601,10 +5601,10 @@ BfIRValue BfModule::CreateFieldData(BfFieldInstance* fieldInstance, int customAt
|
||||||
GetConstValue(typeId, typeIdType), // mFieldTypeId
|
GetConstValue(typeId, typeIdType), // mFieldTypeId
|
||||||
constValue, // mData
|
constValue, // mData
|
||||||
GetConstValue(fieldFlags, shortType), // mFlags
|
GetConstValue(fieldFlags, shortType), // mFlags
|
||||||
GetConstValue(customAttrIdx, intType), // mCustomAttributesIdx
|
GetConstValue((isComptimeArg || mIsComptimeModule) ? fieldInstance->mFieldIdx : customAttrIdx, intType), // mCustomAttributesIdx
|
||||||
};
|
};
|
||||||
FixConstValueParams(reflectFieldDataType, fieldVals, isComptime);
|
FixConstValueParams(reflectFieldDataType, fieldVals, isComptimeArg);
|
||||||
result = isComptime ?
|
result = isComptimeArg ?
|
||||||
mBfIRBuilder->CreateConstAgg(mBfIRBuilder->MapTypeInst(reflectFieldDataType, BfIRPopulateType_Full), fieldVals) :
|
mBfIRBuilder->CreateConstAgg(mBfIRBuilder->MapTypeInst(reflectFieldDataType, BfIRPopulateType_Full), fieldVals) :
|
||||||
mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(reflectFieldDataType, BfIRPopulateType_Full), fieldVals);
|
mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(reflectFieldDataType, BfIRPopulateType_Full), fieldVals);
|
||||||
}
|
}
|
||||||
|
@ -13732,7 +13732,17 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (methodInstGroup == NULL)
|
if (methodInstGroup == NULL)
|
||||||
|
{
|
||||||
|
if (lookupMethodGenericArguments.size() != 0)
|
||||||
|
{
|
||||||
|
BF_ASSERT((flags & BfGetMethodInstanceFlag_ForeignMethodDef) != 0);
|
||||||
|
auto defaultMethodInstance = GetMethodInstance(typeInst, methodDef, BfTypeVector(),
|
||||||
|
(BfGetMethodInstanceFlags)((flags & (BfGetMethodInstanceFlag_ForeignMethodDef)) | BfGetMethodInstanceFlag_UnspecializedPass | BfGetMethodInstanceFlag_MethodInstanceOnly), foreignType);
|
||||||
|
methodInstGroup = defaultMethodInstance.mMethodInstance->mMethodInstanceGroup;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
// Allocate a new entry
|
// Allocate a new entry
|
||||||
typeInst->mMethodInstanceGroups.Resize(typeInst->mMethodInstanceGroups.size() + 1);
|
typeInst->mMethodInstanceGroups.Resize(typeInst->mMethodInstanceGroups.size() + 1);
|
||||||
|
@ -13744,7 +13754,11 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM
|
||||||
if (mCompiler->mOptions.mCompileOnDemandKind == BfCompileOnDemandKind_AlwaysInclude)
|
if (mCompiler->mOptions.mCompileOnDemandKind == BfCompileOnDemandKind_AlwaysInclude)
|
||||||
methodInstGroup->mOnDemandKind = BfMethodOnDemandKind_AlwaysInclude;
|
methodInstGroup->mOnDemandKind = BfMethodOnDemandKind_AlwaysInclude;
|
||||||
else
|
else
|
||||||
|
{
|
||||||
methodInstGroup->mOnDemandKind = BfMethodOnDemandKind_Decl_AwaitingDecl;
|
methodInstGroup->mOnDemandKind = BfMethodOnDemandKind_Decl_AwaitingDecl;
|
||||||
|
mOnDemandMethodCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -13878,6 +13892,13 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (methodInstGroup->mDefault == NULL)
|
||||||
|
{
|
||||||
|
auto defaultMethodInstance = GetMethodInstance(typeInst, methodDef, BfTypeVector(),
|
||||||
|
(BfGetMethodInstanceFlags)((flags & (BfGetMethodInstanceFlag_ForeignMethodDef)) | BfGetMethodInstanceFlag_UnspecializedPass | BfGetMethodInstanceFlag_MethodInstanceOnly), foreignType);
|
||||||
|
methodInstGroup = defaultMethodInstance.mMethodInstance->mMethodInstanceGroup;
|
||||||
|
}
|
||||||
|
|
||||||
BF_ASSERT(lookupMethodGenericArguments.size() != 0);
|
BF_ASSERT(lookupMethodGenericArguments.size() != 0);
|
||||||
if (methodInstGroup->mMethodSpecializationMap == NULL)
|
if (methodInstGroup->mMethodSpecializationMap == NULL)
|
||||||
methodInstGroup->mMethodSpecializationMap = new BfMethodInstanceGroup::MapType();
|
methodInstGroup->mMethodSpecializationMap = new BfMethodInstanceGroup::MapType();
|
||||||
|
|
|
@ -2239,7 +2239,7 @@ void BfModule::HandleCEAttributes(CeEmitContext* ceEmitContext, BfTypeInstance*
|
||||||
{
|
{
|
||||||
mBfIRBuilder->CreateConstAggZero(mBfIRBuilder->MapType(fieldInfoType->ToTypeInstance()->mBaseType, BfIRPopulateType_Identity)),
|
mBfIRBuilder->CreateConstAggZero(mBfIRBuilder->MapType(fieldInfoType->ToTypeInstance()->mBaseType, BfIRPopulateType_Identity)),
|
||||||
mBfIRBuilder->CreateTypeOf(mCurTypeInstance), // mTypeInstance
|
mBfIRBuilder->CreateTypeOf(mCurTypeInstance), // mTypeInstance
|
||||||
CreateFieldData(fieldInstance, fieldInstance->GetFieldDef()->mIdx)
|
CreateFieldData(fieldInstance, -1)
|
||||||
};
|
};
|
||||||
FixConstValueParams(fieldInfoType->ToTypeInstance(), fieldData);
|
FixConstValueParams(fieldInfoType->ToTypeInstance(), fieldData);
|
||||||
auto fieldDataAgg = mBfIRBuilder->CreateConstAgg(mBfIRBuilder->MapType(fieldInfoType, BfIRPopulateType_Identity), fieldData);
|
auto fieldDataAgg = mBfIRBuilder->CreateConstAgg(mBfIRBuilder->MapType(fieldInfoType, BfIRPopulateType_Identity), fieldData);
|
||||||
|
@ -12882,7 +12882,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
|
||||||
|
|
||||||
if (isNull)
|
if (isNull)
|
||||||
{
|
{
|
||||||
spanFieldVals.Add(mBfIRBuilder->CreateConstNull());
|
spanFieldVals.Add(mBfIRBuilder->CreateConstNull(mBfIRBuilder->MapType(CreatePointerType(GetPrimitiveType(BfTypeCode_Char8)))));
|
||||||
spanFieldVals.Add(mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, 0));
|
spanFieldVals.Add(mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, 0));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -1297,6 +1297,15 @@ void CeBuilder::ProcessMethod(BfMethodInstance* methodInstance, BfMethodInstance
|
||||||
dupMethodInstance->mIsReified = true;
|
dupMethodInstance->mIsReified = true;
|
||||||
dupMethodInstance->mInCEMachine = false; // Only have the original one
|
dupMethodInstance->mInCEMachine = false; // Only have the original one
|
||||||
|
|
||||||
|
// We can't use methodInstance->mMethodInstanceGroup because we may add foreign method instances which
|
||||||
|
// would reallocate the methodInstanceGroup
|
||||||
|
BfMethodInstanceGroup methodInstanceGroup;
|
||||||
|
methodInstanceGroup.mOwner = methodInstance->mMethodInstanceGroup->mOwner;
|
||||||
|
methodInstanceGroup.mDefault = methodInstance->mMethodInstanceGroup->mDefault;
|
||||||
|
methodInstanceGroup.mMethodIdx = methodInstance->mMethodInstanceGroup->mMethodIdx;
|
||||||
|
methodInstanceGroup.mOnDemandKind = BfMethodOnDemandKind_AlwaysInclude;
|
||||||
|
dupMethodInstance->mMethodInstanceGroup = &methodInstanceGroup;
|
||||||
|
|
||||||
mCeMachine->mCeModule->mHadBuildError = false;
|
mCeMachine->mCeModule->mHadBuildError = false;
|
||||||
auto irState = irBuilder->GetState();
|
auto irState = irBuilder->GetState();
|
||||||
auto beState = irCodeGen->GetState();
|
auto beState = irCodeGen->GetState();
|
||||||
|
@ -1306,6 +1315,9 @@ void CeBuilder::ProcessMethod(BfMethodInstance* methodInstance, BfMethodInstance
|
||||||
|
|
||||||
if (mCeMachine->mCeModule->mCompiler->mResolvePassData != NULL)
|
if (mCeMachine->mCeModule->mCompiler->mResolvePassData != NULL)
|
||||||
mCeMachine->mCeModule->mCompiler->mResolvePassData->mAutoComplete = prevAutoComplete;
|
mCeMachine->mCeModule->mCompiler->mResolvePassData->mAutoComplete = prevAutoComplete;
|
||||||
|
|
||||||
|
methodInstanceGroup.mDefault = NULL;
|
||||||
|
dupMethodInstance->mMethodInstanceGroup = methodInstance->mMethodInstanceGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CeBuilder::Build()
|
void CeBuilder::Build()
|
||||||
|
@ -2928,6 +2940,8 @@ CeContext::~CeContext()
|
||||||
|
|
||||||
BfError* CeContext::Fail(const StringImpl& error)
|
BfError* CeContext::Fail(const StringImpl& error)
|
||||||
{
|
{
|
||||||
|
if (mCurModule == NULL)
|
||||||
|
return NULL;
|
||||||
if (mCurEmitContext != NULL)
|
if (mCurEmitContext != NULL)
|
||||||
mCurEmitContext->mFailed = true;
|
mCurEmitContext->mFailed = true;
|
||||||
auto bfError = mCurModule->Fail(StrFormat("Unable to comptime %s", mCurModule->MethodToString(mCurMethodInstance).c_str()), mCurTargetSrc, (mCurEvalFlags & CeEvalFlags_PersistantError) != 0);
|
auto bfError = mCurModule->Fail(StrFormat("Unable to comptime %s", mCurModule->MethodToString(mCurMethodInstance).c_str()), mCurTargetSrc, (mCurEvalFlags & CeEvalFlags_PersistantError) != 0);
|
||||||
|
@ -5126,6 +5140,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8*
|
||||||
auto typeInst = type->ToTypeInstance();
|
auto typeInst = type->ToTypeInstance();
|
||||||
if (typeInst != NULL)
|
if (typeInst != NULL)
|
||||||
success = GetCustomAttribute(mCurModule, typeInst->mConstHolder, typeInst->mCustomAttributes, attributeTypeId, resultPtr);
|
success = GetCustomAttribute(mCurModule, typeInst->mConstHolder, typeInst->mCustomAttributes, attributeTypeId, resultPtr);
|
||||||
|
_FixVariables();
|
||||||
}
|
}
|
||||||
|
|
||||||
*(addr_ce*)(stackPtr + 0) = success;
|
*(addr_ce*)(stackPtr + 0) = success;
|
||||||
|
@ -5146,10 +5161,16 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8*
|
||||||
{
|
{
|
||||||
if (typeInst->mDefineState < BfTypeDefineState_CETypeInit)
|
if (typeInst->mDefineState < BfTypeDefineState_CETypeInit)
|
||||||
mCurModule->PopulateType(typeInst);
|
mCurModule->PopulateType(typeInst);
|
||||||
if (fieldIdx < typeInst->mFieldInstances.mSize)
|
if ((fieldIdx >= 0) && (fieldIdx < typeInst->mFieldInstances.mSize))
|
||||||
{
|
{
|
||||||
auto& fieldInstance = typeInst->mFieldInstances[fieldIdx];
|
auto& fieldInstance = typeInst->mFieldInstances[fieldIdx];
|
||||||
success = GetCustomAttribute(mCurModule, typeInst->mConstHolder, fieldInstance.mCustomAttributes, attributeTypeId, resultPtr);
|
success = GetCustomAttribute(mCurModule, typeInst->mConstHolder, fieldInstance.mCustomAttributes, attributeTypeId, resultPtr);
|
||||||
|
_FixVariables();
|
||||||
|
}
|
||||||
|
else if (fieldIdx != -1)
|
||||||
|
{
|
||||||
|
_Fail("Invalid field");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5169,6 +5190,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8*
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool success = GetCustomAttribute(mCurModule, methodInstance->GetOwner()->mConstHolder, methodInstance->GetCustomAttributes(), attributeTypeId, resultPtr);
|
bool success = GetCustomAttribute(mCurModule, methodInstance->GetOwner()->mConstHolder, methodInstance->GetCustomAttributes(), attributeTypeId, resultPtr);
|
||||||
|
_FixVariables();
|
||||||
*(addr_ce*)(stackPtr + 0) = success;
|
*(addr_ce*)(stackPtr + 0) = success;
|
||||||
}
|
}
|
||||||
else if (checkFunction->mFunctionKind == CeFunctionKind_GetMethodCount)
|
else if (checkFunction->mFunctionKind == CeFunctionKind_GetMethodCount)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue