mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-19 00:20:25 +02:00
Added <= support for 'for less'
This commit is contained in:
parent
f4c252048e
commit
7e55369f92
2 changed files with 14 additions and 7 deletions
|
@ -2803,7 +2803,7 @@ BfForEachStatement* BfReducer::CreateForEachStatement(BfAstNode* node, bool hasT
|
||||||
|
|
||||||
if (auto nextNode = BfNodeDynCast<BfTokenNode>(mVisitorPos.GetNext()))
|
if (auto nextNode = BfNodeDynCast<BfTokenNode>(mVisitorPos.GetNext()))
|
||||||
{
|
{
|
||||||
if (nextNode->mToken == BfToken_LParen)
|
if ((nextNode->mToken == BfToken_LParen) || (nextNode->mToken == BfToken_LessEquals))
|
||||||
{
|
{
|
||||||
mVisitorPos.MoveNext();
|
mVisitorPos.MoveNext();
|
||||||
auto tupleNode = CreateTupleExpression(nextNode);
|
auto tupleNode = CreateTupleExpression(nextNode);
|
||||||
|
@ -2816,7 +2816,7 @@ BfForEachStatement* BfReducer::CreateForEachStatement(BfAstNode* node, bool hasT
|
||||||
auto name = ExpectIdentifierAfter(forEachStatement, "variable name");
|
auto name = ExpectIdentifierAfter(forEachStatement, "variable name");
|
||||||
MEMBER_SET_CHECKED(forEachStatement, mVariableName, name);
|
MEMBER_SET_CHECKED(forEachStatement, mVariableName, name);
|
||||||
}
|
}
|
||||||
auto inToken = ExpectTokenAfter(forEachStatement, BfToken_In, BfToken_LChevron);
|
auto inToken = ExpectTokenAfter(forEachStatement, BfToken_In, BfToken_LChevron, BfToken_LessEquals);
|
||||||
MEMBER_SET_CHECKED(forEachStatement, mInToken, inToken);
|
MEMBER_SET_CHECKED(forEachStatement, mInToken, inToken);
|
||||||
auto expr = CreateExpressionAfter(forEachStatement);
|
auto expr = CreateExpressionAfter(forEachStatement);
|
||||||
MEMBER_SET_CHECKED(forEachStatement, mCollectionExpression, expr);
|
MEMBER_SET_CHECKED(forEachStatement, mCollectionExpression, expr);
|
||||||
|
@ -2930,7 +2930,7 @@ BfStatement* BfReducer::CreateForStatement(BfAstNode* node)
|
||||||
if (tokenNode != NULL)
|
if (tokenNode != NULL)
|
||||||
{
|
{
|
||||||
int token = tokenNode->GetToken();
|
int token = tokenNode->GetToken();
|
||||||
if ((token == BfToken_In) || (token == BfToken_LChevron))
|
if ((token == BfToken_In) || (token == BfToken_LChevron) || (token == BfToken_LessEquals))
|
||||||
{
|
{
|
||||||
mVisitorPos.mReadPos = startReadIdx;
|
mVisitorPos.mReadPos = startReadIdx;
|
||||||
return CreateForEachStatement(node, true);
|
return CreateForEachStatement(node, true);
|
||||||
|
|
|
@ -5219,10 +5219,13 @@ void BfModule::DoForLess(BfForEachStatement* forEachStmt)
|
||||||
if (varType == NULL)
|
if (varType == NULL)
|
||||||
varType = GetPrimitiveType(BfTypeCode_IntPtr);
|
varType = GetPrimitiveType(BfTypeCode_IntPtr);
|
||||||
|
|
||||||
if (!varType->IsIntegral())
|
BfType* checkType = varType;
|
||||||
|
if (checkType->IsTypedPrimitive())
|
||||||
|
checkType = checkType->GetUnderlyingType();
|
||||||
|
if (!checkType->IsIntegral())
|
||||||
{
|
{
|
||||||
Fail(StrFormat("Cannot iterate over '%s' in for-less statements, only integer types are allowed", TypeToString(varType).c_str()), forEachStmt->mVariableTypeRef);
|
Fail(StrFormat("Cannot iterate over '%s' in for-less statements, only integer types are allowed", TypeToString(varType).c_str()), forEachStmt->mVariableTypeRef);
|
||||||
varType = GetPrimitiveType(BfTypeCode_Int32);
|
varType = GetPrimitiveType(BfTypeCode_IntPtr);
|
||||||
if (didInference)
|
if (didInference)
|
||||||
target = GetDefaultTypedValue(varType);
|
target = GetDefaultTypedValue(varType);
|
||||||
}
|
}
|
||||||
|
@ -5283,7 +5286,10 @@ void BfModule::DoForLess(BfForEachStatement* forEachStmt)
|
||||||
// Soldier on
|
// Soldier on
|
||||||
target = GetDefaultTypedValue(varType);
|
target = GetDefaultTypedValue(varType);
|
||||||
}
|
}
|
||||||
conditionValue = mBfIRBuilder->CreateCmpLT(localVal, target.mValue, varType->IsSigned());
|
if (forEachStmt->mInToken->mToken == BfToken_LessEquals)
|
||||||
|
conditionValue = mBfIRBuilder->CreateCmpLTE(localVal, target.mValue, varType->IsSigned());
|
||||||
|
else
|
||||||
|
conditionValue = mBfIRBuilder->CreateCmpLT(localVal, target.mValue, varType->IsSigned());
|
||||||
mBfIRBuilder->CreateCondBr(conditionValue, bodyBB, endBB);
|
mBfIRBuilder->CreateCondBr(conditionValue, bodyBB, endBB);
|
||||||
ValueScopeEnd(valueScopeStart);
|
ValueScopeEnd(valueScopeStart);
|
||||||
|
|
||||||
|
@ -5331,7 +5337,8 @@ void BfModule::DoForLess(BfForEachStatement* forEachStmt)
|
||||||
|
|
||||||
void BfModule::Visit(BfForEachStatement* forEachStmt)
|
void BfModule::Visit(BfForEachStatement* forEachStmt)
|
||||||
{
|
{
|
||||||
if ((forEachStmt->mInToken != NULL) && (forEachStmt->mInToken->GetToken() == BfToken_LChevron))
|
if ((forEachStmt->mInToken != NULL) &&
|
||||||
|
((forEachStmt->mInToken->GetToken() == BfToken_LChevron) || (forEachStmt->mInToken->GetToken() == BfToken_LessEquals)))
|
||||||
{
|
{
|
||||||
DoForLess(forEachStmt);
|
DoForLess(forEachStmt);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue