Work on performance improvements
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2019-06-13 16:26:10 +02:00
parent e93bcab14d
commit 1cb65f17c9
19 changed files with 84 additions and 108 deletions

View File

@@ -1,3 +1,5 @@
#include <memory>
#include <utility>
#include <memory>
#include "Evaluator.hpp"
@@ -12,7 +14,7 @@
using namespace std;
EvalValue* Evaluator::Evaluate(BoundScriptStatement *statement) {
this->_evaluationScope = make_shared<EvaluationScope>(this->_scriptData->_scriptVariables, statement->GetDeepestScope());
this->_evaluationScope = make_shared<EvaluationScope>(this->_scriptData->_scriptVariables, statement->GetLocalVariableCount());
EvaluateBlockStatement(statement, false);
return this -> _returnValue.get();
}
@@ -223,10 +225,6 @@ shared_ptr<EvalValue> Evaluator::EvaluateFunctionCallExpression(BoundExpression*
for (int i = 0; i < parameterTypes.size() && i < parameterKeys.size() && i < parameters.size(); i++){
auto parameter = parameters[i];
auto requiredType = parameterTypes.at(i);
if (*parameter->GetType() != requiredType.get()){
throw EvaluationException("Passed wrong type to function.");
}
auto key = parameterKeys.at(i);
this->_evaluationScope->CreateVariable(key.get(), parameter->Clone());
}
@@ -249,10 +247,6 @@ shared_ptr<EvalValue> Evaluator::EvaluateFunction(ScriptFunctionEvalValue *funct
for (int i = 0; i < parameterTypes.size() && i < parameterKeys.size() && i < parameters.size(); i++){
auto parameter = parameters[i];
auto requiredType = parameterTypes.at(i);
if (*parameter->GetType() != requiredType.get()){
throw EvaluationException("Passed wrong type to function.");
}
auto key = parameterKeys.at(i);
this->_evaluationScope->CreateVariable(key.get(), parameter->Clone());
}
@@ -280,7 +274,7 @@ shared_ptr<EvalValue> Evaluator::EvaluateNumericTableExpression(BoundExpression
values -> insert({i + 1, val});
}
auto valuesPointer = shared_ptr<unordered_map<size_t, shared_ptr<EvalValue>>>(values);
return make_shared<TableEvalValue>(valuesPointer, tableExpression->GetType());
return make_shared<TableEvalValue>(valuesPointer);
}
shared_ptr<EvalValue> Evaluator::EvaluateComplexTableExpression(BoundExpression *expression) {
@@ -291,10 +285,10 @@ shared_ptr<EvalValue> Evaluator::EvaluateComplexTableExpression(BoundExpression
for (auto i : *declaredVars){
variables->insert({i.first, nullptr});
}
auto evaluator = make_shared<EvaluationScope>(variables.get(), type -> GetDeepestScope());
auto evaluator = make_shared<EvaluationScope>(variables.get(), type -> GetLocalVariableCount());
auto currentEvaluator = this -> _evaluationScope;
this -> _evaluationScope = evaluator;
this -> EvaluateBlockStatement(tableExpression->GetBlock(), false);
this -> _evaluationScope = currentEvaluator;
return shared_ptr<TableEvalValue>(new TableEvalValue(variables, tableExpression->GetType()));
return make_shared<TableEvalValue>(variables);
}