using System.Collections.Generic; namespace OpenVIII.Fields.Scripts { public static partial class Jsm { #region Classes public sealed class LabeledStack : IStack { #region Fields private readonly Dictionary _positions = new Dictionary(); private readonly Stack _stack = new Stack(); #endregion Fields #region Properties public int Count => _stack.Count; public int CurrentLabel { get; set; } #endregion Properties #region Methods public IJsmExpression Peek() => _stack.Peek(); public bool StackEmpty() => _stack == null || _stack.Count <= 0; public IJsmExpression Pop() { //if (_stack == null || _stack.Count <= 0) return default; var result = _stack.Pop(); CurrentLabel = _positions[result]; _positions.Remove(result); return result; } public void Push(IJsmExpression item) { _positions.Add(item, CurrentLabel); _stack.Push(item); } #endregion Methods } #endregion Classes } }