Files
PorygonLang/src/Evaluator/EvaluationScope/EvaluationScope.cpp
Deukhoofd 76b8ba3ebc
Some checks failed
continuous-integration/drone/push Build is failing
Initial work on iterators, rework of variable handling by including actual string
2019-06-23 15:58:14 +02:00

38 lines
1.3 KiB
C++

#include "EvaluationScope.hpp"
#include <memory>
namespace Porygon::Evaluation {
EvaluationScope::EvaluationScope(map<Utilities::HashedString, shared_ptr<EvalValue>> *scriptVariables,
int localVariableCount) {
_scriptScope = scriptVariables;
_localScope = map<uint64_t, shared_ptr<EvalValue>>();
}
void EvaluationScope::CreateVariable(const BoundVariableKey *key, const shared_ptr<EvalValue> &value) {
if (key->GetScopeId() == 0) {
_scriptScope->at(key->GetIdentifier()) = value;
} else {
auto insert = _localScope.insert({key->GetHash(), value});
if (!insert.second) {
_localScope[key->GetHash()] = value;
}
}
}
void EvaluationScope::SetVariable(const BoundVariableKey *key, const shared_ptr<EvalValue> &value) {
if (key->GetScopeId() == 0) {
_scriptScope->at(key->GetIdentifier()) = value;
} else {
_localScope[key->GetHash()] = value;
}
}
shared_ptr<EvalValue> EvaluationScope::GetVariable(const BoundVariableKey *key) {
if (key->GetScopeId() == 0) {
return _scriptScope->at(key->GetIdentifier());
} else {
return _localScope[key->GetHash()];
}
}
}