mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 04:22: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)
|
if (resolvedTypeRef == NULL)
|
||||||
return;
|
{
|
||||||
|
unresolvedTypeRef = mModule->GetPrimitiveType(BfTypeCode_Var);
|
||||||
|
resolvedTypeRef = unresolvedTypeRef;
|
||||||
|
}
|
||||||
auto resultType = resolvedTypeRef;
|
auto resultType = resolvedTypeRef;
|
||||||
|
|
||||||
if ((resolvedTypeRef->IsInterface()) && (!isArrayAlloc))
|
if ((resolvedTypeRef->IsInterface()) && (!isArrayAlloc))
|
||||||
|
@ -11300,6 +11303,14 @@ void BfExprEvaluator::Visit(BfObjectCreateExpression* objCreateExpr)
|
||||||
mModule->mBfIRBuilder->CreateConst(BfTypeCode_Int8, isUninit ? 0xCC : 0), clearBytes, resultType->mAlign);
|
mModule->mBfIRBuilder->CreateConst(BfTypeCode_Int8, isUninit ? 0xCC : 0), clearBytes, resultType->mAlign);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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 (isRawArrayAlloc)
|
||||||
{
|
{
|
||||||
|
@ -11569,13 +11580,21 @@ void BfExprEvaluator::Visit(BfObjectCreateExpression* objCreateExpr)
|
||||||
appendAllocAlign = BF_MAX(appendAllocAlign, allocAlign);
|
appendAllocAlign = BF_MAX(appendAllocAlign, allocAlign);
|
||||||
|
|
||||||
BfIRValue allocValue;
|
BfIRValue allocValue;
|
||||||
if (isAppendAlloc)
|
if (resolvedTypeRef->IsVar())
|
||||||
allocValue = mModule->AppendAllocFromType(resolvedTypeRef, appendSizeValue, appendAllocAlign);
|
{
|
||||||
|
mResult = mModule->GetDefaultTypedValue(resultType);
|
||||||
|
return;
|
||||||
|
}
|
||||||
else
|
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)
|
if (isScopeAlloc)
|
||||||
{
|
{
|
||||||
|
@ -11695,33 +11714,7 @@ void BfExprEvaluator::Visit(BfObjectCreateExpression* objCreateExpr)
|
||||||
bindResult.mIRArgs.Insert(0, mResult.mValue);
|
bindResult.mIRArgs.Insert(0, mResult.mValue);
|
||||||
CreateCall(bindResult.mMethodInstance, bindResult.mFunc, false, bindResult.mIRArgs);
|
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)
|
void BfExprEvaluator::Visit(BfBoxExpression* boxExpr)
|
||||||
|
@ -17394,7 +17387,7 @@ void BfExprEvaluator::PerformBinaryOperation(BfAstNode* leftExpression, BfAstNod
|
||||||
|
|
||||||
if ((resultType->IsVar()) || (otherType->IsVar()))
|
if ((resultType->IsVar()) || (otherType->IsVar()))
|
||||||
{
|
{
|
||||||
mResult = BfTypedValue(mModule->GetDefaultValue(resultType), mModule->GetPrimitiveType(BfTypeCode_Var));
|
mResult = mModule->GetDefaultTypedValue(resultType);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1380,6 +1380,9 @@ BfTypedValue BfModule::GetFakeTypedValue(BfType* type)
|
||||||
|
|
||||||
BfTypedValue BfModule::GetDefaultTypedValue(BfType* type, bool allowRef, BfDefaultValueKind defaultValueKind)
|
BfTypedValue BfModule::GetDefaultTypedValue(BfType* type, bool allowRef, BfDefaultValueKind defaultValueKind)
|
||||||
{
|
{
|
||||||
|
if (type->IsVar())
|
||||||
|
return BfTypedValue(mBfIRBuilder->GetFakeVal(), type);
|
||||||
|
|
||||||
PopulateType(type, BfPopulateType_Data);
|
PopulateType(type, BfPopulateType_Data);
|
||||||
mBfIRBuilder->PopulateType(type, type->IsValueType() ? BfIRPopulateType_Full : BfIRPopulateType_Declaration);
|
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;
|
BfScopeData* scopeData = allocTarget.mScopeData;
|
||||||
|
|
||||||
|
BF_ASSERT(!type->IsVar());
|
||||||
|
|
||||||
auto typeInstance = type->ToTypeInstance();
|
auto typeInstance = type->ToTypeInstance();
|
||||||
if ((typeInstance == NULL) && (type->IsGenericParam()))
|
if ((typeInstance == NULL) && (type->IsGenericParam()))
|
||||||
typeInstance = mContext->mBfObjectType;
|
typeInstance = mContext->mBfObjectType;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue