public int GetDynamicInvocationIndex(DynamicInvocation invocation, int bootstrapIndex) { var info = new InvokeDynamicInfo { BootstrapMethodIndex = (ushort)bootstrapIndex, NameAndTypeIndex = (ushort)GetNameAndTypeIndex(invocation.MethodName, invocation.MethodDescriptor) }; if (!_dynamicInfos.TryGetValue(info, out int index)) { index = AddConstant(info); _dynamicInfos.Add(info, index); } return(index); }
/// <summary> /// Compare the values of self and other (coerce using other as the object then call the passed in comparison operator). /// </summary> /// <remarks> /// This method is used for <, <=, > and >= operators. If we can't coerce then throw a specific comparison exception. /// </remarks> /// <exception cref="ArgumentException">If self and other cannot be coerced to the same type.</exception> public static bool CoerceAndCallRelationOperator(RubyContext /*!*/ context, object self, object other, DynamicInvocation invoke) { try { // Swap self and other around to do the coercion. RubyArray coercedValues = RubySites.Coerce(context, other, self); return(RubyOps.IsTrue(invoke(context, coercedValues[0], coercedValues[1]))); } catch (MemberAccessException x) { throw RubyExceptions.MakeComparisonError(context, self, other, x); } catch (ArgumentException x) { throw RubyExceptions.MakeComparisonError(context, self, other, x); } catch (NullReferenceException x) { throw RubyExceptions.MakeComparisonError(context, self, other, x); } }
/// <summary> /// Coerce the values of self and other (using other as the object) then call the passed in method. /// </summary> public static object CoerceAndCall(RubyContext /*!*/ context, object self, object other, DynamicInvocation invoke) { RubyArray coercedValues; try { // Swap self and other around to do the coercion. coercedValues = RubySites.Coerce(context, other, self); } catch (MemberAccessException x) { throw RubyExceptions.MakeCoercionError(context, self, other, x); } catch (ArgumentException x) { throw RubyExceptions.MakeCoercionError(context, self, other, x); } // But then swap them back when invoking the operation return(invoke(context, coercedValues[0], coercedValues[1])); }
/// <summary> /// Compare the values of self and other (coerce using other as the object then call the passed in comparison operator). /// </summary> /// <remarks> /// This method is used for <, <=, > and >= operators. If we can't coerce then throw a specific comparison exception. /// </remarks> /// <exception cref="ArgumentException">If self and other cannot be coerced to the same type.</exception> public static bool CoerceAndCallRelationOperator(RubyContext/*!*/ context, object self, object other, DynamicInvocation invoke) { try { // Swap self and other around to do the coercion. RubyArray coercedValues = RubySites.Coerce(context, other, self); return RubyOps.IsTrue(invoke(context, coercedValues[0], coercedValues[1])); } catch (MemberAccessException x) { throw RubyExceptions.MakeComparisonError(context, self, other, x); } catch (ArgumentException x) { throw RubyExceptions.MakeComparisonError(context, self, other, x); } catch (NullReferenceException x) { throw RubyExceptions.MakeComparisonError(context, self, other, x); } }
/// <summary> /// Coerce the values of self and other (using other as the object) then call the passed in method. /// </summary> public static object CoerceAndCall(RubyContext/*!*/ context, object self, object other, DynamicInvocation invoke) { RubyArray coercedValues; try { // Swap self and other around to do the coercion. coercedValues = RubySites.Coerce(context, other, self); } catch (MemberAccessException x) { throw RubyExceptions.MakeCoercionError(context, self, other, x); } catch (ArgumentException x) { throw RubyExceptions.MakeCoercionError(context, self, other, x); } // But then swap them back when invoking the operation return invoke(context, coercedValues[0], coercedValues[1]); }
public int GetDynamicIndex(DynamicInvocation invocation) { return(_builder.ConstantPoolBuffer.GetDynamicInvocationIndex(invocation, _builder.GetBootstrapMethodIndex(invocation.BootstrapMethod))); }