nimfix handles helloworld

This commit is contained in:
Araq
2014-09-06 00:50:53 +02:00
parent 5fb12144b3
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)
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))

View File

@@ -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)

View File

@@ -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

View File

@@ -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:

View File

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

View File

@@ -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:

View File

@@ -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

View File

@@ -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

View File

@@ -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