コード例 #1
0
ファイル: List.cs プロジェクト: weimingtom/IronPythonMod
        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));
        }
コード例 #2
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);
        }
コード例 #3
0
 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));
 }
コード例 #4
0
ファイル: Set.cs プロジェクト: weimingtom/IronPythonMod
        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)));
        }
コード例 #5
0
 private static object FastNew(object value)
 {
     if (value is bool)
     {
         return(Ops.Bool2Object((bool)value));
     }
     return(Ops.Bool2Object(Ops.IsTrue(value)));
 }
コード例 #6
0
 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));
 }
コード例 #7
0
        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));
        }
コード例 #8
0
            public object RichNotEquals(object other)
            {
                if (!(other is PythonDequeCollection))
                {
                    return(Ops.TRUE);
                }

                return(Ops.Bool2Object(CompareTo(other) != 0));
            }
コード例 #9
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);
        }
コード例 #10
0
ファイル: Builtin.cs プロジェクト: weimingtom/IronPythonMod
        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);
            }
        }
コード例 #11
0
        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);
        }
コード例 #12
0
ファイル: _weakref.cs プロジェクト: weimingtom/IronPythonMod
            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));
            }
コード例 #13
0
ファイル: _weakref.cs プロジェクト: weimingtom/IronPythonMod
            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));
            }
コード例 #14
0
ファイル: IntOps.cs プロジェクト: weimingtom/IronPythonMod
        public static object Equals(int x, object other)
        {
            bool res;

            if (TryEquals(x, other, out res))
            {
                return(Ops.Bool2Object(res));
            }

            return(Ops.NotImplemented);
        }
コード例 #15
0
ファイル: Slice.cs プロジェクト: weimingtom/IronPythonMod
        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)));
        }
コード例 #16
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)));
            }
        }
コード例 #17
0
ファイル: Set.cs プロジェクト: weimingtom/IronPythonMod
        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);
        }
コード例 #18
0
        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);
        }
コード例 #19
0
 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));
 }
コード例 #20
0
ファイル: _weakref.cs プロジェクト: weimingtom/IronPythonMod
            /// <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)));
            }
コード例 #21
0
ファイル: FloatOps.cs プロジェクト: weimingtom/IronPythonMod
        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);
        }
コード例 #22
0
ファイル: Builtin.cs プロジェクト: weimingtom/IronPythonMod
 public static object IsSubClassWrapper(DynamicType c, object typeinfo)
 {
     return(Ops.Bool2Object(IsSubClass(c, typeinfo)));
 }
コード例 #23
0
 public static object Make(object cls, object o)
 {
     return(Ops.Bool2Object(Ops.IsTrue(o)));
 }
コード例 #24
0
 public object ContainsValueWrapper(object item)
 {
     return(Ops.Bool2Object(ContainsValue(item)));
 }
コード例 #25
0
 public object IsLocked()
 {
     return(Ops.Bool2Object(curHolder != null));
 }
コード例 #26
0
 public static object Truth(object o)
 {
     return(Ops.Bool2Object(Ops.IsTrue(o)));
 }
コード例 #27
0
ファイル: Dict.cs プロジェクト: weimingtom/IronPythonMod
 public static object HasKey(IDictionary <object, object> self, object key)
 {
     return(Ops.Bool2Object(self.ContainsKey(key)));
 }
コード例 #28
0
ファイル: List.cs プロジェクト: weimingtom/IronPythonMod
 public object ContainsValueWrapper(object value)
 {
     return(Ops.Bool2Object(ContainsValue(value)));
 }
コード例 #29
0
ファイル: Builtin.cs プロジェクト: weimingtom/IronPythonMod
 public static object IsInstanceWrapper(object o, object typeinfo)
 {
     return(Ops.Bool2Object(IsInstance(o, typeinfo)));
 }