mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-13 22:04:09 +02:00
Reverted for (int i < j)
to reevaluate j
on every iteration
This commit is contained in:
parent
f1d9964ba1
commit
42580df269
2 changed files with 12 additions and 6 deletions
|
@ -5738,6 +5738,10 @@ void BfModule::DoForLess(BfForEachStatement* forEachStmt)
|
||||||
{
|
{
|
||||||
UpdateSrcPos(forEachStmt);
|
UpdateSrcPos(forEachStmt);
|
||||||
|
|
||||||
|
auto startBB = mBfIRBuilder->GetInsertBlock();
|
||||||
|
auto condBB = mBfIRBuilder->CreateBlock("forless.cond", true);
|
||||||
|
mBfIRBuilder->SetInsertPoint(condBB);
|
||||||
|
|
||||||
BfScopeData scopeData;
|
BfScopeData scopeData;
|
||||||
// We set mIsLoop later
|
// We set mIsLoop later
|
||||||
if (forEachStmt->mLabelNode != NULL)
|
if (forEachStmt->mLabelNode != NULL)
|
||||||
|
@ -5800,6 +5804,9 @@ void BfModule::DoForLess(BfForEachStatement* forEachStmt)
|
||||||
target = GetDefaultTypedValue(varType);
|
target = GetDefaultTypedValue(varType);
|
||||||
}
|
}
|
||||||
PopulateType(varType, BfPopulateType_Data);
|
PopulateType(varType, BfPopulateType_Data);
|
||||||
|
|
||||||
|
auto condEndBB = mBfIRBuilder->GetInsertBlock();
|
||||||
|
mBfIRBuilder->SetInsertPoint(startBB);
|
||||||
|
|
||||||
BfLocalVariable* localDef = new BfLocalVariable();
|
BfLocalVariable* localDef = new BfLocalVariable();
|
||||||
localDef->mNameNode = BfNodeDynCast<BfIdentifierNode>(forEachStmt->mVariableName);
|
localDef->mNameNode = BfNodeDynCast<BfIdentifierNode>(forEachStmt->mVariableName);
|
||||||
|
@ -5822,8 +5829,7 @@ void BfModule::DoForLess(BfForEachStatement* forEachStmt)
|
||||||
localDef->Init();
|
localDef->Init();
|
||||||
UpdateExprSrcPos(forEachStmt->mVariableName);
|
UpdateExprSrcPos(forEachStmt->mVariableName);
|
||||||
AddLocalVariableDef(localDef, true);
|
AddLocalVariableDef(localDef, true);
|
||||||
|
|
||||||
auto condBB = mBfIRBuilder->CreateBlock("forless.cond", true);
|
|
||||||
auto bodyBB = mBfIRBuilder->CreateBlock("forless.body");
|
auto bodyBB = mBfIRBuilder->CreateBlock("forless.body");
|
||||||
auto incBB = mBfIRBuilder->CreateBlock("forless.inc");
|
auto incBB = mBfIRBuilder->CreateBlock("forless.inc");
|
||||||
auto endBB = mBfIRBuilder->CreateBlock("forless.end");
|
auto endBB = mBfIRBuilder->CreateBlock("forless.end");
|
||||||
|
@ -5837,7 +5843,7 @@ void BfModule::DoForLess(BfForEachStatement* forEachStmt)
|
||||||
SetAndRestoreValue<BfBreakData*> prevBreakData(mCurMethodState->mBreakData, &breakData);
|
SetAndRestoreValue<BfBreakData*> prevBreakData(mCurMethodState->mBreakData, &breakData);
|
||||||
|
|
||||||
mBfIRBuilder->CreateBr(condBB);
|
mBfIRBuilder->CreateBr(condBB);
|
||||||
mBfIRBuilder->SetInsertPoint(condBB);
|
mBfIRBuilder->SetInsertPoint(condEndBB);
|
||||||
if (forEachStmt->mCollectionExpression != NULL)
|
if (forEachStmt->mCollectionExpression != NULL)
|
||||||
UpdateExprSrcPos(forEachStmt->mCollectionExpression);
|
UpdateExprSrcPos(forEachStmt->mCollectionExpression);
|
||||||
BfIRValue conditionValue;
|
BfIRValue conditionValue;
|
||||||
|
|
|
@ -32,7 +32,7 @@ namespace Tests
|
||||||
|
|
||||||
static int GetVal()
|
static int GetVal()
|
||||||
{
|
{
|
||||||
return 10 + sGetValCount++;
|
return 10 + sGetValCount++ / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -70,8 +70,8 @@ namespace Tests
|
||||||
{
|
{
|
||||||
iterations++;
|
iterations++;
|
||||||
}
|
}
|
||||||
Test.Assert(iterations == 10);
|
Test.Assert(iterations == 19);
|
||||||
Test.Assert(sGetValCount == 1);
|
Test.Assert(sGetValCount == 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void TestEnumerator1(EnumeratorTest e)
|
public static void TestEnumerator1(EnumeratorTest e)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue