Implements setting table values
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -22,16 +22,16 @@ public:
|
||||
|
||||
virtual shared_ptr<EvalValue> Clone() = 0;
|
||||
|
||||
virtual long EvaluateInteger(){
|
||||
virtual long EvaluateInteger() const{
|
||||
throw EvaluationException("Can't evaluate this EvalValue as integer.");
|
||||
}
|
||||
virtual double EvaluateFloat(){
|
||||
virtual double EvaluateFloat() const{
|
||||
throw EvaluationException("Can't evaluate this EvalValue as float.");
|
||||
}
|
||||
virtual bool EvaluateBool(){
|
||||
virtual bool EvaluateBool() const{
|
||||
throw EvaluationException("Can't evaluate this EvalValue as bool.");
|
||||
}
|
||||
virtual std::string* EvaluateString(){
|
||||
virtual const std::string* EvaluateString() const {
|
||||
throw EvaluationException("Can't evaluate this EvalValue as string.");
|
||||
}
|
||||
|
||||
@@ -40,6 +40,10 @@ public:
|
||||
virtual shared_ptr<EvalValue> IndexValue(EvalValue* val){
|
||||
throw EvaluationException("Can't index this EvalValue");
|
||||
}
|
||||
|
||||
virtual void SetIndexValue(EvalValue *key, shared_ptr<EvalValue> value){
|
||||
throw EvaluationException("Can't index this EvalValue");
|
||||
}
|
||||
};
|
||||
|
||||
class BooleanEvalValue : public EvalValue{
|
||||
@@ -58,7 +62,7 @@ public:
|
||||
return TypeClass ::Bool;
|
||||
}
|
||||
|
||||
bool EvaluateBool() final{
|
||||
bool EvaluateBool() const final{
|
||||
return _value;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
long EvaluateInteger() final{
|
||||
long EvaluateInteger() const final{
|
||||
return _value;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
double EvaluateFloat() final{
|
||||
double EvaluateFloat() const final{
|
||||
return _value;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
return this->_hash == b->GetHashCode();
|
||||
};
|
||||
|
||||
string* EvaluateString() final{
|
||||
const string* EvaluateString() const final{
|
||||
return &_value;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,11 @@ public:
|
||||
auto hash = HashedString::ConstHash(val);
|
||||
return this -> _table -> at(hash);
|
||||
}
|
||||
|
||||
void SetIndexValue(EvalValue *key, shared_ptr<EvalValue> value) final{
|
||||
auto hash = key->GetHashCode();
|
||||
this -> _table->at(hash) = value;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -26,6 +26,8 @@ void Evaluator::EvaluateStatement(const 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::IndexAssignment:
|
||||
return this -> EvaluateIndexAssignmentStatement((BoundIndexAssignmentStatement*)statement);
|
||||
case BoundStatementKind ::FunctionDeclaration: return this->EvaluateFunctionDeclarationStatement((BoundFunctionDeclarationStatement*)statement);
|
||||
case BoundStatementKind::Return: return this -> EvaluateReturnStatement((BoundReturnStatement*)statement);
|
||||
case BoundStatementKind::Conditional: return this -> EvaluateConditionalStatement((BoundConditionalStatement*)statement);
|
||||
@@ -58,6 +60,15 @@ void Evaluator::EvaluateAssignmentStatement(const BoundAssignmentStatement *stat
|
||||
}
|
||||
}
|
||||
|
||||
void Evaluator::EvaluateIndexAssignmentStatement(const BoundIndexAssignmentStatement *statement) {
|
||||
auto indexExpression = statement -> GetIndexExpression();
|
||||
auto value = this -> EvaluateExpression(statement -> GetValueExpression());
|
||||
auto index = ((BoundIndexExpression*)indexExpression);
|
||||
auto table = this -> EvaluateExpression(index -> GetIndexableExpression());
|
||||
auto key = this -> EvaluateExpression(index->GetIndexExpression());
|
||||
table -> SetIndexValue(key.get(), value);
|
||||
}
|
||||
|
||||
void Evaluator::EvaluateFunctionDeclarationStatement(const BoundFunctionDeclarationStatement *statement) {
|
||||
auto type = statement->GetType();
|
||||
auto key = statement->GetKey();
|
||||
@@ -300,3 +311,4 @@ shared_ptr<EvalValue> Evaluator::EvaluateUserDataExpression(const BoundExpressio
|
||||
default: throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ class Evaluator {
|
||||
void EvaluateBlockStatement(const BoundBlockStatement *statement);
|
||||
void EvaluateExpressionStatement(const BoundExpressionStatement* statement);
|
||||
void EvaluateAssignmentStatement(const BoundAssignmentStatement* statement);
|
||||
void EvaluateIndexAssignmentStatement(const BoundIndexAssignmentStatement* statement);
|
||||
void EvaluateFunctionDeclarationStatement(const BoundFunctionDeclarationStatement *statement);
|
||||
void EvaluateReturnStatement(const BoundReturnStatement *statement);
|
||||
void EvaluateConditionalStatement(const BoundConditionalStatement *statement);
|
||||
|
||||
Reference in New Issue
Block a user