diff options
Diffstat (limited to 'compiler/passes.nim')
-rw-r--r-- | compiler/passes.nim | 139 |
1 files changed, 58 insertions, 81 deletions
diff --git a/compiler/passes.nim b/compiler/passes.nim index f266d2a6b..997a10cd8 100644 --- a/compiler/passes.nim +++ b/compiler/passes.nim @@ -13,7 +13,7 @@ import options, ast, llstream, msgs, idents, - syntaxes, modulegraphs, reorder, rod, + syntaxes, modulegraphs, reorder, lineinfos, pathutils type @@ -119,88 +119,65 @@ proc processModule*(graph: ModuleGraph; module: PSym; idgen: IdGenerator; s: PLLStream fileIdx = module.fileIdx prepareConfigNotes(graph, module) - if module.id < 0: - # new module caching mechanism: - for i in 0..<graph.passes.len: - if not isNil(graph.passes[i].open) and not graph.passes[i].isFrontend: - a[i] = graph.passes[i].open(graph, module, idgen) - else: - a[i] = nil - - if not graph.stopCompile(): - let n = loadNode(graph, module) - var m = n - for i in 0..<graph.passes.len: - if not isNil(graph.passes[i].process) and not graph.passes[i].isFrontend: - m = graph.passes[i].process(a[i], m) - if isNil(m): - break - - var m: PNode = nil - for i in 0..<graph.passes.len: - if not isNil(graph.passes[i].close) and not graph.passes[i].isFrontend: - m = graph.passes[i].close(graph, a[i], m) - a[i] = nil + openPasses(graph, a, module, idgen) + if stream == nil: + let filename = toFullPathConsiderDirty(graph.config, fileIdx) + s = llStreamOpen(filename, fmRead) + if s == nil: + rawMessage(graph.config, errCannotOpenFile, filename.string) + return false else: - openPasses(graph, a, module, idgen) - if stream == nil: - let filename = toFullPathConsiderDirty(graph.config, fileIdx) - s = llStreamOpen(filename, fmRead) - if s == nil: - rawMessage(graph.config, errCannotOpenFile, filename.string) - return false - else: - s = stream + s = stream + while true: + openParser(p, fileIdx, s, graph.cache, graph.config) + + if module.owner == nil or module.owner.name.s != "stdlib" or module.name.s == "distros": + # XXX what about caching? no processing then? what if I change the + # modules to include between compilation runs? we'd need to track that + # in ROD files. I think we should enable this feature only + # for the interactive mode. + if module.name.s != "nimscriptapi": + processImplicits graph, graph.config.implicitImports, nkImportStmt, a, module + processImplicits graph, graph.config.implicitIncludes, nkIncludeStmt, a, module + while true: - openParser(p, fileIdx, s, graph.cache, graph.config) - - if module.owner == nil or module.owner.name.s != "stdlib" or module.name.s == "distros": - # XXX what about caching? no processing then? what if I change the - # modules to include between compilation runs? we'd need to track that - # in ROD files. I think we should enable this feature only - # for the interactive mode. - if module.name.s != "nimscriptapi": - processImplicits graph, graph.config.implicitImports, nkImportStmt, a, module - processImplicits graph, graph.config.implicitIncludes, nkIncludeStmt, a, module - - while true: - if graph.stopCompile(): break - var n = parseTopLevelStmt(p) - if n.kind == nkEmpty: break - if (sfSystemModule notin module.flags and - ({sfNoForward, sfReorder} * module.flags != {} or - codeReordering in graph.config.features)): - # read everything, no streaming possible - var sl = newNodeI(nkStmtList, n.info) + if graph.stopCompile(): break + var n = parseTopLevelStmt(p) + if n.kind == nkEmpty: break + if (sfSystemModule notin module.flags and + ({sfNoForward, sfReorder} * module.flags != {} or + codeReordering in graph.config.features)): + # read everything, no streaming possible + var sl = newNodeI(nkStmtList, n.info) + sl.add n + while true: + var n = parseTopLevelStmt(p) + if n.kind == nkEmpty: break sl.add n - while true: - var n = parseTopLevelStmt(p) - if n.kind == nkEmpty: break - sl.add n - if sfReorder in module.flags or codeReordering in graph.config.features: - sl = reorder(graph, sl, module) - discard processTopLevelStmt(graph, sl, a) - break - elif n.kind in imperativeCode: - # read everything until the next proc declaration etc. - var sl = newNodeI(nkStmtList, n.info) + if sfReorder in module.flags or codeReordering in graph.config.features: + sl = reorder(graph, sl, module) + discard processTopLevelStmt(graph, sl, a) + break + elif n.kind in imperativeCode: + # read everything until the next proc declaration etc. + var sl = newNodeI(nkStmtList, n.info) + sl.add n + var rest: PNode = nil + while true: + var n = parseTopLevelStmt(p) + if n.kind == nkEmpty or n.kind notin imperativeCode: + rest = n + break sl.add n - var rest: PNode = nil - while true: - var n = parseTopLevelStmt(p) - if n.kind == nkEmpty or n.kind notin imperativeCode: - rest = n - break - sl.add n - #echo "-----\n", sl - if not processTopLevelStmt(graph, sl, a): break - if rest != nil: - #echo "-----\n", rest - if not processTopLevelStmt(graph, rest, a): break - else: - #echo "----- single\n", n - if not processTopLevelStmt(graph, n, a): break - closeParser(p) - if s.kind != llsStdIn: break - closePasses(graph, a) + #echo "-----\n", sl + if not processTopLevelStmt(graph, sl, a): break + if rest != nil: + #echo "-----\n", rest + if not processTopLevelStmt(graph, rest, a): break + else: + #echo "----- single\n", n + if not processTopLevelStmt(graph, n, a): break + closeParser(p) + if s.kind != llsStdIn: break + closePasses(graph, a) result = true |