Implements variable assignment evaluation
This commit is contained in:
@@ -2,8 +2,10 @@
|
||||
#include "Evaluator.hpp"
|
||||
#include "EvaluationException.hpp"
|
||||
#include "../Script.hpp"
|
||||
#include "EvaluationScope/EvaluationScope.hpp"
|
||||
|
||||
void Evaluator::Evaluate(BoundScriptStatement *statement) {
|
||||
this->_evaluationScope = new EvaluationScope(this->_scriptData->_scriptVariables, statement->GetDeepestScope());
|
||||
EvaluateBlockStatement(statement);
|
||||
}
|
||||
|
||||
@@ -12,6 +14,10 @@ void Evaluator::EvaluateStatement(BoundStatement *statement) {
|
||||
case BoundStatementKind ::Script: throw; // Should never happen
|
||||
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::Bad:
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +34,16 @@ void Evaluator::EvaluateExpressionStatement(BoundExpressionStatement *statement)
|
||||
this->_scriptData->_lastValue = this -> EvaluateExpression(statement->GetExpression());
|
||||
}
|
||||
|
||||
void Evaluator::EvaluateAssignmentStatement(BoundAssignmentStatement *statement) {
|
||||
auto value = this -> EvaluateExpression(statement->GetExpression());
|
||||
auto key = statement->GetKey();
|
||||
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()){
|
||||
|
||||
Reference in New Issue
Block a user