コード例 #1
0
        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);
        }
コード例 #2
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);
        }
コード例 #3
0
        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;
            }
        }
コード例 #4
0
        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(' ');
            }
        }
コード例 #5
0
        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;
            }
        }
コード例 #6
0
        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));
            }
        }
コード例 #7
0
        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;
            }
        }
コード例 #8
0
 private static void HandleDuplicate(ExecutionContext context)
 {
     context.EnsureStack(1);
     context.Values.Push(context.Values.Peek());
 }
コード例 #9
0
 private static void HandleNot(ExecutionContext context)
 {
     context.EnsureStack(1);
     context.Values.Push(context.Values.Pop() == 0 ? 1 : 0);
 }