Implements variable usage, tweaks and fixes for variable assignment

This commit is contained in:
2019-05-30 15:23:48 +02:00
parent 257eb942c7
commit 6fad5a0a7d
17 changed files with 145 additions and 4 deletions

View File

@@ -4,6 +4,7 @@
EvaluationScope::EvaluationScope(unordered_map<int, EvalValue *> *scriptVariables, int deepestScope) {
_scriptScope = scriptVariables;
_localScope = vector<unordered_map<int, EvalValue*>>(deepestScope);
_currentScope = -1;
}
EvaluationScope::~EvaluationScope() {
@@ -27,5 +28,21 @@ void EvaluationScope::SetVariable(int scope, int id, EvalValue *value) {
}
EvalValue *EvaluationScope::GetVariable(int scope, int id) {
if (scope == 0){
return _scriptScope->at(id);
}
return _localScope[scope - 1][id];
}
void EvaluationScope::OuterScope() {
_currentScope++;
}
void EvaluationScope::InnerScope() {
auto scope = this->_localScope[_currentScope];
for (auto v: scope){
delete v.second;
}
_currentScope--;
}