using System; using System.Collections.Generic; using System.Linq; using System.Collections; namespace Cosmos.Compiler.Assembler { public class StackContents: IEnumerable { #region class Item public sealed class Item { public Item(int aSize) { Size = aSize; } public Item(int aSize, Type aType) : this(aSize) { IsNumber = (aType == typeof(byte) || aType == typeof(sbyte) || aType == typeof(Boolean) || aType == typeof(short) || aType == typeof(ushort) || aType == typeof(int) || aType == typeof(uint) || aType == typeof(long) || aType == typeof(ulong) || aType == typeof(Single) || aType == typeof(Double)); IsFloat = (aType == typeof(Single) || aType == typeof(Double)); IsSigned = (aType == typeof(sbyte) || aType == typeof(short) || aType == typeof(int) || aType == typeof(long) || aType == typeof(Single) || aType == typeof(Double)); ContentType = aType; } public Item(int aSize, bool aIsNumber, bool aIsFloat, bool aIsSigned) : this(aSize) { IsNumber = aIsNumber; IsFloat = aIsFloat; IsSigned = aIsSigned; } public readonly int Size; public readonly bool IsNumber = false; public readonly bool IsFloat = false; public readonly bool IsSigned = false; public readonly Type ContentType = null; public readonly bool IsBox = false; } #endregion public StackContents() { } private Stack mStack = new Stack(); public int Count { get { return mStack.Count; } } public Item Peek() { return mStack.Peek(); } public void Clear() { mStack.Clear(); } public Item Pop() { return mStack.Pop(); } public void Push(Item aItem) { mStack.Push(aItem); } public void Push(int aSize) { mStack.Push(new Item(aSize)); } public void Push(int aSize, Type aType) { mStack.Push(new Item(aSize, aType)); } public void Push(int aSize, bool aIsNumber, bool aIsFloat, bool aIsSigned) { mStack.Push(new Item(aSize, aIsNumber, aIsFloat, aIsSigned)); } public IEnumerator GetEnumerator() { foreach (var item in mStack) { yield return item; } } IEnumerator IEnumerable.GetEnumerator() { foreach (var xItem in mStack) { yield return xItem; } } } }