コード例 #1
0
        public override T BindDelegate <T>(CallSite <T> site, object[] args)
        {
            IFastSettable fastSet = args[0] as IFastSettable;

            if (fastSet != null)
            {
                T res = fastSet.MakeSetBinding <T>(site, this);
                if (res != null)
                {
                    return(res);
                }
            }

            IPythonObject ipo = args[0] as IPythonObject;

            if (ipo != null && !(ipo is IProxyObject))
            {
                FastBindResult <T> res = UserTypeOps.MakeSetBinding <T>(Context.SharedContext, site, ipo, args[1], this);

                if (res.Target != null)
                {
                    PerfTrack.NoteEvent(PerfTrack.Categories.BindingFast, "IPythonObject");

                    if (res.ShouldCache)
                    {
                        CacheTarget(res.Target);
                    }
                    return(res.Target);
                }

                PerfTrack.NoteEvent(PerfTrack.Categories.BindingSlow, "IPythonObject Set");
            }

            return(base.BindDelegate(site, args));
        }
コード例 #2
0
            public override string ToString()
            {
                object obj;

                if (!UserTypeOps.TryGetNonInheritedMethodHelper(this._class, (object)this, "ToString", out obj))
                {
                    return(base.ToString());
                }
                else
                {
                    return(Converter.ConvertToString(Object_1_1.site_0.Target((CallSite)Object_1_1.site_0, DefaultContext.Default, obj)));
                }
            }
コード例 #3
0
            public override int GetHashCode()
            {
                object obj;

                if (!UserTypeOps.TryGetNonInheritedMethodHelper(this._class, (object)this, "GetHashCode", out obj))
                {
                    return(base.GetHashCode());
                }
                else
                {
                    return(Converter.ConvertToInt32(Object_1_1.site_2.Target((CallSite)Object_1_1.site_2, DefaultContext.Default, obj)));
                }
            }
コード例 #4
0
            public new object MemberwiseClone()
            {
                object obj;

                if (!UserTypeOps.TryGetNonInheritedMethodHelper(this._class, (object)this, "MemberwiseClone", out obj))
                {
                    return(base.MemberwiseClone());
                }
                else
                {
                    return(Object_1_1.site_3.Target((CallSite)Object_1_1.site_3, DefaultContext.Default, obj));
                }
            }
コード例 #5
0
            public override bool Equals(object obj)
            {
                object obj1;

                if (!UserTypeOps.TryGetNonInheritedMethodHelper(this._class, (object)this, "Equals", out obj1))
                {
                    return(base.Equals(obj));
                }
                else
                {
                    return(Converter.ConvertToBoolean(Object_1_1.site_1.Target((CallSite)Object_1_1.site_1, DefaultContext.Default, obj1, obj)));
                }
            }
コード例 #6
0
        public void __init__(object fget = null, object fset = null, object fdel = null, object doc = null)
        {
            _fget = fget; _fset = fset; _fdel = fdel; _doc = doc;
            if (GetType() != typeof(PythonProperty) && _fget is PythonFunction)
            {
                // http://bugs.python.org/issue5890
                PythonDictionary dict = UserTypeOps.GetDictionary((IPythonObject)this);
                if (dict == null)
                {
                    throw PythonOps.AttributeError("{0} object has no __doc__ attribute", PythonOps.GetPythonTypeName(this));
                }

                dict["__doc__"] = ((PythonFunction)_fget).__doc__;
            }
        }
コード例 #7
0
        public override T BindDelegate <T>(CallSite <T> site, object[] args)
        {
            Debug.Assert(args[1].GetType() == typeof(CodeContext));

            IFastGettable fastGet = args[0] as IFastGettable;

            if (fastGet != null)
            {
                T res = fastGet.MakeGetBinding <T>(site, this, (CodeContext)args[1], Name);
                if (res != null)
                {
                    PerfTrack.NoteEvent(PerfTrack.Categories.BindingFast, "IFastGettable");
                    return(res);
                }

                PerfTrack.NoteEvent(PerfTrack.Categories.BindingSlow, "IFastGettable");
                return(base.BindDelegate <T>(site, args));
            }

            IPythonObject pyObj = args[0] as IPythonObject;

            if (pyObj != null && !(args[0] is IProxyObject))
            {
                FastBindResult <T> res = UserTypeOps.MakeGetBinding <T>((CodeContext)args[1], site, pyObj, this);
                if (res.Target != null)
                {
                    PerfTrack.NoteEvent(PerfTrack.Categories.BindingFast, "IPythonObject");
                    if (res.ShouldCache)
                    {
                        CacheTarget(res.Target);
                    }
                    return(res.Target);
                }

                PerfTrack.NoteEvent(PerfTrack.Categories.BindingSlow, "IPythonObject Get");
                return(base.BindDelegate <T>(site, args));
            }

            if (args[0] != null)
            {
                if (args[0].GetType() == typeof(PythonModule))
                {
                    if (SupportsLightThrow)
                    {
                        return((T)(object)new Func <CallSite, object, CodeContext, object>(new PythonModuleDelegate(_name).LightThrowTarget));
                    }
                    else if (!IsNoThrow)
                    {
                        return((T)(object)new Func <CallSite, object, CodeContext, object>(new PythonModuleDelegate(_name).Target));
                    }
                    else
                    {
                        return((T)(object)new Func <CallSite, object, CodeContext, object>(new PythonModuleDelegate(_name).NoThrowTarget));
                    }
                }
                else if (args[0].GetType() == typeof(NamespaceTracker))
                {
                    switch (Name)
                    {
                    case "__str__":
                    case "__repr__":
                    case "__doc__":
                        // need to return the built in method descriptor for these...
                        break;

                    case "__file__":
                        return((T)(object)new Func <CallSite, object, CodeContext, object>(new NamespaceTrackerDelegate(_name).GetFile));

                    case "__dict__":
                        return((T)(object)new Func <CallSite, object, CodeContext, object>(new NamespaceTrackerDelegate(_name).GetDict));

                    case "__name__":
                        return((T)(object)new Func <CallSite, object, CodeContext, object>(new NamespaceTrackerDelegate(_name).GetName));

                    default:
                        if (IsNoThrow)
                        {
                            return((T)(object)new Func <CallSite, object, CodeContext, object>(new NamespaceTrackerDelegate(_name).NoThrowTarget));
                        }
                        else
                        {
                            return((T)(object)new Func <CallSite, object, CodeContext, object>(new NamespaceTrackerDelegate(_name).Target));
                        }
                    }
                }
            }

            if (args[0] != null &&
#if FEATURE_COM
                !Microsoft.Scripting.ComInterop.ComBinder.IsComObject(args[0]) &&
#endif
                !(args[0] is IDynamicMetaObjectProvider))
            {
                Type        selfType = typeof(T).GetMethod("Invoke").GetParameters()[1].ParameterType;
                CodeContext context  = (CodeContext)args[1];
                T           res      = null;
                if (selfType == typeof(object))
                {
                    res = (T)(object)MakeGetMemberTarget <object>(Name, args[0], context);
                }
                else if (selfType == typeof(List))
                {
                    res = (T)(object)MakeGetMemberTarget <List>(Name, args[0], context);
                }
                else if (selfType == typeof(string))
                {
                    res = (T)(object)MakeGetMemberTarget <string>(Name, args[0], context);
                }

                if (res != null)
                {
                    return((T)(object)res);
                }
                return(base.BindDelegate <T>(site, args));
            }

            PerfTrack.NoteEvent(PerfTrack.Categories.BindingSlow, "GetNoFast " + IsNoThrow + " " + CompilerHelpers.GetType(args[0]));
            return(this.LightBind <T>(args, Context.Options.CompilationThreshold));
        }
コード例 #8
0
 void IWeakReferenceable.SetFinalizer(WeakRefTracker obj0)
 {
     UserTypeOps.SetFinalizerHelper((IPythonObject)this, obj0);
 }
コード例 #9
0
 bool IWeakReferenceable.SetWeakRef(WeakRefTracker obj0)
 {
     return(UserTypeOps.SetWeakRefHelper((IPythonObject)this, obj0));
 }
コード例 #10
0
 WeakRefTracker IWeakReferenceable.GetWeakRef()
 {
     return(UserTypeOps.GetWeakRefHelper((IPythonObject)this));
 }
コード例 #11
0
 DynamicMetaObject IDynamicMetaObjectProvider.GetMetaObject(Expression parameter)
 {
     return(UserTypeOps.GetMetaObjectHelper((IPythonObject)this, parameter, (DynamicMetaObject)null));
 }
コード例 #12
0
 object[] IPythonObject.GetSlotsCreate()
 {
     return(UserTypeOps.GetSlotsCreate((IPythonObject)this, ref this._slots_and_weakref));
 }
コード例 #13
0
 PythonDictionary IPythonObject.SetDict(PythonDictionary dict)
 {
     return(UserTypeOps.SetDictHelper(ref this._dict, dict));
 }
コード例 #14
0
 void IWeakReferenceable.SetFinalizer(WeakRefTracker value)
 {
     UserTypeOps.SetFinalizerHelper(this, value);
 }
コード例 #15
0
 bool IWeakReferenceable.SetWeakRef(WeakRefTracker value)
 {
     return(UserTypeOps.SetWeakRefHelper(this, value));
 }
コード例 #16
0
 WeakRefTracker IWeakReferenceable.GetWeakRef()
 {
     return(UserTypeOps.GetWeakRefHelper(this));
 }