diff options
Diffstat (limited to 'compiler/main.nim')
-rw-r--r-- | compiler/main.nim | 163 |
1 files changed, 82 insertions, 81 deletions
diff --git a/compiler/main.nim b/compiler/main.nim index 9ffe99454..f6d11d960 100644 --- a/compiler/main.nim +++ b/compiler/main.nim @@ -1,7 +1,7 @@ # # # The Nimrod Compiler -# (c) Copyright 2013 Andreas Rumpf +# (c) Copyright 2014 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. @@ -14,16 +14,16 @@ import os, condsyms, rodread, rodwrite, times, wordrecg, sem, semdata, idents, passes, docgen, extccomp, cgen, jsgen, json, nversion, - platform, nimconf, importer, passaux, depends, evals, types, idgen, + platform, nimconf, importer, passaux, depends, vm, vmdef, types, idgen, tables, docgen2, service, parser, modules, ccgutils, sigmatch, ropes, lists, pretty -from magicsys import SystemModule, resetSysTypes +from magicsys import systemModule, resetSysTypes const - has_LLVM_Backend = false + hasLLVM_Backend = false -when has_LLVM_Backend: +when hasLLVM_Backend: import llvmgen proc rodPass = @@ -37,22 +37,22 @@ proc semanticPasses = registerPass verbosePass registerPass semPass -proc CommandGenDepend = +proc commandGenDepend = semanticPasses() - registerPass(genDependPass) + registerPass(gendependPass) registerPass(cleanupPass) compileProject() generateDot(gProjectFull) execExternalProgram("dot -Tpng -o" & changeFileExt(gProjectFull, "png") & ' ' & changeFileExt(gProjectFull, "dot")) -proc CommandCheck = +proc commandCheck = msgs.gErrorMax = high(int) # do not stop after first error semanticPasses() # use an empty backend for semantic checking only rodPass() compileProject() -proc CommandDoc2 = +proc commandDoc2 = msgs.gErrorMax = high(int) # do not stop after first error semanticPasses() registerPass(docgen2Pass) @@ -60,7 +60,7 @@ proc CommandDoc2 = compileProject() finishDoc2Pass(gProjectName) -proc CommandCompileToC = +proc commandCompileToC = semanticPasses() registerPass(cgenPass) rodPass() @@ -73,7 +73,7 @@ proc CommandCompileToC = compileProject() cgenWriteModules() if gCmd != cmdRun: - extccomp.CallCCompiler(changeFileExt(gProjectFull, "")) + extccomp.callCCompiler(changeFileExt(gProjectFull, "")) if isServing: # caas will keep track only of the compilation commands @@ -111,45 +111,45 @@ proc CommandCompileToC = ccgutils.resetCaches() GC_fullCollect() -when has_LLVM_Backend: - proc CommandCompileToLLVM = +when hasLLVM_Backend: + proc commandCompileToLLVM = semanticPasses() registerPass(llvmgen.llvmgenPass()) rodPass() #registerPass(cleanupPass()) compileProject() -proc CommandCompileToJS = +proc commandCompileToJS = #incl(gGlobalOptions, optSafeCode) setTarget(osJS, cpuJS) #initDefines() - DefineSymbol("nimrod") # 'nimrod' is always defined - DefineSymbol("ecmascript") # For backward compatibility - DefineSymbol("js") + defineSymbol("nimrod") # 'nimrod' is always defined + defineSymbol("ecmascript") # For backward compatibility + defineSymbol("js") semanticPasses() - registerPass(jsgenPass) + registerPass(JSgenPass) compileProject() -proc InteractivePasses = +proc interactivePasses = #incl(gGlobalOptions, optSafeCode) #setTarget(osNimrodVM, cpuNimrodVM) initDefines() - DefineSymbol("nimrodvm") - when hasFFI: DefineSymbol("nimffi") + defineSymbol("nimrodvm") + when hasFFI: defineSymbol("nimffi") registerPass(verbosePass) registerPass(semPass) registerPass(evalPass) -proc CommandInteractive = +proc commandInteractive = msgs.gErrorMax = high(int) # do not stop after first error - InteractivePasses() + interactivePasses() compileSystemModule() if commandArgs.len > 0: - discard CompileModule(fileInfoIdx(gProjectFull), {}) + discard compileModule(fileInfoIdx(gProjectFull), {}) else: var m = makeStdinModule() incl(m.flags, sfMainModule) - processModule(m, LLStreamOpenStdIn(), nil) + processModule(m, llStreamOpenStdIn(), nil) const evalPasses = [verbosePass, semPass, evalPass] @@ -157,28 +157,28 @@ proc evalNim(nodes: PNode, module: PSym) = carryPasses(nodes, module, evalPasses) proc commandEval(exp: string) = - if SystemModule == nil: - InteractivePasses() + if systemModule == nil: + interactivePasses() compileSystemModule() var echoExp = "echo \"eval\\t\", " & "repr(" & exp & ")" evalNim(echoExp.parseString, makeStdinModule()) -proc CommandPrettyOld = +proc commandPrettyOld = var projectFile = addFileExt(mainCommandArg(), NimExt) var module = parseFile(projectFile.fileInfoIdx) if module != nil: renderModule(module, getOutFile(mainCommandArg(), "pretty." & NimExt)) -proc CommandPretty = +proc commandPretty = msgs.gErrorMax = high(int) # do not stop after first error semanticPasses() registerPass(prettyPass) compileProject() pretty.overwriteFiles() -proc CommandScan = - var f = addFileExt(mainCommandArg(), nimExt) - var stream = LLStreamOpen(f, fmRead) +proc commandScan = + var f = addFileExt(mainCommandArg(), NimExt) + var stream = llStreamOpen(f, fmRead) if stream != nil: var L: TLexer @@ -187,20 +187,20 @@ proc CommandScan = openLexer(L, f, stream) while true: rawGetTok(L, tok) - PrintTok(tok) + printTok(tok) if tok.tokType == tkEof: break - CloseLexer(L) + closeLexer(L) else: rawMessage(errCannotOpenFile, f) -proc CommandSuggest = +proc commandSuggest = if isServing: # XXX: hacky work-around ahead # Currently, it's possible to issue a idetools command, before # issuing the first compile command. This will leave the compiler # cache in a state where "no recompilation is necessary", but the # cgen pass was never executed at all. - CommandCompileToC() + commandCompileToC() if gDirtyBufferIdx != 0: discard compileModule(gDirtyBufferIdx, {sfDirty}) resetModule(gDirtyBufferIdx) @@ -219,21 +219,21 @@ proc CommandSuggest = proc wantMainModule = if gProjectFull.len == 0: if optMainModule.len == 0: - Fatal(gCmdLineInfo, errCommandExpectsFilename) + fatal(gCmdLineInfo, errCommandExpectsFilename) else: gProjectName = optMainModule gProjectFull = gProjectPath / gProjectName - gProjectMainIdx = addFileExt(gProjectFull, nimExt).fileInfoIdx + gProjectMainIdx = addFileExt(gProjectFull, NimExt).fileInfoIdx proc requireMainModuleOption = if optMainModule.len == 0: - Fatal(gCmdLineInfo, errMainModuleMustBeSpecified) + fatal(gCmdLineInfo, errMainModuleMustBeSpecified) else: gProjectName = optMainModule gProjectFull = gProjectPath / gProjectName - gProjectMainIdx = addFileExt(gProjectFull, nimExt).fileInfoIdx + gProjectMainIdx = addFileExt(gProjectFull, NimExt).fileInfoIdx proc resetMemory = resetCompilationLists() @@ -286,7 +286,7 @@ const SimiluateCaasMemReset = false PrintRopeCacheStats = false -proc MainCommand* = +proc mainCommand* = when SimiluateCaasMemReset: gGlobalOptions.incl(optCaasEnabled) @@ -297,7 +297,7 @@ proc MainCommand* = if gProjectFull.len != 0: # current path is always looked first for modules prependStr(searchPaths, gProjectPath) - setID(100) + setId(100) passes.gIncludeFile = includeModule passes.gImportModule = importModule case command.normalize @@ -305,88 +305,88 @@ proc MainCommand* = # compile means compileToC currently gCmd = cmdCompileToC wantMainModule() - CommandCompileToC() + commandCompileToC() of "cpp", "compiletocpp": extccomp.cExt = ".cpp" gCmd = cmdCompileToCpp if cCompiler == ccGcc: setCC("gpp") wantMainModule() - DefineSymbol("cpp") - CommandCompileToC() + defineSymbol("cpp") + commandCompileToC() of "objc", "compiletooc": extccomp.cExt = ".m" gCmd = cmdCompileToOC wantMainModule() - DefineSymbol("objc") - CommandCompileToC() + defineSymbol("objc") + commandCompileToC() of "run": gCmd = cmdRun wantMainModule() when hasTinyCBackend: extccomp.setCC("tcc") - CommandCompileToC() + commandCompileToC() else: rawMessage(errInvalidCommandX, command) of "js", "compiletojs": gCmd = cmdCompileToJS wantMainModule() - CommandCompileToJS() + commandCompileToJS() of "compiletollvm": gCmd = cmdCompileToLLVM wantMainModule() - when has_LLVM_Backend: + when hasLLVM_Backend: CommandCompileToLLVM() else: rawMessage(errInvalidCommandX, command) of "pretty": gCmd = cmdPretty wantMainModule() - CommandPretty() + commandPretty() of "doc": gCmd = cmdDoc - LoadConfigs(DocConfig) + loadConfigs(DocConfig) wantMainModule() - CommandDoc() + commandDoc() of "doc2": gCmd = cmdDoc - LoadConfigs(DocConfig) + loadConfigs(DocConfig) wantMainModule() - DefineSymbol("nimdoc") - CommandDoc2() + defineSymbol("nimdoc") + commandDoc2() of "rst2html": gCmd = cmdRst2html - LoadConfigs(DocConfig) + loadConfigs(DocConfig) wantMainModule() - CommandRst2Html() + commandRst2Html() of "rst2tex": gCmd = cmdRst2tex - LoadConfigs(DocTexConfig) + loadConfigs(DocTexConfig) wantMainModule() - CommandRst2TeX() + commandRst2TeX() of "jsondoc": gCmd = cmdDoc - LoadConfigs(DocConfig) + loadConfigs(DocConfig) wantMainModule() - DefineSymbol("nimdoc") - CommandJSON() + defineSymbol("nimdoc") + commandJSON() of "buildindex": gCmd = cmdDoc - LoadConfigs(DocConfig) - CommandBuildIndex() + loadConfigs(DocConfig) + commandBuildIndex() of "gendepend": gCmd = cmdGenDepend wantMainModule() - CommandGenDepend() + commandGenDepend() of "dump": - gcmd = cmdDump - if getconfigvar("dump.format") == "json": + gCmd = cmdDump + if getConfigVar("dump.format") == "json": requireMainModuleOption() var definedSymbols = newJArray() for s in definedSymbolNames(): definedSymbols.elems.add(%s) var libpaths = newJArray() - for dir in itersearchpath(searchpaths): libpaths.elems.add(%dir) + for dir in iterSearchPath(searchPaths): libpaths.elems.add(%dir) var dumpdata = % [ (key: "version", val: %VersionAsString), @@ -395,17 +395,17 @@ proc MainCommand* = (key: "lib_paths", val: libpaths) ] - outWriteLn($dumpdata) + outWriteln($dumpdata) else: - outWriteLn("-- list of currently defined symbols --") - for s in definedSymbolNames(): outWriteLn(s) - outWriteLn("-- end of list --") + outWriteln("-- list of currently defined symbols --") + for s in definedSymbolNames(): outWriteln(s) + outWriteln("-- end of list --") - for it in iterSearchPath(searchpaths): msgWriteLn(it) + for it in iterSearchPath(searchPaths): msgWriteln(it) of "check": gCmd = cmdCheck wantMainModule() - CommandCheck() + commandCheck() of "parse": gCmd = cmdParse wantMainModule() @@ -413,11 +413,11 @@ proc MainCommand* = of "scan": gCmd = cmdScan wantMainModule() - CommandScan() - MsgWriteln("Beware: Indentation tokens depend on the parser\'s state!") + commandScan() + msgWriteln("Beware: Indentation tokens depend on the parser\'s state!") of "i": gCmd = cmdInteractive - CommandInteractive() + commandInteractive() of "e": # XXX: temporary command for easier testing commandEval(mainCommandArg()) @@ -429,12 +429,12 @@ proc MainCommand* = commandEval(gEvalExpr) else: wantMainModule() - CommandSuggest() + commandSuggest() of "serve": isServing = true gGlobalOptions.incl(optCaasEnabled) msgs.gErrorMax = high(int) # do not stop after first error - serve(MainCommand) + serve(mainCommand) else: rawMessage(errInvalidCommandX, command) @@ -450,7 +450,8 @@ proc MainCommand* = echo " tries : ", gCacheTries echo " misses: ", gCacheMisses echo " int tries: ", gCacheIntTries - echo " efficiency: ", formatFloat(1-(gCacheMisses.float/gCacheTries.float), ffDecimal, 3) + echo " efficiency: ", formatFloat(1-(gCacheMisses.float/gCacheTries.float), + ffDecimal, 3) when SimiluateCaasMemReset: resetMemory() |