diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2017-07-26 08:20:02 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2017-07-26 08:20:11 +0200 |
commit | 50f62ff44a4c448eceacd2d0f8b8fe8457a2e820 (patch) | |
tree | 1b251159a9c04f819c137455cfced1a22c71ce5b | |
parent | e00953cbc08b0eed3fec6044216e5764c85da076 (diff) | |
download | Nim-50f62ff44a4c448eceacd2d0f8b8fe8457a2e820.tar.gz |
distinguish between 'reorder' and 'noforward'
-rw-r--r-- | compiler/ast.nim | 2 | ||||
-rw-r--r-- | compiler/passes.nim | 4 | ||||
-rw-r--r-- | compiler/pragmas.nim | 9 | ||||
-rw-r--r-- | compiler/wordrecg.nim | 4 | ||||
-rw-r--r-- | tests/modules/treorder.nim | 42 |
5 files changed, 53 insertions, 8 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index 6e651ed00..2e6da06c6 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -292,6 +292,8 @@ const sfNoForward* = sfRegister # forward declarations are not required (per module) + sfReorder* = sfForward + # reordering pass is enabled sfCompileToCpp* = sfInfixCall # compile the module as C++ code sfCompileToObjc* = sfNamedParamCall # compile the module as Objective-C code diff --git a/compiler/passes.nim b/compiler/passes.nim index d63a79692..bf6ce1a0a 100644 --- a/compiler/passes.nim +++ b/compiler/passes.nim @@ -202,7 +202,7 @@ proc processModule*(graph: ModuleGraph; module: PSym, stream: PLLStream, if graph.stopCompile(): break var n = parseTopLevelStmt(p) if n.kind == nkEmpty: break - if sfNoForward in module.flags: + if {sfNoForward, sfReorder} * module.flags != {}: # read everything, no streaming possible var sl = newNodeI(nkStmtList, n.info) sl.add n @@ -210,7 +210,7 @@ proc processModule*(graph: ModuleGraph; module: PSym, stream: PLLStream, var n = parseTopLevelStmt(p) if n.kind == nkEmpty: break sl.add n - if isDefined"nimreorder": + if sfReorder in module.flags: sl = reorder sl discard processTopLevelStmt(sl, a) break diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index 7e1db5b29..bc3771700 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -45,7 +45,7 @@ const wFatal, wDefine, wUndef, wCompile, wLink, wLinksys, wPure, wPush, wPop, wBreakpoint, wWatchPoint, wPassl, wPassc, wDeadCodeElim, wDeprecated, wFloatchecks, wInfChecks, wNanChecks, wPragma, wEmit, wUnroll, - wLinearScanEnd, wPatterns, wEffects, wNoForward, wComputedGoto, + wLinearScanEnd, wPatterns, wEffects, wNoForward, wReorder, wComputedGoto, wInjectStmt, wDeprecated, wExperimental, wThis} lambdaPragmas* = {FirstCallConv..LastCallConv, wImportc, wExportc, wNodecl, wNosideeffect, wSideeffect, wNoreturn, wDynlib, wHeader, @@ -210,9 +210,9 @@ proc pragmaDeadCodeElim(c: PContext, n: PNode) = if isTurnedOn(c, n): incl(c.module.flags, sfDeadCodeElim) else: excl(c.module.flags, sfDeadCodeElim) -proc pragmaNoForward(c: PContext, n: PNode) = - if isTurnedOn(c, n): incl(c.module.flags, sfNoForward) - else: excl(c.module.flags, sfNoForward) +proc pragmaNoForward(c: PContext, n: PNode; flag=sfNoForward) = + if isTurnedOn(c, n): incl(c.module.flags, flag) + else: excl(c.module.flags, flag) proc processCallConv(c: PContext, n: PNode) = if (n.kind == nkExprColonExpr) and (n.sons[1].kind == nkIdent): @@ -726,6 +726,7 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: int, incl(sym.flags, sfThread) of wDeadCodeElim: pragmaDeadCodeElim(c, it) of wNoForward: pragmaNoForward(c, it) + of wReorder: pragmaNoForward(c, it, sfReorder) of wMagic: processMagic(c, it, sym) of wCompileTime: noVal(it) diff --git a/compiler/wordrecg.nim b/compiler/wordrecg.nim index 98fd912d8..773ab8ff5 100644 --- a/compiler/wordrecg.nim +++ b/compiler/wordrecg.nim @@ -55,7 +55,7 @@ type wFloatchecks, wNanChecks, wInfChecks, wAssertions, wPatterns, wWarnings, wHints, wOptimization, wRaises, wWrites, wReads, wSize, wEffects, wTags, - wDeadCodeElim, wSafecode, wNoForward, wNoRewrite, + wDeadCodeElim, wSafecode, wNoForward, wReorder, wNoRewrite, wPragma, wCompileTime, wNoInit, wPassc, wPassl, wBorrow, wDiscardable, @@ -143,7 +143,7 @@ const "assertions", "patterns", "warnings", "hints", "optimization", "raises", "writes", "reads", "size", "effects", "tags", - "deadcodeelim", "safecode", "noforward", "norewrite", + "deadcodeelim", "safecode", "noforward", "reorder", "norewrite", "pragma", "compiletime", "noinit", "passc", "passl", "borrow", "discardable", "fieldchecks", diff --git a/tests/modules/treorder.nim b/tests/modules/treorder.nim new file mode 100644 index 000000000..abe74c5df --- /dev/null +++ b/tests/modules/treorder.nim @@ -0,0 +1,42 @@ +discard """ + cmd: "nim -d:testdef $target $file" + output: '''works 34 +34 +defined +first impl''' +""" + +{.reorder: on.} + +{.push callconv: stdcall.} +proc bar(x: T) + +proc foo() = + bar(34) + whendep() + +proc foo(dummy: int) = echo dummy + +proc bar(x: T) = + echo "works ", x + foo(x) + +foo() + +type + T = int + +when defined(testdef): + proc whendep() = echo "defined" +else: + proc whendep() = echo "undefined" + +when not declared(goo): + proc goo() = echo "first impl" + +when not declared(goo): + proc goo() = echo "second impl" + +goo() + +{.pop.} |