Files
PorygonLang/src/Evaluator/EvaluationScope/EvaluationScope.cpp
Deukhoofd e93bcab14d
All checks were successful
continuous-integration/drone/push Build is passing
Changed references of u_int64_t to uint64_t, to account for mingw
2019-06-13 15:31:48 +02:00

35 lines
1.1 KiB
C++

#include "EvaluationScope.hpp"
#include <memory>
EvaluationScope::EvaluationScope(unordered_map<size_t, shared_ptr<EvalValue>> *scriptVariables, int deepestScope) {
_scriptScope = scriptVariables;
_localScope = unordered_map<uint64_t, shared_ptr<EvalValue>>(deepestScope);
}
void EvaluationScope::CreateVariable(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(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(BoundVariableKey* key) {
if (key->GetScopeId() == 0){
return _scriptScope -> at(key->GetIdentifier());
} else{
return _localScope[key->GetHash()];
}
}