Exemplo n.º 1
0
        /// <summary>
        /// Pops two compatible arithmetic arguments from the execution stack.
        /// </summary>
        /// <param name="flags">The conversion flags.</param>
        /// <param name="left">The left operand.</param>
        /// <param name="right">The right operand.</param>
        /// <returns>The type of the two operands.</returns>
        public void PopArithmeticArgs(ConvertFlags flags, out Value left, out Value right)
        {
            right = PopCompareOrArithmeticValue(flags);
            left  = PopCompareOrArithmeticValue(flags);

            Value result;
            bool  swapped = Utilities.Swap(
                left.BasicValueType < right.BasicValueType,
                ref left,
                ref right);

            switch (left.BasicValueType)
            {
            case BasicValueType.Int1:
            case BasicValueType.Int32:
            case BasicValueType.Int64:
            case BasicValueType.Float32:
            case BasicValueType.Float64:
                result = Convert(right, left.Type, flags);
                break;

            default:
                throw CodeGenerator.GetNotSupportedException(
                          ErrorMessages.NotSupportedArithmeticOperandTypes,
                          left.BasicValueType,
                          right.BasicValueType);
            }
            Debug.Assert(result != null);
            right = result;

            Utilities.Swap(swapped, ref left, ref right);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Pops an element as integer from the stack.
        /// </summary>
        /// <param name="flags">The conversion flags.</param>
        /// <returns>The popped element as integer.</returns>
        public Value PopInt(ConvertFlags flags)
        {
            var type = PeekBasicValueType();

            switch (type)
            {
            case BasicValueType.Int32:
            case BasicValueType.Int64:
                return(Pop());

            case BasicValueType.Int1:
            case BasicValueType.Int8:
            case BasicValueType.Int16:
            case BasicValueType.Float32:
                return(Pop(
                           Builder.GetPrimitiveType(BasicValueType.Int32),
                           flags));

            case BasicValueType.Float64:
                return(Pop(
                           Builder.GetPrimitiveType(BasicValueType.Int64),
                           flags));

            default:
                throw CodeGenerator.GetNotSupportedException(
                          ErrorMessages.NotSupportedIntOperand, type);
            }
        }