当前位置: 首页>>代码示例>>C#>>正文


C# ILGenerator.CompareGreaterThanUnsigned方法代码示例

本文整理汇总了C#中Jurassic.Compiler.ILGenerator.CompareGreaterThanUnsigned方法的典型用法代码示例。如果您正苦于以下问题:C# ILGenerator.CompareGreaterThanUnsigned方法的具体用法?C# ILGenerator.CompareGreaterThanUnsigned怎么用?C# ILGenerator.CompareGreaterThanUnsigned使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Jurassic.Compiler.ILGenerator的用法示例。


在下文中一共展示了ILGenerator.CompareGreaterThanUnsigned方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateRelational


//.........这里部分代码省略.........
                this.Right.GenerateCode(generator, optimizationInfo);

                // Compare the two numbers.
                switch (this.OperatorType)
                {
                    case OperatorType.LessThan:
                        generator.CompareLessThan();
                        break;
                    case OperatorType.GreaterThan:
                        generator.CompareGreaterThan();
                        break;

                    case OperatorType.LessThanOrEqual:
                        // a <= b   <-->   (a > b) == false
                        generator.CompareGreaterThan();
                        generator.LoadBoolean(false);
                        generator.CompareEqual();
                        break;

                    case OperatorType.GreaterThanOrEqual:
                        // a >= b   <-->   (a < b) == false
                        generator.CompareLessThan();
                        generator.LoadBoolean(false);
                        generator.CompareEqual();
                        break;
                }
            }
            else if (PrimitiveTypeUtilities.IsNumeric(leftType) || PrimitiveTypeUtilities.IsNumeric(rightType))
            {
                // At least one of the operands is a number.

                // Load the left hand side operand onto the stack.
                this.Left.GenerateCode(generator, optimizationInfo);

                // Convert the operand to a number.
                EmitConversion.ToNumber(generator, leftType);

                // Load the right hand side operand onto the stack.
                this.Right.GenerateCode(generator, optimizationInfo);

                // Convert the operand to a number.
                EmitConversion.ToNumber(generator, rightType);

                // Compare the two numbers.
                switch (this.OperatorType)
                {
                    case OperatorType.LessThan:
                        generator.CompareLessThan();
                        break;
                    case OperatorType.GreaterThan:
                        generator.CompareGreaterThan();
                        break;

                    case OperatorType.LessThanOrEqual:
                        // a <= b   <-->   (a > b) == false
                        generator.CompareGreaterThanUnsigned();
                        generator.LoadBoolean(false);
                        generator.CompareEqual();
                        break;

                    case OperatorType.GreaterThanOrEqual:
                        // a >= b   <-->   (a < b) == false
                        generator.CompareLessThanUnsigned();
                        generator.LoadBoolean(false);
                        generator.CompareEqual();
                        break;
                }
            }
            else
            {
                // It is unknown whether one of the operands is a string.

                // Load the left hand side operand onto the stack.
                this.Left.GenerateCode(generator, optimizationInfo);
                EmitConversion.ToAny(generator, leftType);

                // Load the right hand side operand onto the stack.
                this.Right.GenerateCode(generator, optimizationInfo);
                EmitConversion.ToAny(generator, rightType);

                switch (this.OperatorType)
                {
                    case OperatorType.LessThan:
                        generator.Call(ReflectionHelpers.TypeComparer_LessThan);
                        break;

                    case OperatorType.LessThanOrEqual:
                        generator.Call(ReflectionHelpers.TypeComparer_LessThanOrEqual);
                        break;

                    case OperatorType.GreaterThan:
                        generator.Call(ReflectionHelpers.TypeComparer_GreaterThan);
                        break;

                    case OperatorType.GreaterThanOrEqual:
                        generator.Call(ReflectionHelpers.TypeComparer_GreaterThanOrEqual);
                        break;
                }
            }
        }
开发者ID:leesanghyun2,项目名称:mp-onlinevideos2,代码行数:101,代码来源:BinaryExpression.cs

示例2: ToBool

        /// <summary>
        /// Pops the value on the stack, converts it to a boolean, then pushes the boolean result
        /// onto the stack.
        /// </summary>
        /// <param name="generator"> The IL generator. </param>
        /// <param name="fromType"> The type to convert from. </param>
        public static void ToBool(ILGenerator generator, PrimitiveType fromType)
        {
            // Check that a conversion is actually necessary.
            if (fromType == PrimitiveType.Bool)
                return;

            switch (fromType)
            {
                case PrimitiveType.Undefined:
                case PrimitiveType.Null:
                    // Converting from undefined or null produces false.
                    generator.Pop();
                    generator.LoadInt32(0);
                    break;

                case PrimitiveType.Int32:
                case PrimitiveType.UInt32:
                    // Converting from an integer produces true if the integer is non-zero.
                    generator.LoadInt32(0);
                    generator.CompareGreaterThanUnsigned();
                    break;

                case PrimitiveType.Number:
                    // Converting from a number produces true if the number is non-zero and not NaN.
                    var temp = generator.CreateTemporaryVariable(fromType);
                    generator.StoreVariable(temp);

                    // input != 0
                    generator.LoadVariable(temp);
                    generator.LoadDouble(0.0);
                    generator.CompareEqual();
                    generator.LoadInt32(0);
                    generator.CompareEqual();

                    // input == input
                    generator.LoadVariable(temp);
                    generator.Duplicate();
                    generator.CompareEqual();

                    // &&
                    generator.CompareEqual();

                    // The temporary variable is no longer needed.
                    generator.ReleaseTemporaryVariable(temp);
                    break;

                case PrimitiveType.String:
                    // Converting from a string produces true if the string is not empty.
                    generator.Call(ReflectionHelpers.String_Length);
                    generator.LoadInt32(0);
                    generator.CompareGreaterThan();
                    break;

                case PrimitiveType.ConcatenatedString:
                    // Converting from a string produces true if the string is not empty.
                    generator.Call(ReflectionHelpers.ConcatenatedString_Length);
                    generator.LoadInt32(0);
                    generator.CompareGreaterThan();
                    break;

                case PrimitiveType.Any:
                case PrimitiveType.Object:
                    // Otherwise, fall back to calling TypeConverter.ToBoolean()
                    generator.Call(ReflectionHelpers.TypeConverter_ToBoolean);
                    break;

                default:
                    throw new NotImplementedException(string.Format("Unsupported primitive type: {0}", fromType));
            }
        }
开发者ID:paulbartrum,项目名称:jurassic,代码行数:76,代码来源:EmitConversion.cs


注:本文中的Jurassic.Compiler.ILGenerator.CompareGreaterThanUnsigned方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。