summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2018-05-28 23:48:25 +0200
committerAndreas Rumpf <rumpf_a@web.de>2018-05-28 23:48:25 +0200
commitb92fcacb9995064a500e0d45485ebd5a1db1f237 (patch)
tree74f94f1ab1425063c398ab782f4608cb69e3db19 /compiler
parent83834be938d64e58888b13d8321104da29686559 (diff)
downloadNim-b92fcacb9995064a500e0d45485ebd5a1db1f237.tar.gz
more compiler API cleanups
Diffstat (limited to 'compiler')
-rw-r--r--compiler/main.nim42
-rw-r--r--compiler/passes.nim4
-rw-r--r--compiler/scriptconfig.nim7
3 files changed, 25 insertions, 28 deletions
diff --git a/compiler/main.nim b/compiler/main.nim
index aa0cc9b39..c5b2ddca5 100644
--- a/compiler/main.nim
+++ b/compiler/main.nim
@@ -22,14 +22,14 @@ from magicsys import resetSysTypes
 
 proc rodPass(g: ModuleGraph) =
   if g.config.symbolFiles in {enabledSf, writeOnlySf}:
-    registerPass(rodwritePass)
+    registerPass(g, rodwritePass)
 
-proc codegenPass =
-  registerPass cgenPass
+proc codegenPass(g: ModuleGraph) =
+  registerPass g, cgenPass
 
-proc semanticPasses =
-  registerPass verbosePass
-  registerPass semPass
+proc semanticPasses(g: ModuleGraph) =
+  registerPass g, verbosePass
+  registerPass g, semPass
 
 proc writeDepsFile(g: ModuleGraph; project: string) =
   let f = open(changeFileExt(project, "deps"), fmWrite)
@@ -42,8 +42,8 @@ proc writeDepsFile(g: ModuleGraph; project: string) =
   f.close()
 
 proc commandGenDepend(graph: ModuleGraph; cache: IdentCache) =
-  semanticPasses()
-  registerPass(gendependPass)
+  semanticPasses(graph)
+  registerPass(graph, gendependPass)
   #registerPass(cleanupPass)
   compileProject(graph, cache)
   let project = graph.config.projectFull
@@ -55,15 +55,15 @@ proc commandGenDepend(graph: ModuleGraph; cache: IdentCache) =
 proc commandCheck(graph: ModuleGraph; cache: IdentCache) =
   graph.config.errorMax = high(int)  # do not stop after first error
   defineSymbol(graph.config.symbols, "nimcheck")
-  semanticPasses()            # use an empty backend for semantic checking only
+  semanticPasses(graph)  # use an empty backend for semantic checking only
   rodPass(graph)
   compileProject(graph, cache)
 
 proc commandDoc2(graph: ModuleGraph; cache: IdentCache; json: bool) =
   graph.config.errorMax = high(int)  # do not stop after first error
-  semanticPasses()
-  if json: registerPass(docgen2JsonPass)
-  else: registerPass(docgen2Pass)
+  semanticPasses(graph)
+  if json: registerPass(graph, docgen2JsonPass)
+  else: registerPass(graph, docgen2Pass)
   #registerPass(cleanupPass())
   compileProject(graph, cache)
   finishDoc2Pass(graph.config.projectName)
@@ -71,8 +71,8 @@ proc commandDoc2(graph: ModuleGraph; cache: IdentCache; json: bool) =
 proc commandCompileToC(graph: ModuleGraph; cache: IdentCache) =
   let conf = graph.config
   extccomp.initVars(conf)
-  semanticPasses()
-  registerPass(cgenPass)
+  semanticPasses(graph)
+  registerPass(graph, cgenPass)
   rodPass(graph)
   #registerPass(cleanupPass())
 
@@ -95,17 +95,17 @@ proc commandCompileToJS(graph: ModuleGraph; cache: IdentCache) =
   #initDefines()
   defineSymbol(graph.config.symbols, "ecmascript") # For backward compatibility
   defineSymbol(graph.config.symbols, "js")
-  semanticPasses()
-  registerPass(JSgenPass)
+  semanticPasses(graph)
+  registerPass(graph, JSgenPass)
   compileProject(graph, cache)
 
 proc interactivePasses(graph: ModuleGraph; cache: IdentCache) =
   initDefines(graph.config.symbols)
   defineSymbol(graph.config.symbols, "nimscript")
   when hasFFI: defineSymbol(graph.config.symbols, "nimffi")
-  registerPass(verbosePass)
-  registerPass(semPass)
-  registerPass(evalPass)
+  registerPass(graph, verbosePass)
+  registerPass(graph, semPass)
+  registerPass(graph, evalPass)
 
 proc commandInteractive(graph: ModuleGraph; cache: IdentCache) =
   graph.config.errorMax = high(int)  # do not stop after first error
@@ -156,7 +156,7 @@ proc mainCommand*(graph: ModuleGraph; cache: IdentCache) =
 
   setupModuleCache()
   # In "nim serve" scenario, each command must reset the registered passes
-  clearPasses()
+  clearPasses(graph)
   conf.lastCmdTime = epochTime()
   conf.searchPaths.add(conf.libpath)
   setId(100)
@@ -300,5 +300,3 @@ proc mainCommand*(graph: ModuleGraph; cache: IdentCache) =
                                        ffDecimal, 3)
 
   resetAttributes(conf)
-
-#proc mainCommand*() = mainCommand(newModuleGraph(newConfigRef()), newIdentCache())
diff --git a/compiler/passes.nim b/compiler/passes.nim
index 3fe7ce481..9be7d060a 100644
--- a/compiler/passes.nim
+++ b/compiler/passes.nim
@@ -74,10 +74,10 @@ var
   gPasses: array[0..maxPasses - 1, TPass]
   gPassesLen*: int
 
-proc clearPasses* =
+proc clearPasses*(g: ModuleGraph) =
   gPassesLen = 0
 
-proc registerPass*(p: TPass) =
+proc registerPass*(g: ModuleGraph; p: TPass) =
   gPasses[gPassesLen] = p
   inc(gPassesLen)
 
diff --git a/compiler/scriptconfig.nim b/compiler/scriptconfig.nim
index ac86e8e0c..30bdf162e 100644
--- a/compiler/scriptconfig.nim
+++ b/compiler/scriptconfig.nim
@@ -152,15 +152,14 @@ proc setupVM*(module: PSym; cache: IdentCache; scriptName: string;
 proc runNimScript*(cache: IdentCache; scriptName: string;
                    freshDefines=true; conf: ConfigRef) =
   rawMessage(conf, hintConf, scriptName)
-  passes.gIncludeFile = includeModule
-  passes.gImportModule = importModule
+
   let graph = newModuleGraph(cache, conf)
   if freshDefines: initDefines(conf.symbols)
 
   defineSymbol(conf.symbols, "nimscript")
   defineSymbol(conf.symbols, "nimconfig")
-  registerPass(semPass)
-  registerPass(evalPass)
+  registerPass(graph, semPass)
+  registerPass(graph, evalPass)
 
   conf.searchPaths.add(conf.libpath)