Rework of evaluation variable handling, to account for functions having branching variable states
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2019-06-08 18:33:56 +02:00
parent 4d452b33e0
commit 471632c6e4
4 changed files with 57 additions and 13 deletions

View File

@@ -4,7 +4,10 @@
EvaluationScope::EvaluationScope(unordered_map<int, shared_ptr<EvalValue>> *scriptVariables, int deepestScope) {
_scriptScope = scriptVariables;
_localScope = vector<unordered_map<int, shared_ptr<EvalValue>>>(deepestScope);
_localScope = vector<shared_ptr<unordered_map<int, shared_ptr<EvalValue>>>>(deepestScope);
for (int i = 0; i < deepestScope; i++){
_localScope[i] = make_shared<unordered_map<int, shared_ptr<EvalValue>>>();
}
_currentScope = -1;
}
@@ -12,7 +15,10 @@ void EvaluationScope::CreateVariable(int scope, int id, const shared_ptr<EvalVal
if (scope == 0){
_scriptScope->at(id) = value;
} else{
_localScope[scope - 1][id] = value;
auto insert = _localScope[scope - 1]->insert({id, value});
if (!insert.second){
_localScope[scope - 1]->at(id) = value;
}
}
}
@@ -20,7 +26,7 @@ void EvaluationScope::SetVariable(int scope, int id, const shared_ptr<EvalValue>
if (scope == 0){
_scriptScope->at(id) = value;
} else{
_localScope[scope - 1][id] = value;
_localScope[scope - 1]->at(id) = value;
}
}
@@ -28,11 +34,15 @@ shared_ptr<EvalValue> EvaluationScope::GetVariable(int scope, int id) {
if (scope == 0){
return _scriptScope->at(id);
}
return _localScope[scope - 1][id];
return _localScope[scope - 1]->at(id);
}
void EvaluationScope::JumpToScope(int index){
_currentScope = index;
EvaluationScope* EvaluationScope::CreateBranchingScope(int index){
auto scope = new EvaluationScope(this -> _scriptScope, this -> _localScope.size());
for (int i = 0; i < index; i++){
scope->_localScope[i] = this->_localScope[i];
}
return scope;
}
void EvaluationScope::OuterScope() {
@@ -41,7 +51,7 @@ void EvaluationScope::OuterScope() {
void EvaluationScope::InnerScope() {
auto scope = this->_localScope[_currentScope];
scope.clear();
scope->clear();
_currentScope--;
}