diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2018-05-13 08:51:11 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-05-13 08:51:11 +0200 |
commit | 342e50e26c7023a8ac6829b02d27c3810cb45d05 (patch) | |
tree | f24313dc9556830ac5594bf791d2ae9600c3a932 /compiler | |
parent | 8ca5b71c6aead09fe78b31f4863d2b2c083ad075 (diff) | |
download | Nim-342e50e26c7023a8ac6829b02d27c3810cb45d05.tar.gz |
compiler compiles again; simple programs do work
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/main.nim | 148 | ||||
-rw-r--r-- | compiler/modules.nim | 15 | ||||
-rw-r--r-- | compiler/nim.nim | 83 | ||||
-rw-r--r-- | compiler/scriptconfig.nim | 64 |
4 files changed, 152 insertions, 158 deletions
diff --git a/compiler/main.nim b/compiler/main.nim index f23a3a88e..b9afc6a8d 100644 --- a/compiler/main.nim +++ b/compiler/main.nim @@ -16,9 +16,9 @@ import cgen, jsgen, json, nversion, platform, nimconf, importer, passaux, depends, vm, vmdef, types, idgen, docgen2, service, parser, modules, ccgutils, sigmatch, ropes, - modulegraphs, tables, rod + modulegraphs, tables, rod, configuration -from magicsys import systemModule, resetSysTypes +from magicsys import resetSysTypes proc rodPass = if gSymbolFiles in {enabledSf, writeOnlySf}: @@ -46,54 +46,55 @@ proc commandGenDepend(graph: ModuleGraph; cache: IdentCache) = registerPass(gendependPass) #registerPass(cleanupPass) compileProject(graph, cache) - writeDepsFile(graph, gProjectFull) - generateDot(gProjectFull) - execExternalProgram("dot -Tpng -o" & changeFileExt(gProjectFull, "png") & - ' ' & changeFileExt(gProjectFull, "dot")) + let project = graph.config.projectFull + writeDepsFile(graph, project) + generateDot(project) + execExternalProgram(graph.config, "dot -Tpng -o" & changeFileExt(project, "png") & + ' ' & changeFileExt(project, "dot")) proc commandCheck(graph: ModuleGraph; cache: IdentCache) = - msgs.gErrorMax = high(int) # do not stop after first error - defineSymbol("nimcheck") + 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 rodPass() compileProject(graph, cache) proc commandDoc2(graph: ModuleGraph; cache: IdentCache; json: bool) = - msgs.gErrorMax = high(int) # do not stop after first error + graph.config.errorMax = high(int) # do not stop after first error semanticPasses() if json: registerPass(docgen2JsonPass) else: registerPass(docgen2Pass) #registerPass(cleanupPass()) compileProject(graph, cache) - finishDoc2Pass(gProjectName) + finishDoc2Pass(graph.config.projectName) proc commandCompileToC(graph: ModuleGraph; cache: IdentCache) = - extccomp.initVars() + let conf = graph.config + extccomp.initVars(conf) semanticPasses() registerPass(cgenPass) rodPass() #registerPass(cleanupPass()) compileProject(graph, cache) - cgenWriteModules(graph.backend, graph.config) + cgenWriteModules(graph.backend, conf) if gCmd != cmdRun: - let proj = changeFileExt(gProjectFull, "") - extccomp.callCCompiler(proj) - extccomp.writeJsonBuildInstructions(proj) + let proj = changeFileExt(conf.projectFull, "") + extccomp.callCCompiler(conf, proj) + extccomp.writeJsonBuildInstructions(conf, proj) if optGenScript in gGlobalOptions: - writeDepsFile(graph, toGeneratedFile(proj, "")) + writeDepsFile(graph, toGeneratedFile(conf, proj, "")) proc commandJsonScript(graph: ModuleGraph; cache: IdentCache) = - let proj = changeFileExt(gProjectFull, "") - extccomp.runJsonBuildInstructions(proj) + let proj = changeFileExt(graph.config.projectFull, "") + extccomp.runJsonBuildInstructions(graph.config, proj) proc commandCompileToJS(graph: ModuleGraph; cache: IdentCache) = #incl(gGlobalOptions, optSafeCode) setTarget(osJS, cpuJS) #initDefines() - defineSymbol("nimrod") # 'nimrod' is always defined - defineSymbol("ecmascript") # For backward compatibility - defineSymbol("js") + defineSymbol(graph.config.symbols, "ecmascript") # For backward compatibility + defineSymbol(graph.config.symbols, "js") semanticPasses() registerPass(JSgenPass) compileProject(graph, cache) @@ -101,19 +102,19 @@ proc commandCompileToJS(graph: ModuleGraph; cache: IdentCache) = proc interactivePasses(graph: ModuleGraph; cache: IdentCache) = #incl(gGlobalOptions, optSafeCode) #setTarget(osNimrodVM, cpuNimrodVM) - initDefines() - defineSymbol("nimscript") - when hasFFI: defineSymbol("nimffi") + initDefines(graph.config.symbols) + defineSymbol(graph.config.symbols, "nimscript") + when hasFFI: defineSymbol(graph.config.symbols, "nimffi") registerPass(verbosePass) registerPass(semPass) registerPass(evalPass) proc commandInteractive(graph: ModuleGraph; cache: IdentCache) = - msgs.gErrorMax = high(int) # do not stop after first error + graph.config.errorMax = high(int) # do not stop after first error interactivePasses(graph, cache) compileSystemModule(graph, cache) - if commandArgs.len > 0: - discard graph.compileModule(fileInfoIdx(gProjectFull), cache, {}) + if graph.config.commandArgs.len > 0: + discard graph.compileModule(fileInfoIdx(graph.config, graph.config.projectFull), cache, {}) else: var m = graph.makeStdinModule() incl(m.flags, sfMainModule) @@ -125,7 +126,7 @@ proc evalNim(graph: ModuleGraph; nodes: PNode, module: PSym; cache: IdentCache) carryPasses(graph, nodes, module, cache, evalPasses) proc commandEval(graph: ModuleGraph; cache: IdentCache; exp: string) = - if systemModule == nil: + if graph.systemModule == nil: interactivePasses(graph, cache) compileSystemModule(graph, cache) let echoExp = "echo \"eval\\t\", " & "repr(" & exp & ")" @@ -133,7 +134,7 @@ proc commandEval(graph: ModuleGraph; cache: IdentCache; exp: string) = makeStdinModule(graph), cache) proc commandScan(cache: IdentCache, config: ConfigRef) = - var f = addFileExt(mainCommandArg(), NimExt) + var f = addFileExt(mainCommandArg(config), NimExt) var stream = llStreamOpen(f, fmRead) if stream != nil: var @@ -147,37 +148,32 @@ proc commandScan(cache: IdentCache, config: ConfigRef) = if tok.tokType == tkEof: break closeLexer(L) else: - rawMessage(errCannotOpenFile, f) + rawMessage(config, errGenerated, "cannot open file: " & f) const - SimulateCaasMemReset = false PrintRopeCacheStats = false proc mainCommand*(graph: ModuleGraph; cache: IdentCache) = - when SimulateCaasMemReset: - gGlobalOptions.incl(optCaasEnabled) + let conf = graph.config setupModuleCache() # In "nim serve" scenario, each command must reset the registered passes clearPasses() gLastCmdTime = epochTime() - searchPaths.add(options.libpath) - when false: # gProjectFull.len != 0: - # current path is always looked first for modules - prependStr(searchPaths, gProjectPath) + conf.searchPaths.add(conf.libpath) setId(100) - case command.normalize + case conf.command.normalize of "c", "cc", "compile", "compiletoc": # compile means compileToC currently gCmd = cmdCompileToC commandCompileToC(graph, cache) of "cpp", "compiletocpp": gCmd = cmdCompileToCpp - defineSymbol("cpp") + defineSymbol(graph.config.symbols, "cpp") commandCompileToC(graph, cache) of "objc", "compiletooc": gCmd = cmdCompileToOC - defineSymbol("objc") + defineSymbol(graph.config.symbols, "objc") commandCompileToC(graph, cache) of "run": gCmd = cmdRun @@ -185,69 +181,68 @@ proc mainCommand*(graph: ModuleGraph; cache: IdentCache) = extccomp.setCC("tcc") commandCompileToC(graph, cache) else: - rawMessage(errInvalidCommandX, command) + rawMessage(conf, errGenerated, "'run' command not available; rebuild with -d:tinyc") of "js", "compiletojs": gCmd = cmdCompileToJS commandCompileToJS(graph, cache) of "doc0": - wantMainModule() + wantMainModule(conf) gCmd = cmdDoc loadConfigs(DocConfig, cache) - commandDoc() + commandDoc(conf) of "doc2", "doc": gCmd = cmdDoc loadConfigs(DocConfig, cache) - defineSymbol("nimdoc") + defineSymbol(conf.symbols, "nimdoc") commandDoc2(graph, cache, false) of "rst2html": gCmd = cmdRst2html loadConfigs(DocConfig, cache) - commandRst2Html() + commandRst2Html(conf) of "rst2tex": gCmd = cmdRst2tex loadConfigs(DocTexConfig, cache) - commandRst2TeX() + commandRst2TeX(conf) of "jsondoc0": - wantMainModule() + wantMainModule(conf) gCmd = cmdDoc loadConfigs(DocConfig, cache) - wantMainModule() - defineSymbol("nimdoc") - commandJson() + wantMainModule(conf) + defineSymbol(conf.symbols, "nimdoc") + commandJson(conf) of "jsondoc2", "jsondoc": gCmd = cmdDoc loadConfigs(DocConfig, cache) - wantMainModule() - defineSymbol("nimdoc") + wantMainModule(conf) + defineSymbol(conf.symbols, "nimdoc") commandDoc2(graph, cache, true) of "ctags": - wantMainModule() + wantMainModule(conf) gCmd = cmdDoc loadConfigs(DocConfig, cache) - wantMainModule() - defineSymbol("nimdoc") - commandTags() + defineSymbol(conf.symbols, "nimdoc") + commandTags(conf) of "buildindex": gCmd = cmdDoc loadConfigs(DocConfig, cache) - commandBuildIndex() + commandBuildIndex(conf) of "gendepend": gCmd = cmdGenDepend commandGenDepend(graph, cache) of "dump": gCmd = cmdDump - if getConfigVar("dump.format") == "json": - wantMainModule() + if getConfigVar(conf, "dump.format") == "json": + wantMainModule(conf) var definedSymbols = newJArray() - for s in definedSymbolNames(): definedSymbols.elems.add(%s) + for s in definedSymbolNames(conf.symbols): definedSymbols.elems.add(%s) var libpaths = newJArray() - for dir in searchPaths: libpaths.elems.add(%dir) + for dir in conf.searchPaths: libpaths.elems.add(%dir) var dumpdata = % [ (key: "version", val: %VersionAsString), - (key: "project_path", val: %gProjectFull), + (key: "project_path", val: %conf.projectFull), (key: "defined_symbols", val: definedSymbols), (key: "lib_paths", val: libpaths) ] @@ -256,27 +251,27 @@ proc mainCommand*(graph: ModuleGraph; cache: IdentCache) = else: msgWriteln("-- list of currently defined symbols --", {msgStdout, msgSkipHook}) - for s in definedSymbolNames(): msgWriteln(s, {msgStdout, msgSkipHook}) + for s in definedSymbolNames(conf.symbols): msgWriteln(s, {msgStdout, msgSkipHook}) msgWriteln("-- end of list --", {msgStdout, msgSkipHook}) - for it in searchPaths: msgWriteln(it) + for it in conf.searchPaths: msgWriteln(it) of "check": gCmd = cmdCheck commandCheck(graph, cache) of "parse": gCmd = cmdParse - wantMainModule() - discard parseFile(FileIndex gProjectMainIdx, cache, graph.config) + wantMainModule(conf) + discard parseFile(FileIndex conf.projectMainIdx, cache, conf) of "scan": gCmd = cmdScan - wantMainModule() - commandScan(cache, graph.config) + wantMainModule(conf) + commandScan(cache, conf) msgWriteln("Beware: Indentation tokens depend on the parser's state!") of "secret": gCmd = cmdInteractive commandInteractive(graph, cache) of "e": - commandEval(graph, cache, mainCommandArg()) + commandEval(graph, cache, mainCommandArg(conf)) of "nop", "help": # prevent the "success" message: gCmd = cmdDump @@ -284,18 +279,18 @@ proc mainCommand*(graph: ModuleGraph; cache: IdentCache) = gCmd = cmdJsonScript commandJsonScript(graph, cache) else: - rawMessage(errInvalidCommandX, command) + rawMessage(conf, errGenerated, "invalid command: " & conf.command) - if msgs.gErrorCounter == 0 and + if conf.errorCounter == 0 and gCmd notin {cmdInterpret, cmdRun, cmdDump}: when declared(system.getMaxMem): let usedMem = formatSize(getMaxMem()) & " peakmem" else: let usedMem = formatSize(getTotalMem()) - rawMessage(hintSuccessX, [$graph.config.linesCompiled, + rawMessage(conf, hintSuccessX, [$conf.linesCompiled, formatFloat(epochTime() - gLastCmdTime, ffDecimal, 3), usedMem, - if condSyms.isDefined("release"): "Release Build" + if isDefined(conf, "release"): "Release Build" else: "Debug Build"]) when PrintRopeCacheStats: @@ -306,9 +301,6 @@ proc mainCommand*(graph: ModuleGraph; cache: IdentCache) = echo " efficiency: ", formatFloat(1-(gCacheMisses.float/gCacheTries.float), ffDecimal, 3) - when SimulateCaasMemReset: - resetMemory() + resetAttributes(conf) - resetAttributes() - -proc mainCommand*() = mainCommand(newModuleGraph(newConfigRef()), newIdentCache()) +#proc mainCommand*() = mainCommand(newModuleGraph(newConfigRef()), newIdentCache()) diff --git a/compiler/modules.nim b/compiler/modules.nim index 47da90c5a..3da1bbbc7 100644 --- a/compiler/modules.nim +++ b/compiler/modules.nim @@ -115,22 +115,23 @@ proc includeModule*(graph: ModuleGraph; s: PSym, fileIdx: FileIndex; proc compileSystemModule*(graph: ModuleGraph; cache: IdentCache) = if graph.systemModule == nil: - systemFileIdx = fileInfoIdx(graph.config.libpath / "system.nim") + systemFileIdx = fileInfoIdx(graph.config, graph.config.libpath / "system.nim") discard graph.compileModule(systemFileIdx, cache, {sfSystemModule}) proc wantMainModule*(conf: ConfigRef) = if conf.projectFull.len == 0: - fatal(gCmdLineInfo, errCommandExpectsFilename) - conf.projectMainIdx = int32 addFileExt(conf.projectFull, NimExt).fileInfoIdx + fatal(conf, newLineInfo(conf, "command line", 1, 1), errGenerated, "command expects a filename") + conf.projectMainIdx = int32 fileInfoIdx(conf, addFileExt(conf.projectFull, NimExt)) passes.gIncludeFile = includeModule passes.gImportModule = importModule proc compileProject*(graph: ModuleGraph; cache: IdentCache; projectFileIdx = InvalidFileIDX) = - wantMainModule(graph.config) - let systemFileIdx = fileInfoIdx(graph.config.libpath / "system.nim") - let projectFile = if projectFileIdx == InvalidFileIDX: FileIndex(gProjectMainIdx) else: projectFileIdx + let conf = graph.config + wantMainModule(conf) + let systemFileIdx = fileInfoIdx(conf, conf.libpath / "system.nim") + let projectFile = if projectFileIdx == InvalidFileIDX: FileIndex(conf.projectMainIdx) else: projectFileIdx graph.importStack.add projectFile if projectFile == systemFileIdx: discard graph.compileModule(projectFile, cache, {sfMainModule, sfSystemModule}) @@ -139,7 +140,7 @@ proc compileProject*(graph: ModuleGraph; cache: IdentCache; discard graph.compileModule(projectFile, cache, {sfMainModule}) proc makeModule*(graph: ModuleGraph; filename: string): PSym = - result = graph.newModule(fileInfoIdx filename) + result = graph.newModule(fileInfoIdx(graph.config, filename)) result.id = getID() proc makeStdinModule*(graph: ModuleGraph): PSym = graph.makeModule"stdin" diff --git a/compiler/nim.nim b/compiler/nim.nim index b39eefd65..d8402a2af 100644 --- a/compiler/nim.nim +++ b/compiler/nim.nim @@ -21,7 +21,7 @@ when defined(i386) and defined(windows) and defined(vcc): import commands, lexer, condsyms, options, msgs, nversion, nimconf, ropes, extccomp, strutils, os, osproc, platform, main, parseopt, service, - nodejs, scriptconfig, idents, modulegraphs + nodejs, scriptconfig, idents, modulegraphs, configuration when hasTinyCBackend: import tccgen @@ -37,69 +37,70 @@ proc prependCurDir(f: string): string = else: result = f -proc handleCmdLine(cache: IdentCache; config: ConfigRef) = +proc handleCmdLine(cache: IdentCache; conf: ConfigRef) = + condsyms.initDefines(conf.symbols) if paramCount() == 0: - writeCommandLineUsage(config.helpWritten) + writeCommandLineUsage(conf.helpWritten) else: # Process command line arguments: - processCmdLine(passCmd1, "", config) - if gProjectName == "-": - gProjectName = "stdinfile" - gProjectFull = "stdinfile" - gProjectPath = canonicalizePath getCurrentDir() - gProjectIsStdin = true - elif gProjectName != "": + processCmdLine(passCmd1, "", conf) + if conf.projectName == "-": + conf.projectName = "stdinfile" + conf.projectFull = "stdinfile" + conf.projectPath = canonicalizePath(conf, getCurrentDir()) + conf.projectIsStdin = true + elif conf.projectName != "": try: - gProjectFull = canonicalizePath(gProjectName) + conf.projectFull = canonicalizePath(conf, conf.projectName) except OSError: - gProjectFull = gProjectName - let p = splitFile(gProjectFull) + conf.projectFull = conf.projectName + let p = splitFile(conf.projectFull) let dir = if p.dir.len > 0: p.dir else: getCurrentDir() - gProjectPath = canonicalizePath dir - gProjectName = p.name + conf.projectPath = canonicalizePath(conf, dir) + conf.projectName = p.name else: - gProjectPath = canonicalizePath getCurrentDir() - loadConfigs(DefaultConfig, config) # load all config files - let scriptFile = gProjectFull.changeFileExt("nims") + conf.projectPath = canonicalizePath(conf, getCurrentDir()) + loadConfigs(DefaultConfig, conf) # load all config files + let scriptFile = conf.projectFull.changeFileExt("nims") if fileExists(scriptFile): - runNimScript(cache, scriptFile, freshDefines=false, config) + runNimScript(cache, scriptFile, freshDefines=false, conf) # 'nim foo.nims' means to just run the NimScript file and do nothing more: - if scriptFile == gProjectFull: return - elif fileExists(gProjectPath / "config.nims"): + if scriptFile == conf.projectFull: return + elif fileExists(conf.projectPath / "config.nims"): # directory wide NimScript file - runNimScript(cache, gProjectPath / "config.nims", freshDefines=false, config) + runNimScript(cache, conf.projectPath / "config.nims", freshDefines=false, conf) # now process command line arguments again, because some options in the # command line can overwite the config file's settings - extccomp.initVars() - processCmdLine(passCmd2, "", config) - if options.command == "": - rawMessage(errNoCommand, command) - mainCommand(newModuleGraph(config), cache) - if optHints in gOptions and hintGCStats in gNotes: echo(GC_getStatistics()) + extccomp.initVars(conf) + processCmdLine(passCmd2, "", conf) + if conf.command == "": + rawMessage(conf, errGenerated, "command missing") + mainCommand(newModuleGraph(conf), cache) + if optHints in gOptions and hintGCStats in conf.notes: echo(GC_getStatistics()) #echo(GC_getStatistics()) - if msgs.gErrorCounter == 0: + if conf.errorCounter == 0: when hasTinyCBackend: if gCmd == cmdRun: - tccgen.run(config.arguments) + tccgen.run(conf.arguments) if optRun in gGlobalOptions: if gCmd == cmdCompileToJS: var ex: string - if options.outFile.len > 0: - ex = options.outFile.prependCurDir.quoteShell + if conf.outFile.len > 0: + ex = conf.outFile.prependCurDir.quoteShell else: ex = quoteShell( - completeCFilePath(changeFileExt(gProjectFull, "js").prependCurDir)) - execExternalProgram(findNodeJs() & " " & ex & ' ' & config.arguments) + completeCFilePath(conf, changeFileExt(conf.projectFull, "js").prependCurDir)) + execExternalProgram(conf, findNodeJs() & " " & ex & ' ' & conf.arguments) else: var binPath: string - if options.outFile.len > 0: + if conf.outFile.len > 0: # If the user specified an outFile path, use that directly. - binPath = options.outFile.prependCurDir + binPath = conf.outFile.prependCurDir else: # Figure out ourselves a valid binary name. - binPath = changeFileExt(gProjectFull, ExeExt).prependCurDir + binPath = changeFileExt(conf.projectFull, ExeExt).prependCurDir var ex = quoteShell(binPath) - execExternalProgram(ex & ' ' & config.arguments) + execExternalProgram(conf, ex & ' ' & conf.arguments) when declared(GC_setMaxPause): GC_setMaxPause 2_000 @@ -107,10 +108,10 @@ when declared(GC_setMaxPause): when compileOption("gc", "v2") or compileOption("gc", "refc"): # the new correct mark&sweet collector is too slow :-/ GC_disableMarkAndSweep() -condsyms.initDefines() when not defined(selftest): - handleCmdLine(newIdentCache(), newConfigRef()) + let conf = newConfigRef() + handleCmdLine(newIdentCache(), conf) when declared(GC_setMaxPause): echo GC_getStatistics() - msgQuit(int8(msgs.gErrorCounter > 0)) + msgQuit(int8(conf.errorCounter > 0)) diff --git a/compiler/scriptconfig.nim b/compiler/scriptconfig.nim index 0cd5d1be2..30e5e4803 100644 --- a/compiler/scriptconfig.nim +++ b/compiler/scriptconfig.nim @@ -13,7 +13,7 @@ import ast, modules, idents, passes, passaux, condsyms, options, nimconf, sem, semdata, llstream, vm, vmdef, commands, msgs, - os, times, osproc, wordrecg, strtabs, modulegraphs + os, times, osproc, wordrecg, strtabs, modulegraphs, configuration # we support 'cmpIgnoreStyle' natively for efficiency: from strutils import cmpIgnoreStyle, contains @@ -26,11 +26,12 @@ proc listDirs(a: VmArgs, filter: set[PathComponent]) = setResult(a, result) proc setupVM*(module: PSym; cache: IdentCache; scriptName: string; - config: ConfigRef): PEvalContext = + graph: ModuleGraph): PEvalContext = # For Nimble we need to export 'setupVM'. - result = newCtx(module, cache, config) + result = newCtx(module, cache, graph) result.mode = emRepl registerAdditionalOps(result) + let conf = graph.config # captured vars: var errorMsg: string @@ -98,13 +99,13 @@ proc setupVM*(module: PSym; cache: IdentCache; scriptName: string; cbconf thisDir: setResult(a, vthisDir) cbconf put: - options.setConfigVar(getString(a, 0), getString(a, 1)) + options.setConfigVar(conf, getString(a, 0), getString(a, 1)) cbconf get: - setResult(a, options.getConfigVar(a.getString 0)) + setResult(a, options.getConfigVar(conf, a.getString 0)) cbconf exists: - setResult(a, options.existsConfigVar(a.getString 0)) + setResult(a, options.existsConfigVar(conf, a.getString 0)) cbconf nimcacheDir: - setResult(a, options.getNimcacheDir()) + setResult(a, options.getNimcacheDir(conf)) cbconf paramStr: setResult(a, os.paramStr(int a.getInt 0)) cbconf paramCount: @@ -114,67 +115,66 @@ proc setupVM*(module: PSym; cache: IdentCache; scriptName: string; cbconf cmpIgnoreCase: setResult(a, strutils.cmpIgnoreCase(a.getString 0, a.getString 1)) cbconf setCommand: - options.command = a.getString 0 + conf.command = a.getString 0 let arg = a.getString 1 if arg.len > 0: - gProjectName = arg + conf.projectName = arg let path = - if gProjectName.isAbsolute: gProjectName - else: gProjectPath / gProjectName + if conf.projectName.isAbsolute: conf.projectName + else: conf.projectPath / conf.projectName try: - gProjectFull = canonicalizePath(path) + conf.projectFull = canonicalizePath(conf, path) except OSError: - gProjectFull = path + conf.projectFull = path cbconf getCommand: - setResult(a, options.command) + setResult(a, conf.command) cbconf switch: - processSwitch(a.getString 0, a.getString 1, passPP, module.info, config) + processSwitch(a.getString 0, a.getString 1, passPP, module.info, conf) cbconf hintImpl: processSpecificNote(a.getString 0, wHint, passPP, module.info, - a.getString 1, config) + a.getString 1, conf) cbconf warningImpl: processSpecificNote(a.getString 0, wWarning, passPP, module.info, - a.getString 1, config) + a.getString 1, conf) cbconf patchFile: let key = a.getString(0) & "_" & a.getString(1) var val = a.getString(2).addFileExt(NimExt) if {'$', '~'} in val: - val = pathSubs(val, vthisDir) + val = pathSubs(conf, val, vthisDir) elif not isAbsolute(val): val = vthisDir / val - gModuleOverrides[key] = val + conf.moduleOverrides[key] = val cbconf selfExe: setResult(a, os.getAppFilename()) cbconf cppDefine: - if config != nil: - options.cppDefine(config, a.getString(0)) + options.cppDefine(conf, a.getString(0)) proc runNimScript*(cache: IdentCache; scriptName: string; - freshDefines=true; config: ConfigRef) = - rawMessage(hintConf, scriptName) + freshDefines=true; conf: ConfigRef) = + rawMessage(conf, hintConf, scriptName) passes.gIncludeFile = includeModule passes.gImportModule = importModule - let graph = newModuleGraph(config) - if freshDefines: initDefines() + let graph = newModuleGraph(conf) + if freshDefines: initDefines(conf.symbols) - defineSymbol("nimscript") - defineSymbol("nimconfig") + defineSymbol(conf.symbols, "nimscript") + defineSymbol(conf.symbols, "nimconfig") registerPass(semPass) registerPass(evalPass) - searchPaths.add(options.libpath) + conf.searchPaths.add(conf.libpath) var m = graph.makeModule(scriptName) incl(m.flags, sfMainModule) - vm.globalCtx = setupVM(m, cache, scriptName, config) + vm.globalCtx = setupVM(m, cache, scriptName, graph) graph.compileSystemModule(cache) discard graph.processModule(m, llStreamOpen(scriptName, fmRead), nil, cache) # ensure we load 'system.nim' again for the real non-config stuff! - resetSystemArtifacts() + resetSystemArtifacts(graph) vm.globalCtx = nil # do not remove the defined symbols #initDefines() - undefSymbol("nimscript") - undefSymbol("nimconfig") + undefSymbol(conf.symbols, "nimscript") + undefSymbol(conf.symbols, "nimconfig") |