mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 12:32:20 +02:00
Improved some var handling for allocations
This commit is contained in:
parent
1c876af91c
commit
5d909752c9
2 changed files with 31 additions and 33 deletions
|
@ -10987,7 +10987,10 @@ void BfExprEvaluator::Visit(BfObjectCreateExpression* objCreateExpr)
|
|||
}
|
||||
|
||||
if (resolvedTypeRef == NULL)
|
||||
return;
|
||||
{
|
||||
unresolvedTypeRef = mModule->GetPrimitiveType(BfTypeCode_Var);
|
||||
resolvedTypeRef = unresolvedTypeRef;
|
||||
}
|
||||
auto resultType = resolvedTypeRef;
|
||||
|
||||
if ((resolvedTypeRef->IsInterface()) && (!isArrayAlloc))
|
||||
|
@ -11301,6 +11304,14 @@ void BfExprEvaluator::Visit(BfObjectCreateExpression* objCreateExpr)
|
|||
}
|
||||
};
|
||||
|
||||
if (resultType->IsVar())
|
||||
{
|
||||
SetAndRestoreValue<bool> prevIgnoreWrites(mModule->mBfIRBuilder->mIgnoreWrites, true);
|
||||
mResult = BfTypedValue(BfTypedValue(mModule->mBfIRBuilder->GetFakeVal(), mModule->GetPrimitiveType(BfTypeCode_Var)));
|
||||
_HandleInitExprs(mResult.mValue, 0, objCreateExpr->mArguments);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isRawArrayAlloc)
|
||||
{
|
||||
// If we have a constant-sized alloc then make the type a pointer to the sized array, otherwise just a pointer to the raw type
|
||||
|
@ -11569,13 +11580,21 @@ void BfExprEvaluator::Visit(BfObjectCreateExpression* objCreateExpr)
|
|||
appendAllocAlign = BF_MAX(appendAllocAlign, allocAlign);
|
||||
|
||||
BfIRValue allocValue;
|
||||
if (isAppendAlloc)
|
||||
allocValue = mModule->AppendAllocFromType(resolvedTypeRef, appendSizeValue, appendAllocAlign);
|
||||
if (resolvedTypeRef->IsVar())
|
||||
{
|
||||
mResult = mModule->GetDefaultTypedValue(resultType);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
allocValue = mModule->AllocFromType(resolvedTypeRef, allocTarget, appendSizeValue, BfIRValue(), 0, BfAllocFlags_None, allocAlign);
|
||||
if (isAppendAlloc)
|
||||
allocValue = mModule->AppendAllocFromType(resolvedTypeRef, appendSizeValue, appendAllocAlign);
|
||||
else
|
||||
{
|
||||
allocValue = mModule->AllocFromType(resolvedTypeRef, allocTarget, appendSizeValue, BfIRValue(), 0, BfAllocFlags_None, allocAlign);
|
||||
}
|
||||
mResult = BfTypedValue(allocValue, resultType);
|
||||
}
|
||||
mResult = BfTypedValue(allocValue, resultType);
|
||||
|
||||
if (isScopeAlloc)
|
||||
{
|
||||
|
@ -11696,32 +11715,6 @@ void BfExprEvaluator::Visit(BfObjectCreateExpression* objCreateExpr)
|
|||
CreateCall(bindResult.mMethodInstance, bindResult.mFunc, false, bindResult.mIRArgs);
|
||||
}
|
||||
}
|
||||
|
||||
// if ((mResult) && (!isArrayAlloc) && (objCreateExpr->mCollectionInitializer != NULL))
|
||||
// {
|
||||
// for (BfExpression* initExpr : objCreateExpr->mCollectionInitializer->mValues)
|
||||
// {
|
||||
// SizedArray<ASTREF(BfExpression*), 1> exprs;
|
||||
//
|
||||
// if (auto groupExpr = BfNodeDynCast<BfCollectionInitializerExpression>(initExpr))
|
||||
// {
|
||||
// for (BfExpression* argExpr : groupExpr->mValues)
|
||||
// exprs.push_back(argExpr);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// exprs.push_back(initExpr);
|
||||
// }
|
||||
//
|
||||
// BfExprEvaluator exprEvaluator(mModule);
|
||||
// SizedArray<BfExpression*, 8> copiedArgs;
|
||||
// for (BfExpression* arg : exprs)
|
||||
// copiedArgs.push_back(arg);
|
||||
// BfResolvedArgs argValues(copiedArgs);
|
||||
// exprEvaluator.ResolveArgValues(argValues);
|
||||
// exprEvaluator.MatchMethod(initExpr, NULL, mResult, false, false, "Add", argValues, NULL);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
void BfExprEvaluator::Visit(BfBoxExpression* boxExpr)
|
||||
|
@ -17394,7 +17387,7 @@ void BfExprEvaluator::PerformBinaryOperation(BfAstNode* leftExpression, BfAstNod
|
|||
|
||||
if ((resultType->IsVar()) || (otherType->IsVar()))
|
||||
{
|
||||
mResult = BfTypedValue(mModule->GetDefaultValue(resultType), mModule->GetPrimitiveType(BfTypeCode_Var));
|
||||
mResult = mModule->GetDefaultTypedValue(resultType);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1380,6 +1380,9 @@ BfTypedValue BfModule::GetFakeTypedValue(BfType* type)
|
|||
|
||||
BfTypedValue BfModule::GetDefaultTypedValue(BfType* type, bool allowRef, BfDefaultValueKind defaultValueKind)
|
||||
{
|
||||
if (type->IsVar())
|
||||
return BfTypedValue(mBfIRBuilder->GetFakeVal(), type);
|
||||
|
||||
PopulateType(type, BfPopulateType_Data);
|
||||
mBfIRBuilder->PopulateType(type, type->IsValueType() ? BfIRPopulateType_Full : BfIRPopulateType_Declaration);
|
||||
|
||||
|
@ -7384,6 +7387,8 @@ BfIRValue BfModule::AllocFromType(BfType* type, const BfAllocTarget& allocTarget
|
|||
|
||||
BfScopeData* scopeData = allocTarget.mScopeData;
|
||||
|
||||
BF_ASSERT(!type->IsVar());
|
||||
|
||||
auto typeInstance = type->ToTypeInstance();
|
||||
if ((typeInstance == NULL) && (type->IsGenericParam()))
|
||||
typeInstance = mContext->mBfObjectType;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue