public override object NotEqual(object self, object other) { object func; if (PythonType.TryLookupSpecialMethod(self, SymbolTable.OpNotEqual, out func)) { object ret; if (Ops.TryCall(func, other, out ret) && ret != Ops.NotImplemented) { return(ret); } } if (PythonType.TryLookupSpecialMethod(self, SymbolTable.Cmp, out func) && func != __cmp__F) { object ret = Ops.Call(func, other); if (ret != Ops.NotImplemented) { return(Ops.CompareToZero(ret) != 0); } //if (ret is int) { // return ((int)ret) != 0; //} else if (ret is ExtensibleInt) { // return ((ExtensibleInt)ret)._value != 0; //} //throw Ops.TypeError("comparison did not return an int"); } return(Ops.NotImplemented); }
object ICallableWithCallerContext.Call(ICallerContext context, object[] args) { object newMethod, newObject; newMethod = Ops.GetAttr(context, this, SymbolTable.NewInst); newObject = Ops.CallWithContext(context, newMethod, PrependThis(args)); if (newObject == null) { return(null); } if (Ops.GetDynamicType(newObject).IsSubclassOf(this)) { object init; if (PythonType.TryLookupSpecialMethod(DefaultContext.Default, newObject, SymbolTable.Init, out init)) { switch (args.Length) { case 0: Ops.CallWithContext(context, init); break; case 1: Ops.CallWithContext(context, init, args[0]); break; case 2: Ops.CallWithContext(context, init, args[0], args[1]); break; default: Ops.CallWithContext(context, init, args); break; } } } return(newObject); }
public override object CompareTo(object self, object other) { object func; if (PythonType.TryLookupSpecialMethod(self, SymbolTable.Cmp, out func)) { return(Ops.Call(func, other)); } return(Ops.NotImplemented); }
public static object RichGetHashCodeHelper(object self) { // new-style classes only lookup in slots, not in instance // members object func; if (PythonType.TryLookupSpecialMethod(self, SymbolTable.Hash, out func)) { return(Converter.ConvertToInt32(Ops.Call(func))); } return(Ops.NotImplemented); }
private static object InternalCompare(SymbolId cmp, object self, object other) { object meth; if (PythonType.TryLookupSpecialMethod(self, cmp, out meth)) { object ret; if (Ops.TryCall(meth, other, out ret)) { return(ret); } } return(Ops.NotImplemented); }