Support break statements
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -48,7 +48,9 @@ namespace Porygon::Evaluation {
|
||||
return this->EvaluateNumericalForStatement((BoundNumericalForStatement*)statement);
|
||||
case BoundStatementKind::GenericFor:
|
||||
return this-> EvaluateGenericForStatement((BoundGenericForStatement*)statement);
|
||||
|
||||
case BoundStatementKind::Break:
|
||||
this -> _hasBroken = true;
|
||||
return;
|
||||
case BoundStatementKind::Bad:
|
||||
throw;
|
||||
}
|
||||
@@ -138,20 +140,25 @@ namespace Porygon::Evaluation {
|
||||
this -> _evaluationScope -> SetVariable(identifier, make_shared<IntegerEvalValue>(i));
|
||||
for (auto s: *block->GetStatements()) {
|
||||
this->EvaluateStatement(s);
|
||||
if (this->_hasReturned)
|
||||
if (this->_hasReturned || this -> _hasBroken)
|
||||
break;
|
||||
}
|
||||
if (this->_hasReturned || this -> _hasBroken)
|
||||
break;
|
||||
}
|
||||
} else{
|
||||
for (long i = start; i >= end; i += step){
|
||||
this -> _evaluationScope -> SetVariable(identifier, make_shared<IntegerEvalValue>(i));
|
||||
for (auto s: *block->GetStatements()) {
|
||||
this->EvaluateStatement(s);
|
||||
if (this->_hasReturned)
|
||||
if (this->_hasReturned || this -> _hasBroken)
|
||||
break;
|
||||
}
|
||||
if (this->_hasReturned || this -> _hasBroken)
|
||||
break;
|
||||
}
|
||||
}
|
||||
this -> _hasBroken = false;
|
||||
}
|
||||
|
||||
void Evaluator::EvaluateGenericForStatement(const BoundGenericForStatement *statement) {
|
||||
@@ -172,8 +179,15 @@ namespace Porygon::Evaluation {
|
||||
auto currentValue = iteratorVal -> IndexValue(currentKey.get());
|
||||
this -> _evaluationScope -> SetVariable(valueVariable, currentValue);
|
||||
}
|
||||
this -> EvaluateBlockStatement(block);
|
||||
for (auto s: *block->GetStatements()) {
|
||||
this->EvaluateStatement(s);
|
||||
if (this->_hasReturned || this -> _hasBroken)
|
||||
break;
|
||||
}
|
||||
if (this->_hasReturned || this -> _hasBroken)
|
||||
break;
|
||||
}
|
||||
this -> _hasBroken = false;
|
||||
delete iterator;
|
||||
}
|
||||
|
||||
@@ -433,7 +447,7 @@ namespace Porygon::Evaluation {
|
||||
auto type = dynamic_pointer_cast<TableScriptType>(tableExpression->GetType());
|
||||
auto declaredVars = type->GetValues();
|
||||
auto variables = make_shared<map<Utilities::HashedString, shared_ptr<EvalValue>>>();
|
||||
for (auto i : *declaredVars) {
|
||||
for (const auto& i : *declaredVars) {
|
||||
variables->insert({i.first, nullptr});
|
||||
}
|
||||
auto evaluator = make_shared<EvaluationScope>(variables.get(), type->GetLocalVariableCount());
|
||||
|
||||
Reference in New Issue
Block a user