Fixes for return statement, make Evaluate function on script return value
Some checks reported errors
continuous-integration/drone/push Build was killed

This commit is contained in:
2019-06-12 18:45:47 +02:00
parent 3477ddd18c
commit 22149d9243
7 changed files with 31 additions and 16 deletions

View File

@@ -11,9 +11,10 @@
using namespace std;
void Evaluator::Evaluate(BoundScriptStatement *statement) {
EvalValue* Evaluator::Evaluate(BoundScriptStatement *statement) {
this->_evaluationScope = make_shared<EvaluationScope>(this->_scriptData->_scriptVariables, statement->GetDeepestScope());
EvaluateBlockStatement(statement, false);
return this -> _returnValue.get();
}
void Evaluator::EvaluateStatement(BoundStatement *statement) {
@@ -73,11 +74,12 @@ void Evaluator::EvaluateFunctionDeclarationStatement(BoundFunctionDeclarationSta
void Evaluator::EvaluateReturnStatement(BoundReturnStatement* statement){
auto expression = statement->GetExpression();
this->_hasReturned = true;
if (expression == nullptr){
this->_hasReturned = true;
return;
}
auto value = this -> EvaluateExpression(expression);
this->_hasReturned = true;
this -> _returnValue = value;
}

View File

@@ -47,6 +47,7 @@ class Evaluator {
shared_ptr<EvalValue> EvaluateFunctionCallExpression(BoundExpression *expression);
shared_ptr<EvalValue> EvaluateIndexExpression(BoundExpression* expression);
shared_ptr<EvalValue> EvaluateNumericTableExpression(BoundExpression* expression);
shared_ptr<EvalValue> EvaluateComplexTableExpression(BoundExpression *expression);
shared_ptr<EvalValue> GetVariable(BoundVariableExpression *expression);
public:
@@ -57,14 +58,13 @@ public:
_evaluationScope = nullptr;
}
void Evaluate(BoundScriptStatement* statement);
EvalValue* Evaluate(BoundScriptStatement* statement);
shared_ptr<EvalValue> EvaluateFunction(ScriptFunctionEvalValue* func, vector<EvalValue*> parameters);
EvalValue* GetLastValue(){
return _lastValue.get();
}
shared_ptr<EvalValue> EvaluateComplexTableExpression(BoundExpression *expression);
};