nimfix handles helloworld

This commit is contained in:
Araq 2014-09-06 00:50:53 +02:00
commit 7f7b13a45f
9 changed files with 29 additions and 47 deletions

View file

@ -626,6 +626,12 @@ proc strTableAdd(t: var TStrTable, n: PSym) =
strTableRawInsert(t.data, n) strTableRawInsert(t.data, n)
inc(t.counter) 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.} = proc strTableIncl*(t: var TStrTable, n: PSym): bool {.discardable.} =
# returns true if n is already in the string table: # returns true if n is already in the string table:
# It is essential that `n` is written nevertheless! # It is essential that `n` is written nevertheless!
@ -635,7 +641,7 @@ proc strTableIncl*(t: var TStrTable, n: PSym): bool {.discardable.} =
while true: while true:
var it = t.data[h] var it = t.data[h]
if it == nil: break 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! t.data[h] = n # overwrite it with newer definition!
return true # found it return true # found it
h = nextTry(h, high(t.data)) h = nextTry(h, high(t.data))

View file

@ -308,8 +308,7 @@ proc processSwitch(switch, arg: string, pass: TCmdLinePass, info: TLineInfo) =
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)
options.docSeeSrcUrl = arg options.docSeeSrcUrl = arg
of "mainmodule", "m": of "mainmodule", "m":
expectArg(switch, arg, pass, info) discard "allow for backwards compatibility, but don't do anything"
optMainModule = arg
of "define", "d": of "define", "d":
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)
defineSymbol(arg) defineSymbol(arg)

View file

@ -211,25 +211,6 @@ proc commandSuggest =
else: gProjectMainIdx else: gProjectMainIdx
compileProject(projFile) 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 = proc resetMemory =
resetCompilationLists() resetCompilationLists()
ccgutils.resetCaches() ccgutils.resetCaches()
@ -293,30 +274,24 @@ proc mainCommand* =
# current path is always looked first for modules # current path is always looked first for modules
prependStr(searchPaths, gProjectPath) prependStr(searchPaths, gProjectPath)
setId(100) setId(100)
passes.gIncludeFile = includeModule
passes.gImportModule = importModule
case command.normalize case command.normalize
of "c", "cc", "compile", "compiletoc": of "c", "cc", "compile", "compiletoc":
# compile means compileToC currently # compile means compileToC currently
gCmd = cmdCompileToC gCmd = cmdCompileToC
wantMainModule()
commandCompileToC() commandCompileToC()
of "cpp", "compiletocpp": of "cpp", "compiletocpp":
extccomp.cExt = ".cpp" extccomp.cExt = ".cpp"
gCmd = cmdCompileToCpp gCmd = cmdCompileToCpp
if cCompiler == ccGcc: setCC("gcc") if cCompiler == ccGcc: setCC("gcc")
wantMainModule()
defineSymbol("cpp") defineSymbol("cpp")
commandCompileToC() commandCompileToC()
of "objc", "compiletooc": of "objc", "compiletooc":
extccomp.cExt = ".m" extccomp.cExt = ".m"
gCmd = cmdCompileToOC gCmd = cmdCompileToOC
wantMainModule()
defineSymbol("objc") defineSymbol("objc")
commandCompileToC() commandCompileToC()
of "run": of "run":
gCmd = cmdRun gCmd = cmdRun
wantMainModule()
when hasTinyCBackend: when hasTinyCBackend:
extccomp.setCC("tcc") extccomp.setCC("tcc")
commandCompileToC() commandCompileToC()
@ -324,39 +299,32 @@ proc mainCommand* =
rawMessage(errInvalidCommandX, command) rawMessage(errInvalidCommandX, command)
of "js", "compiletojs": of "js", "compiletojs":
gCmd = cmdCompileToJS gCmd = cmdCompileToJS
wantMainModule()
commandCompileToJS() commandCompileToJS()
of "compiletollvm": of "compiletollvm":
gCmd = cmdCompileToLLVM gCmd = cmdCompileToLLVM
wantMainModule()
when hasLLVM_Backend: when hasLLVM_Backend:
CommandCompileToLLVM() CommandCompileToLLVM()
else: else:
rawMessage(errInvalidCommandX, command) rawMessage(errInvalidCommandX, command)
of "pretty": of "pretty":
gCmd = cmdPretty gCmd = cmdPretty
wantMainModule()
commandPretty() commandPretty()
of "doc": of "doc":
gCmd = cmdDoc gCmd = cmdDoc
loadConfigs(DocConfig) loadConfigs(DocConfig)
wantMainModule()
commandDoc() commandDoc()
of "doc2": of "doc2":
gCmd = cmdDoc gCmd = cmdDoc
loadConfigs(DocConfig) loadConfigs(DocConfig)
wantMainModule()
defineSymbol("nimdoc") defineSymbol("nimdoc")
commandDoc2() commandDoc2()
of "rst2html": of "rst2html":
gCmd = cmdRst2html gCmd = cmdRst2html
loadConfigs(DocConfig) loadConfigs(DocConfig)
wantMainModule()
commandRst2Html() commandRst2Html()
of "rst2tex": of "rst2tex":
gCmd = cmdRst2tex gCmd = cmdRst2tex
loadConfigs(DocTexConfig) loadConfigs(DocTexConfig)
wantMainModule()
commandRst2TeX() commandRst2TeX()
of "jsondoc": of "jsondoc":
gCmd = cmdDoc gCmd = cmdDoc
@ -370,12 +338,11 @@ proc mainCommand* =
commandBuildIndex() commandBuildIndex()
of "gendepend": of "gendepend":
gCmd = cmdGenDepend gCmd = cmdGenDepend
wantMainModule()
commandGenDepend() commandGenDepend()
of "dump": of "dump":
gCmd = cmdDump gCmd = cmdDump
if getConfigVar("dump.format") == "json": if getConfigVar("dump.format") == "json":
requireMainModuleOption() wantMainModule()
var definedSymbols = newJArray() var definedSymbols = newJArray()
for s in definedSymbolNames(): definedSymbols.elems.add(%s) for s in definedSymbolNames(): definedSymbols.elems.add(%s)
@ -399,7 +366,6 @@ proc mainCommand* =
for it in iterSearchPath(searchPaths): msgWriteln(it) for it in iterSearchPath(searchPaths): msgWriteln(it)
of "check": of "check":
gCmd = cmdCheck gCmd = cmdCheck
wantMainModule()
commandCheck() commandCheck()
of "parse": of "parse":
gCmd = cmdParse gCmd = cmdParse
@ -423,7 +389,6 @@ proc mainCommand* =
if gEvalExpr != "": if gEvalExpr != "":
commandEval(gEvalExpr) commandEval(gEvalExpr)
else: else:
wantMainModule()
commandSuggest() commandSuggest()
of "serve": of "serve":
isServing = true isServing = true

View file

@ -185,8 +185,17 @@ proc compileSystemModule* =
systemFileIdx = fileInfoIdx(options.libpath/"system.nim") systemFileIdx = fileInfoIdx(options.libpath/"system.nim")
discard compileModule(systemFileIdx, {sfSystemModule}) 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 systemFileIdx = fileInfoIdx(options.libpath / "system.nim")
let projectFile = if projectFileIdx < 0: gProjectMainIdx else: projectFileIdx
if projectFile == systemFileIdx: if projectFile == systemFileIdx:
discard compileModule(projectFile, {sfMainModule, sfSystemModule}) discard compileModule(projectFile, {sfMainModule, sfSystemModule})
else: else:

View file

@ -1,7 +1,5 @@
# Special configuration file for the Nim project # Special configuration file for the Nim project
mainModule:"nimrod.nim"
# gc:markAndSweep # gc:markAndSweep
hint[XDeclaredButNotUsed]:off hint[XDeclaredButNotUsed]:off

View file

@ -11,7 +11,7 @@
import strutils, os, parseopt import strutils, os, parseopt
import options, commands, modules, sem, passes, passaux, pretty, msgs, nimconf, import options, commands, modules, sem, passes, passaux, pretty, msgs, nimconf,
extccomp, condsyms extccomp, condsyms, lists
const Usage = """ const Usage = """
Nimfix - Tool to patch Nim code Nimfix - Tool to patch Nim code
@ -36,6 +36,11 @@ proc mainCommand =
registerPass semPass registerPass semPass
registerPass prettyPass registerPass prettyPass
gCmd = cmdPretty gCmd = cmdPretty
appendStr(searchPaths, options.libpath)
if gProjectFull.len != 0:
# current path is always looked first for modules
prependStr(searchPaths, gProjectPath)
compileProject() compileProject()
pretty.overwriteFiles() pretty.overwriteFiles()
@ -68,7 +73,8 @@ proc processCmdLine*(pass: TCmdLinePass, cmd: string) =
else: else:
processSwitch(pass, p) processSwitch(pass, p)
of cmdArgument: of cmdArgument:
if processArgument(pass, p, argsCount): break options.gProjectName = unixToNativePath(p.key)
# if processArgument(pass, p, argsCount): break
proc handleCmdLine() = proc handleCmdLine() =
if paramCount() == 0: if paramCount() == 0:

View file

@ -152,7 +152,6 @@ var
gProjectPath* = "" # holds a path like /home/alice/projects/nimrod/compiler/ gProjectPath* = "" # holds a path like /home/alice/projects/nimrod/compiler/
gProjectFull* = "" # projectPath/projectName gProjectFull* = "" # projectPath/projectName
gProjectMainIdx*: int32 # the canonical path id of the main module gProjectMainIdx*: int32 # the canonical path id of the main module
optMainModule* = "" # the main module that should be used for idetools commands
nimcacheDir* = "" nimcacheDir* = ""
command* = "" # the main command (e.g. cc, check, scan, etc) command* = "" # the main command (e.g. cc, check, scan, etc)
commandArgs*: seq[string] = @[] # any arguments after the main command commandArgs*: seq[string] = @[] # any arguments after the main command

View file

@ -28,7 +28,6 @@ Advanced commands:
--server.address:HOST binds to that address, by default "" --server.address:HOST binds to that address, by default ""
Advanced options: Advanced options:
-m, --mainmodule:FILE set the project main module
-o, --out:FILE set the output filename -o, --out:FILE set the output filename
--stdout output to stdout --stdout output to stdout
--listFullPaths list full paths in messages --listFullPaths list full paths in messages

View file

@ -1,7 +1,6 @@
version 0.10 version 0.10
============ ============
- Write new nimfix tool
- Test nimfix on various babel packages - Test nimfix on various babel packages
- Pegs do not work at compile-time - Pegs do not work at compile-time
@ -10,6 +9,8 @@ version 0.9.6
============= =============
- fix tflowvar codegen test - 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 idetools into separate tool
- split docgen into separate tool - split docgen into separate tool
- .benign pragma - .benign pragma