private static void HandleGreaterThan(ExecutionContext context)
        {
            context.EnsureStack(2);
            var a = context.Values.Pop();
            var b = context.Values.Pop();

            context.Values.Push(b > a ? 1 : 0);
        }
        private static void HandleSwap(ExecutionContext context)
        {
            context.EnsureStack(2);

            var a = context.Values.Pop();
            var b = context.Values.Pop();

            context.Values.Push(a);
            context.Values.Push(b);
        }
        internal override void OnHandle(ExecutionContext context)
        {
            context.EnsureStack(1);

            switch (context.Current.Value)
            {
                case TurnInstructionHandler.LeftRightInstruction:
                    context.Direction = context.Values.Pop() == 0 ? Direction.Right : Direction.Left;
                    break;
                case TurnInstructionHandler.UpDownInstruction:
                    context.Direction = context.Values.Pop() == 0 ? Direction.Down : Direction.Up;
                    break;
            }
        }
        private static void HandleGet(ExecutionContext context)
        {
            context.EnsureStack(2);
            var y = context.Values.Pop();
            var x = context.Values.Pop();
            var target = context.Find(new Point(x, y));

            if (target != null)
            {
                context.Values.Push(target.Value);
            }
            else
            {
                context.Values.Push(' ');
            }
        }
        internal override void OnHandle(ExecutionContext context)
        {
            context.EnsureStack(1);

            switch (context.Current.Value)
            {
                case OutputInstructionHandler.AsciiInstruction:
                    context.Writer.Write(Convert.ToChar(
                        context.Values.Pop()));
                    break;
                case OutputInstructionHandler.NumericInstruction:
                    context.Writer.Write(
                        context.Values.Pop().ToString(CultureInfo.CurrentCulture));
                    break;
            }
        }
        private static void HandlePut(ExecutionContext context)
        {
            context.EnsureStack(3);
            var y = context.Values.Pop();
            var x = context.Values.Pop();
            var value = Convert.ToChar(context.Values.Pop());

            var location = new Point(x, y);
            var target = context.Find(location);

            if (target != null)
            {
                context.Cells[context.Cells.IndexOf(target)] = new Cell(location, value);
            }
            else if (value != ' ')
            {
                context.Cells.Add(new Cell(location, value));
            }
        }
        internal override void OnHandle(ExecutionContext context)
        {
            context.EnsureStack(2);

            switch (context.Current.Value)
            {
                case MathInstructionHandler.AddInstruction:
                    MathInstructionHandler.HandleAddition(context);
                    break;
                case MathInstructionHandler.SubtractInstruction:
                    MathInstructionHandler.HandleSubtraction(context);
                    break;
                case MathInstructionHandler.MultiplyInstruction:
                    MathInstructionHandler.HandleMultiplication(context);
                    break;
                case MathInstructionHandler.DivideInstruction:
                    MathInstructionHandler.HandleDivision(context);
                    break;
                case MathInstructionHandler.ModInstruction:
                    MathInstructionHandler.HandleModulo(context);
                    break;
            }
        }
 private static void HandleDuplicate(ExecutionContext context)
 {
     context.EnsureStack(1);
     context.Values.Push(context.Values.Peek());
 }
 private static void HandleNot(ExecutionContext context)
 {
     context.EnsureStack(1);
     context.Values.Push(context.Values.Pop() == 0 ? 1 : 0);
 }