Private
Public Access
ValueStorage now removes stacks after lowering stack count
This commit is contained in:
1 parent
c7ab58d0bb
commit
8dffaa1326
1 file changed
+4
-9
+4
-9
@@ -6,16 +6,13 @@ namespace Advanced_Software_Engineering.Verbs.Value {
|
|||||||
|
|
||||||
protected int currentStack;
|
protected int currentStack;
|
||||||
protected Dictionary<int, Dictionary<string, IValue>> Variables = new Dictionary<int, Dictionary<string, IValue>>();
|
protected Dictionary<int, Dictionary<string, IValue>> Variables = new Dictionary<int, Dictionary<string, IValue>>();
|
||||||
protected List<IValue> VariableList = new List<IValue>();
|
|
||||||
|
|
||||||
public ValueStorage() {
|
public ValueStorage() {
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reset() {
|
public void Reset() {
|
||||||
//for every ivalue
|
|
||||||
Variables = new Dictionary<int, Dictionary<string, IValue>>();
|
Variables = new Dictionary<int, Dictionary<string, IValue>>();
|
||||||
//for (int index = 0; index < VariableList.Count; index++) VariableList[index] = null;
|
|
||||||
SetStack(0);
|
SetStack(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,21 +27,19 @@ namespace Advanced_Software_Engineering.Verbs.Value {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void DecreaseStack() {
|
public void DecreaseStack() {
|
||||||
|
if (currentStack > 0) {
|
||||||
|
Variables.Remove(currentStack);
|
||||||
currentStack--;
|
currentStack--;
|
||||||
SetStack(currentStack);
|
SetStack(currentStack);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void SetVariable(string name, int stack, IValue value) {
|
public void SetVariable(string name, int stack, IValue value) {
|
||||||
if (stack == 0) Variables[stack][name] = value;
|
if (stack == 0) Variables[stack][name] = value;
|
||||||
else {
|
else {
|
||||||
if (CheckVariableExists(name, stack)) Variables[stack][name] = value;
|
if (CheckVariableExists(name, stack)) Variables[stack][name] = value;
|
||||||
else if (CheckVariableExists(name, 0)) Variables[0][name] = value;
|
else if (CheckVariableExists(name, 0)) Variables[0][name] = value;
|
||||||
else// if(value == null) {
|
else Variables[stack][name] = value;
|
||||||
Variables[stack][name] = value;
|
|
||||||
//VariableList.Add(Variables[stack][name]);
|
|
||||||
//} else {
|
|
||||||
// throw new Exception("Tried setting a variable that was not declared");
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user