Exemplo n.º 1
0
        public void Roll()
        {
            FInteger     index      = new FInteger(BitConverter.ToInt32(_stack.Pop().Bytes, 0));
            Stack <Cell> savedCells = new Stack <Cell>();

            for (int i = 0; i < index.Value; i++)
            {
                savedCells.Push(this.Pop());
            }

            Cell rolledCell = this.Pop();

            while (savedCells.Count > 0)
            {
                this.Push(savedCells.Pop());
            }

            this.Push(rolledCell);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Performs a mathematical function. Most functions will pop two items from the stack, perform the operation
        /// and push the result
        /// </summary>
        /// <param name="token">String containing the mathematical operator</param>
        public void IntMaths(string token)
        {
            FInteger intConstant1 = new FInteger(BitConverter.ToInt32(_stack.Pop().Bytes, 0));

            if (token.Equals(Constants.Not))
            {
                _stack.Push(new Cell(
                                new FInteger(intConstant1.Value != Constants.True ? Constants.True : Constants.False).GetBytes()));
                return;
            }

            FInteger intConstant2 = new FInteger(BitConverter.ToInt32(_stack.Pop().Bytes, 0));

            if (token.Equals(Constants.Add))
            {
                _stack.Push(new Cell(new FInteger(intConstant1.Value + intConstant2.Value).GetBytes()));
            }
            else if (token.Equals(Constants.Subtract))
            {
                _stack.Push(new Cell(new FInteger(intConstant2.Value - intConstant1.Value).GetBytes()));
            }
            else if (token.Equals(Constants.Multiply))
            {
                _stack.Push(new Cell(new FInteger(intConstant2.Value * intConstant1.Value).GetBytes()));
            }
            else if (token.Equals(Constants.Divide))
            {
                _stack.Push(new Cell(new FInteger(intConstant2.Value / intConstant1.Value).GetBytes()));
            }
            else if (token.Equals(Constants.Modulus))
            {
                _stack.Push(new Cell(new FInteger(intConstant2.Value % intConstant1.Value).GetBytes()));
            }
            else if (token.Equals(Constants.GreaterThan))
            {
                _stack.Push(new Cell(
                                new FInteger(intConstant1.Value > intConstant2.Value ? Constants.True : Constants.False)
                                .GetBytes()));
            }
            else if (token.Equals(Constants.GreaterThanOrEqual))
            {
                _stack.Push(new Cell(
                                new FInteger(intConstant1.Value >= intConstant2.Value ? Constants.True : Constants.False)
                                .GetBytes()));
            }
            else if (token.Equals(Constants.LessThan))
            {
                _stack.Push(new Cell(
                                new FInteger(intConstant1.Value < intConstant2.Value ? Constants.True : Constants.False)
                                .GetBytes()));
            }
            else if (token.Equals(Constants.LessThanOrEqual))
            {
                _stack.Push(new Cell(
                                new FInteger(intConstant1.Value <= intConstant2.Value ? Constants.True : Constants.False)
                                .GetBytes()));
            }
            else if (token.Equals(Constants.Equal))
            {
                _stack.Push(new Cell(
                                new FInteger(intConstant1.Value == intConstant2.Value ? Constants.True : Constants.False)
                                .GetBytes()));
            }
            else if (token.Equals(Constants.NotEqual))
            {
                _stack.Push(new Cell(
                                new FInteger(intConstant1.Value != intConstant2.Value ? Constants.True : Constants.False)
                                .GetBytes()));
            }
            else if (token.Equals(Constants.And))
            {
                _stack.Push(new Cell(
                                new FInteger(intConstant1.Value == Constants.True && intConstant2.Value == Constants.True
                        ? Constants.True
                        : Constants.False).GetBytes()));
            }
            else if (token.Equals(Constants.Or))
            {
                _stack.Push(new Cell(
                                new FInteger(intConstant1.Value == Constants.True || intConstant2.Value == Constants.True
                        ? Constants.True
                        : Constants.False).GetBytes()));
            }
        }