Implements binding and evaluating function declarations

This commit is contained in:
2019-06-01 12:33:52 +02:00
parent c407ba2f50
commit 6936b26cae
11 changed files with 215 additions and 10 deletions

View File

@@ -3,6 +3,7 @@
#include "EvaluationException.hpp"
#include "../Script.hpp"
#include "EvaluationScope/EvaluationScope.hpp"
#include "EvalValues/ScriptFunctionEvalValue.hpp"
void Evaluator::Evaluate(BoundScriptStatement *statement) {
this->_evaluationScope = new EvaluationScope(this->_scriptData->_scriptVariables, statement->GetDeepestScope());
@@ -15,6 +16,7 @@ void Evaluator::EvaluateStatement(BoundStatement *statement) {
case BoundStatementKind ::Block: return this -> EvaluateBlockStatement((BoundBlockStatement*)statement);
case BoundStatementKind ::Expression: return this -> EvaluateExpressionStatement((BoundExpressionStatement*)statement);
case BoundStatementKind ::Assignment: return this -> EvaluateAssignmentStatement((BoundAssignmentStatement*)statement);
case BoundStatementKind ::FunctionDeclaration: return this->EvaluateFunctionDeclarationStatement((BoundFunctionDeclarationStatement*)statement);
case BoundStatementKind::Bad:
throw;
@@ -46,6 +48,18 @@ void Evaluator::EvaluateAssignmentStatement(BoundAssignmentStatement *statement)
}
}
void Evaluator::EvaluateFunctionDeclarationStatement(BoundFunctionDeclarationStatement *statement) {
auto type = statement->GetType();
auto key = statement->GetKey();
auto block = statement->GetBlock();
auto value = new ScriptFunctionEvalValue(block, *type);
if (key->IsCreation()){
this->_evaluationScope->CreateVariable(key->GetScopeId(), key->GetIdentifier(), value);
} else{
this->_evaluationScope->SetVariable(key->GetScopeId(), key->GetIdentifier(), value);
}
}
EvalValue *Evaluator::EvaluateExpression(BoundExpression *expression) {
auto type = expression -> GetType();
switch (type->GetClass()){