This commit is contained in:
arookas 2015-12-27 22:58:15 -05:00
parent 0794267ff0
commit 80c4c94b28

View file

@ -6,36 +6,37 @@ namespace arookas
{ {
class sunScopeStack : IEnumerable<sunScope> class sunScopeStack : IEnumerable<sunScope>
{ {
List<sunScope> stack = new List<sunScope>(8); List<sunScope> Stack { get; set; }
int GlobalCount { get { return stack.Where(i => i.Type == sunScopeType.Script).Sum(i => i.StorableCount); } } int GlobalCount { get { return Stack.Where(i => i.Type == sunScopeType.Script).Sum(i => i.StorableCount); } }
int LocalCount { get { return stack.Where(i => i.Type == sunScopeType.Function).Sum(i => i.StorableCount); } } int LocalCount { get { return Stack.Where(i => i.Type == sunScopeType.Function).Sum(i => i.StorableCount); } }
public int Count { get { return stack.Count; } } public int Count { get { return Stack.Count; } }
public sunScope Root { get { return this[0]; } } public sunScope Root { get { return this[0]; } }
public sunScope Top { get { return this[Count - 1]; } } public sunScope Top { get { return this[Count - 1]; } }
public sunScope this[int index] { get { return stack[index]; } } public sunScope this[int index] { get { return Stack[index]; } }
public sunScopeStack() public sunScopeStack()
{ {
Stack = new List<sunScope>(8);
Push(sunScopeType.Script); // push global scope Push(sunScopeType.Script); // push global scope
} }
public void Push(sunScopeType type) public void Push(sunScopeType type)
{ {
stack.Add(new sunScope(type)); Stack.Add(new sunScope(type));
} }
public void Pop() public void Pop()
{ {
if (Count > 1) if (Count > 1)
{ {
stack.RemoveAt(Count - 1); Stack.RemoveAt(Count - 1);
} }
} }
public void Clear() public void Clear()
{ {
stack.Clear(); Stack.Clear();
Push(sunScopeType.Script); // add global scope Push(sunScopeType.Script); // add global scope
} }
@ -71,7 +72,7 @@ namespace arookas
return variableInfo; return variableInfo;
} }
public IEnumerator<sunScope> GetEnumerator() { return stack.GetEnumerator(); } public IEnumerator<sunScope> GetEnumerator() { return Stack.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
} }