Beispiel #1
0
 public Module(Modules references, string name, GlobalSuite global, Dictionary <ScopeStatement, Scope> scopes)
 {
     this.references = references;
     this.name       = name;
     this.scopes     = scopes;
     this.global     = global;
 }
Beispiel #2
0
        private void CompilePythonModule(string fileName, PythonCompilerSink sink, bool createMain)
        {
            assemblyGen.SetPythonSourceFile(fileName);
            CompilerContext context = new CompilerContext(fileName, sink);
            Parser          p       = Parser.FromFile(state, context);
            Stmt            body    = p.ParseFileInput();

            if (sink.Errors > 0)
            {
                return;
            }

            GlobalSuite gs         = IronPython.Compiler.Binder.Bind(body, context);
            string      moduleName = Path.GetFileNameWithoutExtension(fileName);
            TypeGen     tg         = OutputGenerator.GenerateModuleType(moduleName, assemblyGen);
            CodeGen     init;

            if (!AutoImportAll)
            {
                init = OutputGenerator.GenerateModuleInitialize(context, gs, tg);
            }
            else
            {
                // auto-import all compiled modules, useful for CodeDom scenarios.
                init = OutputGenerator.GenerateModuleInitialize(context, gs, tg, delegate(CodeGen cg) {
                    for (int i = 0; i < sourceFiles.Count; i++)
                    {
                        string otherModName = Path.GetFileNameWithoutExtension(sourceFiles[i]);
                        if (otherModName == moduleName)
                        {
                            continue;
                        }

                        FromImportStmt stmt = new FromImportStmt(
                            new DottedName(new Name[] { Name.Make(otherModName) }),
                            FromImportStmt.Star, null);
                        stmt.start = new Location(1, 1);
                        stmt.end   = new Location(1, 1);
                        stmt.Emit(cg);
                    }
                });
            }

            if (createMain)
            {
                CodeGen main = OutputGenerator.GenerateModuleEntryPoint(tg, init, Path.GetFileNameWithoutExtension(mainFile), referencedAssemblies);
                assemblyGen.SetEntryPoint(main.MethodInfo, targetKind);
            }

            AddPythonModuleAttribute(tg, moduleName);
            tg.FinishType();
        }
        private Module DoAnalyze(Modules modules, string name, Statement root)
        {
            GlobalSuite global = new GlobalSuite(root);

            module = new Module(modules, name, global, scopes);

            ModuleScope modsc;

            module.ModuleScope = modsc = new ModuleScope(module, null, global);

            PushScope(modsc);

            root.Walk(this);

            foreach (FieldAssignment fer in this.fields)
            {
                fer.Infer(module);
            }
            return(module);
        }
 public void PostWalk(GlobalSuite node)
 {
     AssertCurrent(node); current = current.Parent;
 }
 // GlobalSuite
 public bool Walk(GlobalSuite node)
 {
     current = node; return(Process(node));
 }
Beispiel #6
0
 public ModuleScope(Module module, Scope parent, GlobalSuite statement)
     : base(module, parent)
 {
     this.statement = statement;
 }
 // GlobalSuite
 public override void PostWalk(GlobalSuite node)
 {
     PopScope();
 }
 private List <Inferred> InferGlobalScope(GlobalSuite node, Scope scope)
 {
     Debug.Print("Not implemented: InferGlobalScopeIn");
     return(null);
 }