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