protected override void OptimizeMethod()
        {
            BuiltinFunction optimized = ReflectOptimizer.MakeFunction(this);

            if (optimized != null)
            {
                ReflectedType declType = (ReflectedType)DeclaringType;
                if (declType.dict == null)
                {
                    declType.dict = new Dict();
                }

                object    newmeth;
                NewMethod newMethAsMeth;
                if (declType.dict.TryGetValue(SymbolTable.NewInst, out newmeth) && (newMethAsMeth = newmeth as NewMethod) != null)
                {
                    newMethAsMeth.Optimize(optimized);
                }
                else
                {
                    declType.dict[SymbolTable.NewInst] = optimized;
                    declType.ctor = optimized;
                }

                optimizedTarget = optimized;
            }
        }
示例#2
0
        //!!! This needs to go
        public void InitializeBuiltins()
        {
            FieldInfo ti = __dict__.GetType().GetField(ModuleFieldName);

            if (ti != null)
            {
                ti.SetValue(__dict__, this);
            }

            foreach (FieldInfo fi in __dict__.GetType().GetFields())
            {
                if (fi.FieldType != typeof(object) && fi.FieldType != typeof(BuiltinWrapper))
                {
                    continue;
                }
                if (!fi.IsStatic)
                {
                    continue;
                }

                if (fi.Name == "__debug__")
                {
                    fi.SetValue(null, new BuiltinWrapper(IronPython.Hosting.PythonEngine.options.DebugMode, "__debug__"));
                    continue;
                }

                //!!! GetAttr instead of GetSlot

                object bi;
                if (TypeCache.Builtin.TryGetSlot(DefaultContext.Default, SymbolTable.StringToId(fi.Name), out bi))
                {
                    Debug.Assert(fi.FieldType == typeof(BuiltinWrapper));

                    ReflectedMethod rm = bi as ReflectedMethod;
                    BuiltinFunction bf;
                    if (rm != null)
                    {
                        // update the dictionary w/ an optimized version, if one's available.
                        bf = ReflectOptimizer.MakeFunction(rm);
                        if (bf != null)
                        {
                            bi = bf;
                        }
                    }

                    fi.SetValue(null, new BuiltinWrapper(Ops.GetDescriptor(bi, null, TypeCache.Builtin), fi.Name));
                    continue;
                }

                if (fi.GetValue(null) == null)
                {
                    Debug.Assert(fi.FieldType == typeof(object));

                    fi.SetValue(null, new Uninitialized(fi.Name));
                }
            }
        }
        protected virtual void OptimizeMethod()
        {
            BuiltinFunction optimized = ReflectOptimizer.MakeFunction(this);

            if (optimized != null)
            {
                Debug.Assert(optimized.Targets.Length == Targets.Length);

                ReflectedType declType = (ReflectedType)DeclaringType;
                declType.Initialize();

                object   prevVal;
                SymbolId myId = SymbolTable.StringToId(Name);
                if (declType.dict.TryGetValue(myId, out prevVal))
                {
                    ClassMethod cm;
                    if ((cm = prevVal as ClassMethod) != null)
                    {
                        cm.func = optimized;
                    }
                    else
                    {
                        if (myId == SymbolTable.NewInst)
                        {
                            declType.dict[myId] = declType.ctor = optimized;
                        }
                        else
                        {
                            declType.dict[myId] = optimized.GetDescriptor();
                        }
                    }

                    optimizedTarget = optimized;
                }
            }
        }