public object RichEquals(object other) { List l = other as List; if (l == null) { IEnumerator ie; if (Ops.TryGetEnumerator(other, out ie)) { int curIndex = 0; while (ie.MoveNext()) { if (curIndex >= size || !Ops.EqualRetBool(ie.Current, this[curIndex++])) { return(Ops.FALSE); } } return(Ops.TRUE); } return(Ops.FALSE); } if (l.Count != this.Count) { return(Ops.FALSE); } return(Ops.Bool2Object(CompareTo(l) == 0)); }
public static object Equals(bool x, object other) { // common case is bool vs bool if (other is bool) { return(Ops.Bool2Object(x == (bool)other)); } // otherwise convert other to a bool, and compare Conversion conv; int otherInt = Converter.TryConvertToInt32(other, out conv); if (conv < Conversion.Truncation) { int myint = x ? 1 : 0; return(Ops.Bool2Object(myint == otherInt)); } else if (conv == Conversion.Truncation) { // if we truncated the value (eg 1.5) we wouldn't be equal // to True, but if we had something like 1.0 we didn't lose // any precision and we're equal if (EqualsTruncation(x, other)) { return(true); } } return(Ops.NotImplemented); }
public static object IsSequenceType(object o) { return(Ops.Bool2Object( o is System.Collections.ICollection || o is System.Collections.IEnumerable || o is System.Collections.IEnumerator || o is System.Collections.IList)); }
public object Contains(object o) { // promote sets to FrozenSet's for contains checks (so we get a hash code) o = SetHelpers.GetHashableSetIfSet(o); Ops.Hash(o);// make sure we have a hashable item return(Ops.Bool2Object(items.ContainsKey(o))); }
private static object FastNew(object value) { if (value is bool) { return(Ops.Bool2Object((bool)value)); } return(Ops.Bool2Object(Ops.IsTrue(value))); }
public static object BitwiseAnd(bool x, object other) { if (other is bool) { return(Ops.Bool2Object(x & (bool)other)); } return(IntOps.BitwiseAnd(x ? 1 : 0, other)); }
public static object Xor(bool x, object other) { if (other is bool) { return(Ops.Bool2Object(x ^ (bool)other)); } return(IntOps.Xor(x ? 1 : 0, other)); }
public object RichNotEquals(object other) { if (!(other is PythonDequeCollection)) { return(Ops.TRUE); } return(Ops.Bool2Object(CompareTo(other) != 0)); }
public static object Equals(BigInteger x, object other) { if (other is int) { return(Ops.Bool2Object(x == (BigInteger)(int)other)); } else if (other is long) { return(Ops.Bool2Object(x == (BigInteger)(long)other)); } else if (other is double) { return(Ops.Bool2Object(x == (double)other)); } else if (other is BigInteger) { return(Ops.Bool2Object((BigInteger)x == (BigInteger)other)); } else if (other is Complex64) { return(Ops.Bool2Object(x == (Complex64)other)); } else if (other is bool) { return(Ops.Bool2Object((bool)other ? x == 1 : x == 0)); } else if (other is ExtensibleFloat) { return(Ops.Bool2Object(x == ((ExtensibleFloat)other).value)); } else if (other is decimal) { return(Ops.Bool2Object(x == (double)(decimal)other)); } else if (other == null) { return(Ops.FALSE); } Conversion conversion; BigInteger y = Converter.TryConvertToBigInteger(other, out conversion); if (conversion != Conversion.None) { return(Ops.Bool2Object(x == y)); } object res = Ops.GetDynamicType(other).Coerce(other, x); if (res != Ops.NotImplemented && !(res is OldInstance)) { return(Ops.Equal(((Tuple)res)[1], ((Tuple)res)[0])); } return(Ops.NotImplemented); }
public static object HasAttr(ICallerContext context, object o, string name) { object tmp; try { return(Ops.Bool2Object(Ops.TryGetAttr(context, o, SymbolTable.StringToId(name), out tmp))); } catch { return(Ops.FALSE); } }
public static object LessThanEqual(decimal x, object other) { object res = FloatOps.Compare((double)x, other); if (res != Ops.NotImplemented) { return(Ops.Bool2Object((int)res <= 0)); } return(res); }
public object RichEquals(object other) { PythonWeakRefProxy wrp = other as PythonWeakRefProxy; if (wrp != null) { return(Ops.Bool2Object(Ops.EqualRetBool(GetObject(), wrp.GetObject()))); } return(Ops.Equal(GetObject(), other)); }
public object RichNotEquals(object other) { PythonCallableWeakRefProxy wrp = other as PythonCallableWeakRefProxy; if (wrp != null) { return(Ops.Bool2Object(!GetObject().Equals(wrp.GetObject()))); } return(Ops.NotEqual(GetObject(), other)); }
public static object Equals(int x, object other) { bool res; if (TryEquals(x, other, out res)) { return(Ops.Bool2Object(res)); } return(Ops.NotImplemented); }
public object RichEquals(object other) { Slice s = other as Slice; if (s == null) { return(Ops.FALSE); } return(Ops.Bool2Object((Ops.Compare(start, s.start) == 0) && (Ops.Compare(stop, s.stop) == 0) && (Ops.Compare(step, s.step) == 0))); }
public static object NotEquals(BigInteger x, object y) { object res = Equals(x, y); if (res == Ops.NotImplemented) { return(res); } else { return(Ops.Bool2Object(!((bool)res))); } }
public object RichEquals(object other) { ISet set = other as ISet; if (set != null) { if (set.GetLength() != GetLength()) { return(Ops.FALSE); } return(Ops.Bool2Object(set.IsSubset(this) == Ops.TRUE && this.IsSubset(set) == Ops.TRUE)); } return(Ops.FALSE); }
public object RichEquals(object other) { if (other == null) { return(Ops.FALSE); } BigInteger bi = other as BigInteger; if (!object.ReferenceEquals(bi, null)) { return(Ops.Bool2Object(Equals(bi))); } return(Ops.NotImplemented); }
public static object IsNumberType(object o) { return(Ops.Bool2Object( o is int || o is long || o is double || o is float || o is short || o is uint || o is ulong || o is ushort || o is decimal || o is IronMath.BigInteger || o is IronMath.Complex64 || o is byte)); }
/// <summary> /// Special equals because none of the special cases in Ops.Equals /// are applicable here, and the reference equality check breaks some tests. /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> static object RefEquals(object x, object y) { object ret = Ops.NotImplemented; ret = Ops.GetDynamicType(x).Equal(x, y); if (ret != Ops.NotImplemented) { return(ret); } ret = Ops.GetDynamicType(y).Equal(y, x); if (ret != Ops.NotImplemented) { return(ret); } return(Ops.Bool2Object(x.Equals(y))); }
public object RichEquals(object other) { ExtensibleFloat ei = other as ExtensibleFloat; if (ei != null) { return(Ops.Bool2Object(value == ei.value)); } if (other is double) { return(Ops.Bool2Object(value == (double)other)); } if (other is float) { return(Ops.Bool2Object(value == (float)other)); } return(Ops.NotImplemented); }
public static object IsSubClassWrapper(DynamicType c, object typeinfo) { return(Ops.Bool2Object(IsSubClass(c, typeinfo))); }
public static object Make(object cls, object o) { return(Ops.Bool2Object(Ops.IsTrue(o))); }
public object ContainsValueWrapper(object item) { return(Ops.Bool2Object(ContainsValue(item))); }
public object IsLocked() { return(Ops.Bool2Object(curHolder != null)); }
public static object Truth(object o) { return(Ops.Bool2Object(Ops.IsTrue(o))); }
public static object HasKey(IDictionary <object, object> self, object key) { return(Ops.Bool2Object(self.ContainsKey(key))); }
public object ContainsValueWrapper(object value) { return(Ops.Bool2Object(ContainsValue(value))); }
public static object IsInstanceWrapper(object o, object typeinfo) { return(Ops.Bool2Object(IsInstance(o, typeinfo))); }