internal static PythonModule ReloadBuiltin(PythonModule module) { Type ty; if (module.SystemState.TopPackage.Builtins.TryGetValue(module.ModuleName, out ty)) { if (typeof(CustomFieldIdDict).IsAssignableFrom(ty)) { CustomFieldIdDict dict = (CustomFieldIdDict)ty.GetConstructor(Type.EmptyTypes).Invoke(new object[0]); //@todo share logic to copy old values in when not already there from reload module.__dict__ = dict; module.Initialize(); return(module); } else { ReflectedType type = (ReflectedType)Ops.GetDynamicTypeFromType(ty); type.Initialize(); foreach (string attrName in type.GetAttrNames(module)) { SymbolId id = SymbolTable.StringToId(attrName); module.__dict__[id] = type.GetAttr(module, null, id); } module.Initialize(); return(module); } } throw new NotImplementedException(); }
private static PythonModule MakePythonModule(PythonModule importer, string name, ReflectedType type) { type.Initialize(); FieldIdDict dict = new FieldIdDict(); //!!! need a GetAttrIds foreach (string attrName in type.GetAttrNames(DefaultContext.Default)) { dict[SymbolTable.StringToId(attrName)] = type.GetAttr(DefaultContext.Default, null, SymbolTable.StringToId(attrName)); } PythonModule ret = new PythonModule(name, dict, importer.SystemState); importer.SystemState.modules[name] = ret; return(ret); }
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; } } }