ValueStorage now removes stacks after lowering stack count

This commit is contained in:
Lukasz Baldyga committed 2020-12-02 22:16:42 +00:00
1 parent c7ab58d0bb
commit 8dffaa1326
1 file changed
+4 -9
@@ -6,16 +6,13 @@ namespace Advanced_Software_Engineering.Verbs.Value {
protected int currentStack;
protected Dictionary<int, Dictionary<string, IValue>> Variables = new Dictionary<int, Dictionary<string, IValue>>();
protected List<IValue> VariableList = new List<IValue>();
public ValueStorage() {
Reset();
}
public void Reset() {
//for every ivalue
Variables = new Dictionary<int, Dictionary<string, IValue>>();
//for (int index = 0; index < VariableList.Count; index++) VariableList[index] = null;
SetStack(0);
}
@@ -30,21 +27,19 @@ namespace Advanced_Software_Engineering.Verbs.Value {
}
public void DecreaseStack() {
if (currentStack > 0) {
Variables.Remove(currentStack);
currentStack--;
SetStack(currentStack);
}
}
public void SetVariable(string name, int stack, IValue value) {
if (stack == 0) Variables[stack][name] = value;
else {
if (CheckVariableExists(name, stack)) Variables[stack][name] = value;
else if (CheckVariableExists(name, 0)) Variables[0][name] = value;
else// if(value == null) {
Variables[stack][name] = value;
//VariableList.Add(Variables[stack][name]);
//} else {
// throw new Exception("Tried setting a variable that was not declared");
//}
else Variables[stack][name] = value;
}
}