diff options
author | Araq <rumpf_a@web.de> | 2014-09-06 00:50:53 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-09-06 00:50:53 +0200 |
commit | 7f7b13a45f73c6d9dcca3ce8388833189d77426c (patch) | |
tree | 79780167960b4aaae49e733ecb94afc39b5e4828 | |
parent | 5fb12144b31a97fd208fb286de557f913b97e108 (diff) | |
download | Nim-7f7b13a45f73c6d9dcca3ce8388833189d77426c.tar.gz |
nimfix handles helloworld
-rw-r--r-- | compiler/astalgo.nim | 8 | ||||
-rw-r--r-- | compiler/commands.nim | 3 | ||||
-rw-r--r-- | compiler/main.nim | 37 | ||||
-rw-r--r-- | compiler/modules.nim | 11 | ||||
-rw-r--r-- | compiler/nim.nimrod.cfg | 2 | ||||
-rw-r--r-- | compiler/nimfix.nim | 10 | ||||
-rw-r--r-- | compiler/options.nim | 1 | ||||
-rw-r--r-- | doc/advopt.txt | 1 | ||||
-rw-r--r-- | todo.txt | 3 |
9 files changed, 29 insertions, 47 deletions
diff --git a/compiler/astalgo.nim b/compiler/astalgo.nim index 8918888a3..110b0c26e 100644 --- a/compiler/astalgo.nim +++ b/compiler/astalgo.nim @@ -626,6 +626,12 @@ proc strTableAdd(t: var TStrTable, n: PSym) = strTableRawInsert(t.data, n) inc(t.counter) +proc reallySameIdent(a, b: string): bool {.inline.} = + when defined(nimfix): + result = a[0] == b[0] + else: + result = true + proc strTableIncl*(t: var TStrTable, n: PSym): bool {.discardable.} = # returns true if n is already in the string table: # It is essential that `n` is written nevertheless! @@ -635,7 +641,7 @@ proc strTableIncl*(t: var TStrTable, n: PSym): bool {.discardable.} = while true: var it = t.data[h] if it == nil: break - if it.name.id == n.name.id: + if it.name.id == n.name.id and reallySameIdent(it.name.s, n.name.s): t.data[h] = n # overwrite it with newer definition! return true # found it h = nextTry(h, high(t.data)) diff --git a/compiler/commands.nim b/compiler/commands.nim index 2a2e0c4ee..596cdafba 100644 --- a/compiler/commands.nim +++ b/compiler/commands.nim @@ -308,8 +308,7 @@ proc processSwitch(switch, arg: string, pass: TCmdLinePass, info: TLineInfo) = expectArg(switch, arg, pass, info) options.docSeeSrcUrl = arg of "mainmodule", "m": - expectArg(switch, arg, pass, info) - optMainModule = arg + discard "allow for backwards compatibility, but don't do anything" of "define", "d": expectArg(switch, arg, pass, info) defineSymbol(arg) diff --git a/compiler/main.nim b/compiler/main.nim index 0bb057df5..47da96a03 100644 --- a/compiler/main.nim +++ b/compiler/main.nim @@ -211,25 +211,6 @@ proc commandSuggest = else: gProjectMainIdx compileProject(projFile) -proc wantMainModule = - if gProjectFull.len == 0: - if optMainModule.len == 0: - fatal(gCmdLineInfo, errCommandExpectsFilename) - else: - gProjectName = optMainModule - gProjectFull = gProjectPath / gProjectName - - gProjectMainIdx = addFileExt(gProjectFull, NimExt).fileInfoIdx - -proc requireMainModuleOption = - if optMainModule.len == 0: - fatal(gCmdLineInfo, errMainModuleMustBeSpecified) - else: - gProjectName = optMainModule - gProjectFull = gProjectPath / gProjectName - - gProjectMainIdx = addFileExt(gProjectFull, NimExt).fileInfoIdx - proc resetMemory = resetCompilationLists() ccgutils.resetCaches() @@ -293,30 +274,24 @@ proc mainCommand* = # current path is always looked first for modules prependStr(searchPaths, gProjectPath) setId(100) - passes.gIncludeFile = includeModule - passes.gImportModule = importModule case command.normalize of "c", "cc", "compile", "compiletoc": # compile means compileToC currently gCmd = cmdCompileToC - wantMainModule() commandCompileToC() of "cpp", "compiletocpp": extccomp.cExt = ".cpp" gCmd = cmdCompileToCpp if cCompiler == ccGcc: setCC("gcc") - wantMainModule() defineSymbol("cpp") commandCompileToC() of "objc", "compiletooc": extccomp.cExt = ".m" gCmd = cmdCompileToOC - wantMainModule() defineSymbol("objc") commandCompileToC() of "run": gCmd = cmdRun - wantMainModule() when hasTinyCBackend: extccomp.setCC("tcc") commandCompileToC() @@ -324,39 +299,32 @@ proc mainCommand* = rawMessage(errInvalidCommandX, command) of "js", "compiletojs": gCmd = cmdCompileToJS - wantMainModule() commandCompileToJS() of "compiletollvm": gCmd = cmdCompileToLLVM - wantMainModule() when hasLLVM_Backend: CommandCompileToLLVM() else: rawMessage(errInvalidCommandX, command) of "pretty": gCmd = cmdPretty - wantMainModule() commandPretty() of "doc": gCmd = cmdDoc loadConfigs(DocConfig) - wantMainModule() commandDoc() of "doc2": gCmd = cmdDoc loadConfigs(DocConfig) - wantMainModule() defineSymbol("nimdoc") commandDoc2() of "rst2html": gCmd = cmdRst2html loadConfigs(DocConfig) - wantMainModule() commandRst2Html() of "rst2tex": gCmd = cmdRst2tex loadConfigs(DocTexConfig) - wantMainModule() commandRst2TeX() of "jsondoc": gCmd = cmdDoc @@ -370,12 +338,11 @@ proc mainCommand* = commandBuildIndex() of "gendepend": gCmd = cmdGenDepend - wantMainModule() commandGenDepend() of "dump": gCmd = cmdDump if getConfigVar("dump.format") == "json": - requireMainModuleOption() + wantMainModule() var definedSymbols = newJArray() for s in definedSymbolNames(): definedSymbols.elems.add(%s) @@ -399,7 +366,6 @@ proc mainCommand* = for it in iterSearchPath(searchPaths): msgWriteln(it) of "check": gCmd = cmdCheck - wantMainModule() commandCheck() of "parse": gCmd = cmdParse @@ -423,7 +389,6 @@ proc mainCommand* = if gEvalExpr != "": commandEval(gEvalExpr) else: - wantMainModule() commandSuggest() of "serve": isServing = true diff --git a/compiler/modules.nim b/compiler/modules.nim index 8939afd5a..dd8ccedb1 100644 --- a/compiler/modules.nim +++ b/compiler/modules.nim @@ -185,8 +185,17 @@ proc compileSystemModule* = systemFileIdx = fileInfoIdx(options.libpath/"system.nim") discard compileModule(systemFileIdx, {sfSystemModule}) -proc compileProject*(projectFile = gProjectMainIdx) = +proc wantMainModule* = + if gProjectFull.len == 0: + fatal(gCmdLineInfo, errCommandExpectsFilename) + gProjectMainIdx = addFileExt(gProjectFull, NimExt).fileInfoIdx + +proc compileProject*(projectFileIdx = -1'i32) = + wantMainModule() + passes.gIncludeFile = includeModule + passes.gImportModule = importModule let systemFileIdx = fileInfoIdx(options.libpath / "system.nim") + let projectFile = if projectFileIdx < 0: gProjectMainIdx else: projectFileIdx if projectFile == systemFileIdx: discard compileModule(projectFile, {sfMainModule, sfSystemModule}) else: diff --git a/compiler/nim.nimrod.cfg b/compiler/nim.nimrod.cfg index 5a892bad0..ba7697c4c 100644 --- a/compiler/nim.nimrod.cfg +++ b/compiler/nim.nimrod.cfg @@ -1,7 +1,5 @@ # Special configuration file for the Nim project -mainModule:"nimrod.nim" - # gc:markAndSweep hint[XDeclaredButNotUsed]:off diff --git a/compiler/nimfix.nim b/compiler/nimfix.nim index 3fbf27e54..60ebb48e5 100644 --- a/compiler/nimfix.nim +++ b/compiler/nimfix.nim @@ -11,7 +11,7 @@ import strutils, os, parseopt import options, commands, modules, sem, passes, passaux, pretty, msgs, nimconf, - extccomp, condsyms + extccomp, condsyms, lists const Usage = """ Nimfix - Tool to patch Nim code @@ -36,6 +36,11 @@ proc mainCommand = registerPass semPass registerPass prettyPass gCmd = cmdPretty + appendStr(searchPaths, options.libpath) + if gProjectFull.len != 0: + # current path is always looked first for modules + prependStr(searchPaths, gProjectPath) + compileProject() pretty.overwriteFiles() @@ -68,7 +73,8 @@ proc processCmdLine*(pass: TCmdLinePass, cmd: string) = else: processSwitch(pass, p) of cmdArgument: - if processArgument(pass, p, argsCount): break + options.gProjectName = unixToNativePath(p.key) + # if processArgument(pass, p, argsCount): break proc handleCmdLine() = if paramCount() == 0: diff --git a/compiler/options.nim b/compiler/options.nim index 11c8241ef..cb2173554 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -152,7 +152,6 @@ var gProjectPath* = "" # holds a path like /home/alice/projects/nimrod/compiler/ gProjectFull* = "" # projectPath/projectName gProjectMainIdx*: int32 # the canonical path id of the main module - optMainModule* = "" # the main module that should be used for idetools commands nimcacheDir* = "" command* = "" # the main command (e.g. cc, check, scan, etc) commandArgs*: seq[string] = @[] # any arguments after the main command diff --git a/doc/advopt.txt b/doc/advopt.txt index 370639a60..0febf778f 100644 --- a/doc/advopt.txt +++ b/doc/advopt.txt @@ -28,7 +28,6 @@ Advanced commands: --server.address:HOST binds to that address, by default "" Advanced options: - -m, --mainmodule:FILE set the project main module -o, --out:FILE set the output filename --stdout output to stdout --listFullPaths list full paths in messages diff --git a/todo.txt b/todo.txt index acdec7547..f29e97a21 100644 --- a/todo.txt +++ b/todo.txt @@ -1,7 +1,6 @@ version 0.10 ============ -- Write new nimfix tool - Test nimfix on various babel packages - Pegs do not work at compile-time @@ -10,6 +9,8 @@ version 0.9.6 ============= - fix tflowvar codegen test +- allow simple read accesses to global variables --> difficult to ensure that + no data races happen - split idetools into separate tool - split docgen into separate tool - .benign pragma |