本文整理汇总了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;
}
}
}
示例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));
}
}