本文整理汇总了C#中BinaryOpStorage.GetCallSite方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryOpStorage.GetCallSite方法的具体用法?C# BinaryOpStorage.GetCallSite怎么用?C# BinaryOpStorage.GetCallSite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryOpStorage
的用法示例。
在下文中一共展示了BinaryOpStorage.GetCallSite方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialize
public void Initialize(BinaryOpStorage/*!*/ comparisonStorage,
RubyContext/*!*/ context, object begin, object end, bool excludeEnd) {
if (_initialized) {
throw RubyExceptions.CreateNameError("`initialize' called twice");
}
// Range tests whether the items can be compared, and uses that to determine if the range is valid
// Only a non-existent <=> method or a result of nil seems to trigger the exception.
object compareResult;
var site = comparisonStorage.GetCallSite("<=>");
try {
compareResult = site.Target(site, begin, end);
} catch (Exception) {
compareResult = null;
}
if (compareResult == null) {
throw RubyExceptions.CreateArgumentError("bad value for range");
}
_begin = begin;
_end = end;
_excludeEnd = excludeEnd;
_initialized = true;
}
示例2: Abort
public static void Abort(BinaryOpStorage/*!*/ writeStorage, object/*!*/ self, [DefaultProtocol, NotNull]MutableString/*!*/ message)
{
var site = writeStorage.GetCallSite("write", 1);
site.Target(site, writeStorage.Context.StandardErrorOutput, message);
Exit(self, 1);
}
示例3: Abs
public static object Abs(BinaryOpStorage/*!*/ lessThanStorage, UnaryOpStorage/*!*/ minusStorage, object self)
{
var lessThan = lessThanStorage.GetCallSite("<");
if (RubyOps.IsTrue(lessThan.Target(lessThan, self, 0))) {
var minus = minusStorage.GetCallSite("[email protected]");
return minus.Target(minus, self);
}
return self;
}
示例4: DefineFinalizer
public static object DefineFinalizer(RespondToStorage/*!*/ respondTo, BinaryOpStorage/*!*/ call, RubyModule/*!*/ self, object obj, object finalizer)
{
if (!Protocols.RespondTo(respondTo, finalizer, "call")) {
throw RubyExceptions.CreateArgumentError("finalizer should be callable (respond to :call)");
}
respondTo.Context.SetInstanceVariable(obj, FinalizerInvoker.InstanceVariableName, new FinalizerInvoker(call.GetCallSite("call"), finalizer));
RubyArray result = new RubyArray(2);
result.Add(0);
result.Add(finalizer);
return result;
}
示例5: Equal
public static bool Equal(BinaryOpStorage/*!*/ compareStorage, object self, object other)
{
if (self == other) {
return true;
}
// calls method_missing:
var compare = compareStorage.GetCallSite("<=>");
object compareResult;
try {
compareResult = compare.Target(compare, self, other);
} catch (SystemException) {
// catches StandardError (like rescue)
return false;
}
return compareResult is int && (int)compareResult == 0;
}
示例6: Step
public static object Step(
BinaryOpStorage/*!*/ equals,
BinaryOpStorage/*!*/ greaterThanStorage,
BinaryOpStorage/*!*/ lessThanStorage,
BinaryOpStorage/*!*/ addStorage,
RubyContext/*!*/ context, BlockParam block, object self, object limit, [Optional]object step) {
if (step == Missing.Value) {
step = ScriptingRuntimeHelpers.Int32ToObject(1);
}
if (self is double || limit is double || step is double) {
// At least one of the arguments is double so convert all to double and run the Float version of Step
double floatSelf = Protocols.ConvertToFloat(context, self);
double floatLimit = Protocols.ConvertToFloat(context, limit);
double floatStep = Protocols.ConvertToFloat(context, step);
return Step(context, block, floatSelf, floatLimit, floatSelf);
} else {
#region The generic step algorithm:
// current = self
// if step is postive then
// while current < limit do
// yield(current)
// current = current + step
// end
// else
// while current > limit do
// yield(current)
// current = current + step
// end
// return self
#endregion
bool isStepZero = Protocols.IsEqual(equals, context, step, 0);
if (isStepZero) {
throw RubyExceptions.CreateArgumentError("step can't be 0");
}
var greaterThan = greaterThanStorage.GetCallSite(">");
bool isStepPositive = RubyOps.IsTrue(greaterThan.Target(greaterThan, context, step, 0));
var compare = isStepPositive ? greaterThan : lessThanStorage.GetCallSite("<");
object current = self;
while (!RubyOps.IsTrue(compare.Target(compare, context, current, limit))) {
object result;
if (YieldStep(block, current, out result)) {
return result;
}
var add = addStorage.GetCallSite("+");
current = add.Target(add, context, current, step);
}
return self;
}
}
示例7: Quo
public static object Quo(BinaryOpStorage/*!*/ divideStorage,
RubyContext/*!*/ context, object self, object other) {
var site = divideStorage.GetCallSite("/");
return site.Target(site, context, self, other);
}
示例8: Remainder
public static object Remainder(
BinaryOpStorage/*!*/ equals,
BinaryOpStorage/*!*/ greaterThanStorage,
BinaryOpStorage/*!*/ lessThanStorage,
BinaryOpStorage/*!*/ minusStorage,
BinaryOpStorage/*!*/ moduloStorage,
RubyContext/*!*/ context, object self, object other) {
var modulo = moduloStorage.GetCallSite("%");
object remainder = modulo.Target(modulo, context, self, other);
if (!Protocols.IsEqual(equals, context, remainder, 0)) {
var greaterThan = greaterThanStorage.GetCallSite(">");
var lessThan = lessThanStorage.GetCallSite("<");
// modulo is not zero
if (RubyOps.IsTrue(lessThan.Target(lessThan, context, self, 0)) && RubyOps.IsTrue(greaterThan.Target(greaterThan, context, other, 0)) ||
RubyOps.IsTrue(greaterThan.Target(greaterThan, context, self, 0)) && RubyOps.IsTrue(lessThan.Target(lessThan, context, other, 0))) {
// (self is negative and other is positive) OR (self is positive and other is negative)
var minus = minusStorage.GetCallSite("-");
return minus.Target(minus, context, remainder, other);
}
}
// Either modulo is zero or self and other are not of the same sign
return remainder;
}
示例9: Wrap
public static object Wrap(BinaryOpStorage/*!*/ newStorage, UnaryOpStorage/*!*/ closeStorage,
BlockParam block, RubyClass/*!*/ self, object io)
{
var newSite = newStorage.GetCallSite("new");
GZipFile gzipFile = (GZipFile)newSite.Target(newSite, self, io);
return gzipFile.Do(block);
}
示例10: Modulo
public static object Modulo(
BinaryOpStorage/*!*/ moduloStorage,
RubyContext/*!*/ context, object self, object other) {
var modulo = moduloStorage.GetCallSite("%");
return modulo.Target(modulo, context, self, other);
}
示例11: ConvertCompareResult
public static int ConvertCompareResult(
BinaryOpStorage/*!*/ lessThanStorage,
BinaryOpStorage/*!*/ greaterThanStorage,
object/*!*/ result) {
Debug.Assert(result != null);
var greaterThanSite = greaterThanStorage.GetCallSite(">");
if (RubyOps.IsTrue(greaterThanSite.Target(greaterThanSite, result, 0))) {
return 1;
}
var lessThanSite = lessThanStorage.GetCallSite("<");
if (RubyOps.IsTrue(lessThanSite.Target(lessThanSite, result, 0))) {
return -1;
}
return 0;
}
示例12: ReportWarning
public static void ReportWarning(BinaryOpStorage/*!*/ writeStorage, ConversionStorage<MutableString>/*!*/ tosConversion,
object self, object message) {
if (writeStorage.Context.Verbose != null) {
var output = writeStorage.Context.StandardErrorOutput;
// MRI: unlike Kernel#puts this outputs \n even if the message ends with \n:
var site = writeStorage.GetCallSite("write", 1);
site.Target(site, output, RubyIOOps.ToPrintedString(tosConversion, message));
RubyIOOps.PutsEmptyLine(writeStorage, output);
}
}
示例13: Compare
public static object Compare(BinaryOpStorage/*!*/ comparisonStorage, RespondToStorage/*!*/ respondToStorage, object/*!*/ self, object other) {
// Self is object so that we can reuse this method.
// We test to see if other responds to to_str AND <=>
// Ruby never attempts to convert other to a string via to_str and call Compare ... which is strange -- feels like a BUG in Ruby
if (Protocols.RespondTo(respondToStorage, other, "to_str") && Protocols.RespondTo(respondToStorage, other, "<=>")) {
var site = comparisonStorage.GetCallSite("<=>");
object result = Integer.TryUnaryMinus(site.Target(site, other, self));
if (result == null) {
throw RubyExceptions.CreateTypeError(String.Format("{0} can't be coerced into Fixnum",
comparisonStorage.Context.GetClassDisplayName(result)));
}
return result;
}
return null;
}
示例14: Equals
public static bool Equals(RespondToStorage/*!*/ respondToStorage, BinaryOpStorage/*!*/ equalsStorage,
object/*!*/ self, object other) {
// Self is object so that we can reuse this method.
if (!Protocols.RespondTo(respondToStorage, other, "to_str")) {
return false;
}
var equals = equalsStorage.GetCallSite("==");
return Protocols.IsTrue(equals.Target(equals, other, self));
}
示例15: Times
public static object Times(BinaryOpStorage/*!*/ lessThanStorage, BinaryOpStorage/*!*/ addStorage, BlockParam block, object/*!*/ self) {
object i = 0;
var lessThan = lessThanStorage.GetCallSite("<");
while (RubyOps.IsTrue(lessThan.Target(lessThan, i, self))) {
if (block == null) {
throw RubyExceptions.NoBlockGiven();
}
object result;
if (block.Yield(i, out result)) {
return result;
}
var add = addStorage.GetCallSite("+");
i = add.Target(add, i, 1);
}
return self;
}