diff --git a/compiler/passes.nim b/compiler/passes.nim index 7966ee88d9..d63a796924 100644 --- a/compiler/passes.nim +++ b/compiler/passes.nim @@ -13,7 +13,7 @@ import strutils, options, ast, astalgo, llstream, msgs, platform, os, condsyms, idents, renderer, types, extccomp, math, magicsys, nversion, - nimsets, syntaxes, times, rodread, idgen, modulegraphs + nimsets, syntaxes, times, rodread, idgen, modulegraphs, reorder type TPassContext* = object of RootObj # the pass's context @@ -210,6 +210,8 @@ proc processModule*(graph: ModuleGraph; module: PSym, stream: PLLStream, var n = parseTopLevelStmt(p) if n.kind == nkEmpty: break sl.add n + if isDefined"nimreorder": + sl = reorder sl discard processTopLevelStmt(sl, a) break elif not processTopLevelStmt(n, a): break diff --git a/compiler/reorder.nim b/compiler/reorder.nim new file mode 100644 index 0000000000..215bc41123 --- /dev/null +++ b/compiler/reorder.nim @@ -0,0 +1,102 @@ + +import intsets, tables, ast, idents, renderer + +const + nfTempMark = nfTransf + nfPermMark = nfNoRewrite + +proc accQuoted(n: PNode): PIdent = + var id = "" + for i in 0 .. = 3: + decl(a[0]) + for i in 1..