1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 20:42:21 +02:00

Reverted for (int i < j) to reevaluate j on every iteration

This commit is contained in:
Brian Fiete 2021-07-20 12:28:23 -07:00
parent f1d9964ba1
commit 42580df269
2 changed files with 12 additions and 6 deletions

View file

@ -5738,6 +5738,10 @@ void BfModule::DoForLess(BfForEachStatement* forEachStmt)
{
UpdateSrcPos(forEachStmt);
auto startBB = mBfIRBuilder->GetInsertBlock();
auto condBB = mBfIRBuilder->CreateBlock("forless.cond", true);
mBfIRBuilder->SetInsertPoint(condBB);
BfScopeData scopeData;
// We set mIsLoop later
if (forEachStmt->mLabelNode != NULL)
@ -5800,6 +5804,9 @@ void BfModule::DoForLess(BfForEachStatement* forEachStmt)
target = GetDefaultTypedValue(varType);
}
PopulateType(varType, BfPopulateType_Data);
auto condEndBB = mBfIRBuilder->GetInsertBlock();
mBfIRBuilder->SetInsertPoint(startBB);
BfLocalVariable* localDef = new BfLocalVariable();
localDef->mNameNode = BfNodeDynCast<BfIdentifierNode>(forEachStmt->mVariableName);
@ -5822,8 +5829,7 @@ void BfModule::DoForLess(BfForEachStatement* forEachStmt)
localDef->Init();
UpdateExprSrcPos(forEachStmt->mVariableName);
AddLocalVariableDef(localDef, true);
auto condBB = mBfIRBuilder->CreateBlock("forless.cond", true);
auto bodyBB = mBfIRBuilder->CreateBlock("forless.body");
auto incBB = mBfIRBuilder->CreateBlock("forless.inc");
auto endBB = mBfIRBuilder->CreateBlock("forless.end");
@ -5837,7 +5843,7 @@ void BfModule::DoForLess(BfForEachStatement* forEachStmt)
SetAndRestoreValue<BfBreakData*> prevBreakData(mCurMethodState->mBreakData, &breakData);
mBfIRBuilder->CreateBr(condBB);
mBfIRBuilder->SetInsertPoint(condBB);
mBfIRBuilder->SetInsertPoint(condEndBB);
if (forEachStmt->mCollectionExpression != NULL)
UpdateExprSrcPos(forEachStmt->mCollectionExpression);
BfIRValue conditionValue;

View file

@ -32,7 +32,7 @@ namespace Tests
static int GetVal()
{
return 10 + sGetValCount++;
return 10 + sGetValCount++ / 2;
}
[Test]
@ -70,8 +70,8 @@ namespace Tests
{
iterations++;
}
Test.Assert(iterations == 10);
Test.Assert(sGetValCount == 1);
Test.Assert(iterations == 19);
Test.Assert(sGetValCount == 20);
}
public static void TestEnumerator1(EnumeratorTest e)