implemented --nimcache config option; big clean up of magic words

This commit is contained in:
Araq
2011-08-19 01:46:24 +02:00
parent 257b16ca34
commit c7b130b4e2
8 changed files with 170 additions and 187 deletions

View File

@@ -229,57 +229,59 @@ proc processCompile(filename: string) =
extccomp.addFileToLink(completeCFilePath(trunc, false)) extccomp.addFileToLink(completeCFilePath(trunc, false))
proc testCompileOptionArg*(switch, arg: string, info: TLineInfo): bool = proc testCompileOptionArg*(switch, arg: string, info: TLineInfo): bool =
case whichKeyword(switch) case switch.normalize
of wGC: of "gc":
case whichKeyword(arg) case arg.normalize
of wBoehm: result = contains(gGlobalOptions, optBoehmGC) of "boehm": result = contains(gGlobalOptions, optBoehmGC)
of wRefc: result = contains(gGlobalOptions, optRefcGC) of "refc": result = contains(gGlobalOptions, optRefcGC)
of wNone: result = gGlobalOptions * {optBoehmGC, optRefcGC} == {} of "none": result = gGlobalOptions * {optBoehmGC, optRefcGC} == {}
else: LocalError(info, errNoneBoehmRefcExpectedButXFound, arg) else: LocalError(info, errNoneBoehmRefcExpectedButXFound, arg)
of wOpt: of "opt":
case whichKeyword(arg) case arg.normalize
of wSpeed: result = contains(gOptions, optOptimizeSpeed) of "speed": result = contains(gOptions, optOptimizeSpeed)
of wSize: result = contains(gOptions, optOptimizeSize) of "size": result = contains(gOptions, optOptimizeSize)
of wNone: result = gOptions * {optOptimizeSpeed, optOptimizeSize} == {} of "none": result = gOptions * {optOptimizeSpeed, optOptimizeSize} == {}
else: LocalError(info, errNoneSpeedOrSizeExpectedButXFound, arg) else: LocalError(info, errNoneSpeedOrSizeExpectedButXFound, arg)
else: InvalidCmdLineOption(passCmd1, switch, info) else: InvalidCmdLineOption(passCmd1, switch, info)
proc testCompileOption*(switch: string, info: TLineInfo): bool = proc testCompileOption*(switch: string, info: TLineInfo): bool =
case whichKeyword(switch) case switch.normalize
of wDebuginfo: result = contains(gGlobalOptions, optCDebug) of "debuginfo": result = contains(gGlobalOptions, optCDebug)
of wCompileOnly, wC: result = contains(gGlobalOptions, optCompileOnly) of "compileonly", "c": result = contains(gGlobalOptions, optCompileOnly)
of wNoLinking: result = contains(gGlobalOptions, optNoLinking) of "nolinking": result = contains(gGlobalOptions, optNoLinking)
of wNoMain: result = contains(gGlobalOptions, optNoMain) of "nomain": result = contains(gGlobalOptions, optNoMain)
of wForceBuild, wF: result = contains(gGlobalOptions, optForceFullMake) of "forcebuild", "f": result = contains(gGlobalOptions, optForceFullMake)
of wWarnings, wW: result = contains(gOptions, optWarns) of "warnings", "w": result = contains(gOptions, optWarns)
of wHints: result = contains(gOptions, optHints) of "hints": result = contains(gOptions, optHints)
of wThreadAnalysis: result = contains(gGlobalOptions, optThreadAnalysis) of "threadanalysis": result = contains(gGlobalOptions, optThreadAnalysis)
of wStackTrace: result = contains(gOptions, optStackTrace) of "stacktrace": result = contains(gOptions, optStackTrace)
of wLineTrace: result = contains(gOptions, optLineTrace) of "linetrace": result = contains(gOptions, optLineTrace)
of wDebugger: result = contains(gOptions, optEndb) of "debugger": result = contains(gOptions, optEndb)
of wProfiler: result = contains(gOptions, optProfiler) of "profiler": result = contains(gOptions, optProfiler)
of wChecks, wX: result = gOptions * checksOptions == checksOptions of "checks", "x": result = gOptions * checksOptions == checksOptions
of wFloatChecks: of "floatchecks":
result = gOptions * {optNanCheck, optInfCheck} == {optNanCheck, optInfCheck} result = gOptions * {optNanCheck, optInfCheck} == {optNanCheck, optInfCheck}
of wInfChecks: result = contains(gOptions, optInfCheck) of "infchecks": result = contains(gOptions, optInfCheck)
of wNanChecks: result = contains(gOptions, optNanCheck) of "nanchecks": result = contains(gOptions, optNanCheck)
of wObjChecks: result = contains(gOptions, optObjCheck) of "objchecks": result = contains(gOptions, optObjCheck)
of wFieldChecks: result = contains(gOptions, optFieldCheck) of "fieldchecks": result = contains(gOptions, optFieldCheck)
of wRangeChecks: result = contains(gOptions, optRangeCheck) of "rangechecks": result = contains(gOptions, optRangeCheck)
of wBoundChecks: result = contains(gOptions, optBoundsCheck) of "boundchecks": result = contains(gOptions, optBoundsCheck)
of wOverflowChecks: result = contains(gOptions, optOverflowCheck) of "overflowchecks": result = contains(gOptions, optOverflowCheck)
of wLineDir: result = contains(gOptions, optLineDir) of "linedir": result = contains(gOptions, optLineDir)
of wAssertions, wA: result = contains(gOptions, optAssert) of "assertions", "a": result = contains(gOptions, optAssert)
of wDeadCodeElim: result = contains(gGlobalOptions, optDeadCodeElim) of "deadcodeelim": result = contains(gGlobalOptions, optDeadCodeElim)
of wRun, wR: result = contains(gGlobalOptions, optRun) of "run", "r": result = contains(gGlobalOptions, optRun)
of wSymbolFiles: result = contains(gGlobalOptions, optSymbolFiles) of "symbolfiles": result = contains(gGlobalOptions, optSymbolFiles)
of wGenScript: result = contains(gGlobalOptions, optGenScript) of "genscript": result = contains(gGlobalOptions, optGenScript)
of wThreads: result = contains(gGlobalOptions, optThreads) of "threads": result = contains(gGlobalOptions, optThreads)
else: InvalidCmdLineOption(passCmd1, switch, info) else: InvalidCmdLineOption(passCmd1, switch, info)
proc processPath(path: string): string = proc processPath(path: string): string =
result = UnixToNativePath(path % ["nimrod", getPrefixDir(), "lib", libpath, result = UnixToNativePath(path % ["nimrod", getPrefixDir(), "lib", libpath,
"home", removeTrailingDirSep(os.getHomeDir())]) "home", removeTrailingDirSep(os.getHomeDir()),
"projectname", options.projectName,
"projectpath", options.projectPath])
proc addPath(path: string, info: TLineInfo) = proc addPath(path: string, info: TLineInfo) =
if not contains(options.searchPaths, path): if not contains(options.searchPaths, path):
@@ -310,134 +312,137 @@ proc processSwitch(switch, arg: string, pass: TCmdlinePass, info: TLineInfo) =
theOS: TSystemOS theOS: TSystemOS
cpu: TSystemCPU cpu: TSystemCPU
key, val: string key, val: string
case whichKeyword(switch) case switch.normalize
of wPath, wP: of "path", "p":
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)
addPath(processPath(arg), info) addPath(processPath(arg), info)
of wRecursivePath: of "recursivepath":
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)
var path = processPath(arg) var path = processPath(arg)
addPathRec(path, info) addPathRec(path, info)
addPath(path, info) addPath(path, info)
of wOut, wO: of "nimcache":
expectArg(switch, arg, pass, info)
options.nimcacheDir = processPath(arg)
of "out", "o":
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)
options.outFile = arg options.outFile = arg
of wDefine, wD: of "define", "d":
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)
DefineSymbol(arg) DefineSymbol(arg)
of wUndef, wU: of "undef", "u":
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)
UndefSymbol(arg) UndefSymbol(arg)
of wCompile: of "compile":
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)
if pass in {passCmd2, passPP}: processCompile(arg) if pass in {passCmd2, passPP}: processCompile(arg)
of wLink: of "link":
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)
if pass in {passCmd2, passPP}: addFileToLink(arg) if pass in {passCmd2, passPP}: addFileToLink(arg)
of wDebuginfo: of "debuginfo":
expectNoArg(switch, arg, pass, info) expectNoArg(switch, arg, pass, info)
incl(gGlobalOptions, optCDebug) incl(gGlobalOptions, optCDebug)
of wCompileOnly, wC: of "compileonly", "c":
expectNoArg(switch, arg, pass, info) expectNoArg(switch, arg, pass, info)
incl(gGlobalOptions, optCompileOnly) incl(gGlobalOptions, optCompileOnly)
of wNoLinking: of "nolinking":
expectNoArg(switch, arg, pass, info) expectNoArg(switch, arg, pass, info)
incl(gGlobalOptions, optNoLinking) incl(gGlobalOptions, optNoLinking)
of wNoMain: of "nomain":
expectNoArg(switch, arg, pass, info) expectNoArg(switch, arg, pass, info)
incl(gGlobalOptions, optNoMain) incl(gGlobalOptions, optNoMain)
of wForceBuild, wF: of "forcebuild", "f":
expectNoArg(switch, arg, pass, info) expectNoArg(switch, arg, pass, info)
incl(gGlobalOptions, optForceFullMake) incl(gGlobalOptions, optForceFullMake)
of wGC: of "gc":
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)
case whichKeyword(arg) case arg.normalize
of wBoehm: of "boehm":
incl(gGlobalOptions, optBoehmGC) incl(gGlobalOptions, optBoehmGC)
excl(gGlobalOptions, optRefcGC) excl(gGlobalOptions, optRefcGC)
DefineSymbol("boehmgc") DefineSymbol("boehmgc")
of wRefc: of "refc":
excl(gGlobalOptions, optBoehmGC) excl(gGlobalOptions, optBoehmGC)
incl(gGlobalOptions, optRefcGC) incl(gGlobalOptions, optRefcGC)
of wNone: of "none":
excl(gGlobalOptions, optRefcGC) excl(gGlobalOptions, optRefcGC)
excl(gGlobalOptions, optBoehmGC) excl(gGlobalOptions, optBoehmGC)
defineSymbol("nogc") defineSymbol("nogc")
else: LocalError(info, errNoneBoehmRefcExpectedButXFound, arg) else: LocalError(info, errNoneBoehmRefcExpectedButXFound, arg)
of wWarnings, wW: ProcessOnOffSwitch({optWarns}, arg, pass, info) of "warnings", "w": ProcessOnOffSwitch({optWarns}, arg, pass, info)
of wWarning: ProcessSpecificNote(arg, wWarning, pass, info) of "warning": ProcessSpecificNote(arg, wWarning, pass, info)
of wHint: ProcessSpecificNote(arg, wHint, pass, info) of "hint": ProcessSpecificNote(arg, wHint, pass, info)
of wHints: ProcessOnOffSwitch({optHints}, arg, pass, info) of "hints": ProcessOnOffSwitch({optHints}, arg, pass, info)
of wThreadAnalysis: ProcessOnOffSwitchG({optThreadAnalysis}, arg, pass, info) of "threadanalysis": ProcessOnOffSwitchG({optThreadAnalysis}, arg, pass, info)
of wStackTrace: ProcessOnOffSwitch({optStackTrace}, arg, pass, info) of "stacktrace": ProcessOnOffSwitch({optStackTrace}, arg, pass, info)
of wLineTrace: ProcessOnOffSwitch({optLineTrace}, arg, pass, info) of "linetrace": ProcessOnOffSwitch({optLineTrace}, arg, pass, info)
of wDebugger: of "debugger":
ProcessOnOffSwitch({optEndb}, arg, pass, info) ProcessOnOffSwitch({optEndb}, arg, pass, info)
if optEndb in gOptions: DefineSymbol("endb") if optEndb in gOptions: DefineSymbol("endb")
else: UndefSymbol("endb") else: UndefSymbol("endb")
of wProfiler: of "profiler":
ProcessOnOffSwitch({optProfiler}, arg, pass, info) ProcessOnOffSwitch({optProfiler}, arg, pass, info)
if optProfiler in gOptions: DefineSymbol("profiler") if optProfiler in gOptions: DefineSymbol("profiler")
else: UndefSymbol("profiler") else: UndefSymbol("profiler")
of wChecks, wX: ProcessOnOffSwitch(checksOptions, arg, pass, info) of "checks", "x": ProcessOnOffSwitch(checksOptions, arg, pass, info)
of wFloatChecks: of "floatchecks":
ProcessOnOffSwitch({optNanCheck, optInfCheck}, arg, pass, info) ProcessOnOffSwitch({optNanCheck, optInfCheck}, arg, pass, info)
of wInfChecks: ProcessOnOffSwitch({optInfCheck}, arg, pass, info) of "infchecks": ProcessOnOffSwitch({optInfCheck}, arg, pass, info)
of wNanChecks: ProcessOnOffSwitch({optNanCheck}, arg, pass, info) of "nanchecks": ProcessOnOffSwitch({optNanCheck}, arg, pass, info)
of wObjChecks: ProcessOnOffSwitch({optObjCheck}, arg, pass, info) of "objchecks": ProcessOnOffSwitch({optObjCheck}, arg, pass, info)
of wFieldChecks: ProcessOnOffSwitch({optFieldCheck}, arg, pass, info) of "fieldchecks": ProcessOnOffSwitch({optFieldCheck}, arg, pass, info)
of wRangeChecks: ProcessOnOffSwitch({optRangeCheck}, arg, pass, info) of "rangechecks": ProcessOnOffSwitch({optRangeCheck}, arg, pass, info)
of wBoundChecks: ProcessOnOffSwitch({optBoundsCheck}, arg, pass, info) of "boundchecks": ProcessOnOffSwitch({optBoundsCheck}, arg, pass, info)
of wOverflowChecks: ProcessOnOffSwitch({optOverflowCheck}, arg, pass, info) of "overflowchecks": ProcessOnOffSwitch({optOverflowCheck}, arg, pass, info)
of wLineDir: ProcessOnOffSwitch({optLineDir}, arg, pass, info) of "linedir": ProcessOnOffSwitch({optLineDir}, arg, pass, info)
of wAssertions, wA: ProcessOnOffSwitch({optAssert}, arg, pass, info) of "assertions", "a": ProcessOnOffSwitch({optAssert}, arg, pass, info)
of wDeadCodeElim: ProcessOnOffSwitchG({optDeadCodeElim}, arg, pass, info) of "deadcodeelim": ProcessOnOffSwitchG({optDeadCodeElim}, arg, pass, info)
of wThreads: ProcessOnOffSwitchG({optThreads}, arg, pass, info) of "threads": ProcessOnOffSwitchG({optThreads}, arg, pass, info)
of wOpt: of "opt":
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)
case whichKeyword(arg) case arg.normalize
of wSpeed: of "speed":
incl(gOptions, optOptimizeSpeed) incl(gOptions, optOptimizeSpeed)
excl(gOptions, optOptimizeSize) excl(gOptions, optOptimizeSize)
of wSize: of "size":
excl(gOptions, optOptimizeSpeed) excl(gOptions, optOptimizeSpeed)
incl(gOptions, optOptimizeSize) incl(gOptions, optOptimizeSize)
of wNone: of "none":
excl(gOptions, optOptimizeSpeed) excl(gOptions, optOptimizeSpeed)
excl(gOptions, optOptimizeSize) excl(gOptions, optOptimizeSize)
else: LocalError(info, errNoneSpeedOrSizeExpectedButXFound, arg) else: LocalError(info, errNoneSpeedOrSizeExpectedButXFound, arg)
of wApp: of "app":
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)
case whichKeyword(arg) case arg.normalize
of wGui: of "gui":
incl(gGlobalOptions, optGenGuiApp) incl(gGlobalOptions, optGenGuiApp)
defineSymbol("guiapp") defineSymbol("guiapp")
of wConsole: of "console":
excl(gGlobalOptions, optGenGuiApp) excl(gGlobalOptions, optGenGuiApp)
of wLib: of "lib":
incl(gGlobalOptions, optGenDynLib) incl(gGlobalOptions, optGenDynLib)
excl(gGlobalOptions, optGenGuiApp) excl(gGlobalOptions, optGenGuiApp)
defineSymbol("library") defineSymbol("library")
else: LocalError(info, errGuiConsoleOrLibExpectedButXFound, arg) else: LocalError(info, errGuiConsoleOrLibExpectedButXFound, arg)
of wPassC, wT: of "passc", "t":
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)
if pass in {passCmd2, passPP}: extccomp.addCompileOption(arg) if pass in {passCmd2, passPP}: extccomp.addCompileOption(arg)
of wPassL, wL: of "passl", "l":
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)
if pass in {passCmd2, passPP}: extccomp.addLinkOption(arg) if pass in {passCmd2, passPP}: extccomp.addLinkOption(arg)
of wIndex: of "index":
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)
if pass in {passCmd2, passPP}: gIndexFile = arg if pass in {passCmd2, passPP}: gIndexFile = arg
of wImport: of "import":
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)
options.addImplicitMod(arg) options.addImplicitMod(arg)
of wListCmd: of "listcmd":
expectNoArg(switch, arg, pass, info) expectNoArg(switch, arg, pass, info)
incl(gGlobalOptions, optListCmd) incl(gGlobalOptions, optListCmd)
of wGenMapping: of "genmapping":
expectNoArg(switch, arg, pass, info) expectNoArg(switch, arg, pass, info)
incl(gGlobalOptions, optGenMapping) incl(gGlobalOptions, optGenMapping)
of wOS: of "os":
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)
if (pass == passCmd1): if (pass == passCmd1):
theOS = platform.NameToOS(arg) theOS = platform.NameToOS(arg)
@@ -446,7 +451,7 @@ proc processSwitch(switch, arg: string, pass: TCmdlinePass, info: TLineInfo) =
setTarget(theOS, targetCPU) setTarget(theOS, targetCPU)
incl(gGlobalOptions, optCompileOnly) incl(gGlobalOptions, optCompileOnly)
condsyms.InitDefines() condsyms.InitDefines()
of wCPU: of "cpu":
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)
if (pass == passCmd1): if (pass == passCmd1):
cpu = platform.NameToCPU(arg) cpu = platform.NameToCPU(arg)
@@ -455,61 +460,61 @@ proc processSwitch(switch, arg: string, pass: TCmdlinePass, info: TLineInfo) =
setTarget(targetOS, cpu) setTarget(targetOS, cpu)
incl(gGlobalOptions, optCompileOnly) incl(gGlobalOptions, optCompileOnly)
condsyms.InitDefines() condsyms.InitDefines()
of wRun, wR: of "run", "r":
expectNoArg(switch, arg, pass, info) expectNoArg(switch, arg, pass, info)
incl(gGlobalOptions, optRun) incl(gGlobalOptions, optRun)
of wVerbosity: of "verbosity":
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)
gVerbosity = parseInt(arg) gVerbosity = parseInt(arg)
of wParallelBuild: of "parallelbuild":
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)
gNumberOfProcessors = parseInt(arg) gNumberOfProcessors = parseInt(arg)
of wVersion, wV: of "version", "v":
expectNoArg(switch, arg, pass, info) expectNoArg(switch, arg, pass, info)
writeVersionInfo(pass) writeVersionInfo(pass)
of wAdvanced: of "advanced":
expectNoArg(switch, arg, pass, info) expectNoArg(switch, arg, pass, info)
writeAdvancedUsage(pass) writeAdvancedUsage(pass)
of wHelp, wH: of "help", "h":
expectNoArg(switch, arg, pass, info) expectNoArg(switch, arg, pass, info)
helpOnError(pass) helpOnError(pass)
of wSymbolFiles: of "symbolfiles":
ProcessOnOffSwitchG({optSymbolFiles}, arg, pass, info) ProcessOnOffSwitchG({optSymbolFiles}, arg, pass, info)
of wSkipCfg: of "skipcfg":
expectNoArg(switch, arg, pass, info) expectNoArg(switch, arg, pass, info)
incl(gGlobalOptions, optSkipConfigFile) incl(gGlobalOptions, optSkipConfigFile)
of wSkipProjCfg: of "skipprojcfg":
expectNoArg(switch, arg, pass, info) expectNoArg(switch, arg, pass, info)
incl(gGlobalOptions, optSkipProjConfigFile) incl(gGlobalOptions, optSkipProjConfigFile)
of wGenScript: of "genscript":
expectNoArg(switch, arg, pass, info) expectNoArg(switch, arg, pass, info)
incl(gGlobalOptions, optGenScript) incl(gGlobalOptions, optGenScript)
of wLib: of "lib":
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)
libpath = processPath(arg) libpath = processPath(arg)
of wPutEnv: of "putenv":
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)
splitSwitch(arg, key, val, pass, info) splitSwitch(arg, key, val, pass, info)
os.putEnv(key, val) os.putEnv(key, val)
of wCC: of "cc":
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)
setCC(arg) setCC(arg)
of wTrack: of "track":
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)
track(arg, info) track(arg, info)
of wSuggest: of "suggest":
expectNoArg(switch, arg, pass, info) expectNoArg(switch, arg, pass, info)
incl(gGlobalOptions, optSuggest) incl(gGlobalOptions, optSuggest)
of wDef: of "def":
expectNoArg(switch, arg, pass, info) expectNoArg(switch, arg, pass, info)
incl(gGlobalOptions, optDef) incl(gGlobalOptions, optDef)
of wContext: of "context":
expectNoArg(switch, arg, pass, info) expectNoArg(switch, arg, pass, info)
incl(gGlobalOptions, optContext) incl(gGlobalOptions, optContext)
of wStdout: of "stdout":
expectNoArg(switch, arg, pass, info) expectNoArg(switch, arg, pass, info)
incl(gGlobalOptions, optStdout) incl(gGlobalOptions, optStdout)
else: else:
if strutils.find(switch, '.') >= 0: options.setConfigVar(switch, arg) if strutils.find(switch, '.') >= 0: options.setConfigVar(switch, arg)
else: InvalidCmdLineOption(pass, switch, info) else: InvalidCmdLineOption(pass, switch, info)

View File

@@ -58,7 +58,10 @@ proc HandleCmdLine() =
var command = "" var command = ""
var filename = "" var filename = ""
ProcessCmdLine(passCmd1, command, filename) ProcessCmdLine(passCmd1, command, filename)
if filename != "": options.projectPath = splitFile(filename).dir if filename != "":
var p = splitFile(filename)
options.projectPath = p.dir
options.projectName = p.name
nimconf.LoadConfig(filename) # load the right config file nimconf.LoadConfig(filename) # load the right config file
# 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

View File

@@ -104,6 +104,8 @@ var
gConfigVars*: PStringTable gConfigVars*: PStringTable
libpath*: string = "" libpath*: string = ""
projectPath*: string = "" projectPath*: string = ""
projectName* = ""
nimcacheDir* = ""
gKeepComments*: bool = true # whether the parser needs to keep comments gKeepComments*: bool = true # whether the parser needs to keep comments
gImplicitMods*: TStringSeq = @[] # modules that are to be implicitly imported gImplicitMods*: TStringSeq = @[] # modules that are to be implicitly imported
@@ -155,16 +157,19 @@ proc removeTrailingDirSep*(path: string): string =
else: else:
result = path result = path
proc getGeneratedPath: string =
result = if nimcacheDir.len > 0: nimcacheDir else: projectPath / genSubDir
proc toGeneratedFile(path, ext: string): string = proc toGeneratedFile(path, ext: string): string =
var (head, tail) = splitPath(path) var (head, tail) = splitPath(path)
if len(head) > 0: head = shortenDir(head & dirSep) if len(head) > 0: head = shortenDir(head & dirSep)
result = joinPath([projectPath, genSubDir, head, changeFileExt(tail, ext)]) result = joinPath([getGeneratedPath(), head, changeFileExt(tail, ext)])
proc completeGeneratedFilePath(f: string, createSubDir: bool = true): string = proc completeGeneratedFilePath(f: string, createSubDir: bool = true): string =
var (head, tail) = splitPath(f) var (head, tail) = splitPath(f)
if len(head) > 0: head = removeTrailingDirSep(shortenDir(head & dirSep)) if len(head) > 0: head = removeTrailingDirSep(shortenDir(head & dirSep))
var subdir = joinPath([projectPath, genSubDir, head]) var subdir = getGeneratedPath() / head
if createSubDir: if createSubDir:
try: try:
createDir(subdir) createDir(subdir)
except EOS: except EOS:

View File

@@ -334,34 +334,6 @@ proc addVar(father, v: PNode) =
addSon(vpart, ast.emptyNode) addSon(vpart, ast.emptyNode)
addSon(father, vpart) addSon(father, vpart)
when false:
proc transformAddrDeref(c: PTransf, n: PNode, a, b: TNodeKind): PTransNode =
case n.sons[0].kind
of nkObjUpConv, nkObjDownConv, nkChckRange, nkChckRangeF, nkChckRange64:
var m = n.sons[0].sons[0]
if m.kind == a or m.kind == b:
# addr ( nkConv ( deref ( x ) ) ) --> nkConv(x)
var x = copyTree(n)
x.sons[0].sons[0] = m.sons[0]
result = transform(c, x.sons[0])
else:
result = transformSons(c, n)
of nkHiddenStdConv, nkHiddenSubConv, nkConv:
var m = n.sons[0].sons[1]
if m.kind == a or m.kind == b:
# addr ( nkConv ( deref ( x ) ) ) --> nkConv(x)
var x = copyTree(n)
x.sons[0].sons[1] = m.sons[0]
result = transform(c, x.sons[0])
else:
result = transformSons(c, n)
else:
if n.sons[0].kind == a or n.sons[0].kind == b:
# addr ( deref ( x )) --> x
result = transform(c, n.sons[0].sons[0])
else:
result = transformSons(c, n)
proc transformAddrDeref(c: PTransf, n: PNode, a, b: TNodeKind): PTransNode = proc transformAddrDeref(c: PTransf, n: PNode, a, b: TNodeKind): PTransNode =
result = transformSons(c, n) result = transformSons(c, n)
var n = result.pnode var n = result.pnode
@@ -519,14 +491,8 @@ proc transformFor(c: PTransf, n: PNode): PTransNode =
IdNodeTablePut(newC.mapping, formal, newSymNode(temp)) IdNodeTablePut(newC.mapping, formal, newSymNode(temp))
of paVarAsgn: of paVarAsgn:
assert(skipTypes(formal.typ, abstractInst).kind == tyVar) assert(skipTypes(formal.typ, abstractInst).kind == tyVar)
# XXX why is this even necessary?
when false:
var b = newNodeIT(nkHiddenAddr, arg.info, formal.typ)
b.add(arg)
arg = b
IdNodeTablePut(newC.mapping, formal, arg) IdNodeTablePut(newC.mapping, formal, arg)
# XXX BUG still not correct if the arg has a side effect! # XXX BUG still not correct if the arg has a side effect!
#InternalError(arg.info, "not implemented: pass to var parameter")
var body = newC.owner.ast.sons[codePos] var body = newC.owner.ast.sons[codePos]
pushInfoContext(n.info) pushInfoContext(n.info)
inc(c.inlining) inc(c.inlining)

View File

@@ -40,27 +40,22 @@ type
wAlign, wNodecl, wPure, wVolatile, wRegister, wSideeffect, wHeader, wAlign, wNodecl, wPure, wVolatile, wRegister, wSideeffect, wHeader,
wNosideeffect, wNoreturn, wMerge, wLib, wDynlib, wCompilerproc, wProcVar, wNosideeffect, wNoreturn, wMerge, wLib, wDynlib, wCompilerproc, wProcVar,
wFatal, wError, wWarning, wHint, wLine, wPush, wPop, wDefine, wUndef, wFatal, wError, wWarning, wHint, wLine, wPush, wPop, wDefine, wUndef,
wLinedir, wStacktrace, wLinetrace, wParallelBuild, wLink, wCompile, wLinedir, wStacktrace, wLinetrace, wLink, wCompile,
wLinksys, wDeprecated, wVarargs, wByref, wCallconv, wBreakpoint, wDebugger, wLinksys, wDeprecated, wVarargs, wByref, wCallconv, wBreakpoint, wDebugger,
wNimcall, wStdcall, wCdecl, wSafecall, wSyscall, wInline, wNoInline, wNimcall, wStdcall, wCdecl, wSafecall, wSyscall, wInline, wNoInline,
wFastcall, wClosure, wNoconv, wOn, wOff, wChecks, wRangechecks, wFastcall, wClosure, wNoconv, wOn, wOff, wChecks, wRangechecks,
wBoundchecks, wOverflowchecks, wNilchecks, wBoundchecks, wOverflowchecks, wNilchecks,
wFloatchecks, wNanChecks, wInfChecks, wFloatchecks, wNanChecks, wInfChecks,
wAssertions, wWarnings, wW, wAssertions, wWarnings,
wHints, wOptimization, wSpeed, wSize, wNone, wPath, wP, wD, wU, wDebuginfo, wHints, wOptimization, wSpeed, wSize, wNone,
wCompileonly, wNolinking, wForcebuild, wF, wDeadCodeElim, wSafecode, wDeadCodeElim, wSafecode,
wPragma, wPragma,
wCompileTime, wGc, wRefc, wBoehm, wA, wOpt, wO, wApp, wConsole, wGui, wCompileTime,
wPassc, wT, wPassl, wL, wListcmd, wGendoc, wGenmapping, wOs, wCpu, wPassc, wPassl, wBorrow,
wGenerate, wG, wC, wBorrow, wRun, wR, wVerbosity, wV, wHelp, wH, wFieldChecks,
wSymbolFiles, wFieldChecks, wX, wVersion, wAdvanced, wSkipcfg, wSkipProjCfg, wCheckPoint, wSubsChar,
wCc, wGenscript, wCheckPoint, wThreadAnalysis, wNoMain, wSubsChar,
wAcyclic, wShallow, wUnroll, wLinearScanEnd, wAcyclic, wShallow, wUnroll, wLinearScanEnd,
wIndex, wWrite, wPutEnv, wPrependEnv, wAppendEnv, wThreadVar, wEmit
wWrite, wPutEnv, wPrependEnv, wAppendEnv, wThreadVar, wEmit, wThreads,
wRecursivePath,
wStdout,
wIdeTools, wSuggest, wTrack, wDef, wContext
TSpecialWords* = set[TSpecialWord] TSpecialWords* = set[TSpecialWord]
@@ -89,28 +84,22 @@ const
"header", "nosideeffect", "noreturn", "merge", "lib", "dynlib", "header", "nosideeffect", "noreturn", "merge", "lib", "dynlib",
"compilerproc", "procvar", "fatal", "error", "warning", "hint", "line", "compilerproc", "procvar", "fatal", "error", "warning", "hint", "line",
"push", "pop", "define", "undef", "linedir", "stacktrace", "linetrace", "push", "pop", "define", "undef", "linedir", "stacktrace", "linetrace",
"parallelbuild", "link", "compile", "linksys", "deprecated", "varargs", "link", "compile", "linksys", "deprecated", "varargs",
"byref", "callconv", "breakpoint", "debugger", "nimcall", "stdcall", "byref", "callconv", "breakpoint", "debugger", "nimcall", "stdcall",
"cdecl", "safecall", "syscall", "inline", "noinline", "fastcall", "closure", "cdecl", "safecall", "syscall", "inline", "noinline", "fastcall", "closure",
"noconv", "on", "off", "checks", "rangechecks", "boundchecks", "noconv", "on", "off", "checks", "rangechecks", "boundchecks",
"overflowchecks", "nilchecks", "overflowchecks", "nilchecks",
"floatchecks", "nanchecks", "infchecks", "floatchecks", "nanchecks", "infchecks",
"assertions", "warnings", "w", "hints", "assertions", "warnings", "hints",
"optimization", "speed", "size", "none", "path", "p", "d", "u", "debuginfo", "optimization", "speed", "size", "none",
"compileonly", "nolinking", "forcebuild", "f", "deadcodeelim", "safecode", "deadcodeelim", "safecode",
"pragma", "pragma",
"compiletime", "gc", "refc", "boehm", "a", "opt", "o", "app", "console", "compiletime",
"gui", "passc", "t", "passl", "l", "listcmd", "gendoc", "genmapping", "os", "passc", "passl", "borrow", "fieldchecks",
"cpu", "generate", "g", "c", "borrow", "run", "r", "verbosity", "v", "checkpoint",
"help", "h", "symbolfiles", "fieldchecks", "x", "version", "advanced", "subschar", "acyclic", "shallow", "unroll", "linearscanend",
"skipcfg", "skipprojcfg", "cc", "genscript", "checkpoint", "threadanalysis", "write", "putenv", "prependenv", "appendenv", "threadvar", "emit"]
"nomain", "subschar", "acyclic", "shallow", "unroll", "linearscanend",
"index",
"write", "putenv", "prependenv", "appendenv", "threadvar", "emit",
"threads", "recursivepath",
"stdout",
"idetools", "suggest", "track", "def", "context"]
proc findStr*(a: openarray[string], s: string): int = proc findStr*(a: openarray[string], s: string): int =
for i in countup(low(a), high(a)): for i in countup(low(a), high(a)):

View File

@@ -512,6 +512,21 @@ proc cmpPaths*(pathA, pathB: string): int {.
else: else:
result = cmpIgnoreCase(pathA, pathB) result = cmpIgnoreCase(pathA, pathB)
proc isAbsolute*(path: string): bool {.rtl, noSideEffect, extern: "nos$1".} =
## Checks whether a given path is absolute.
##
## on Windows, network paths are considered absolute too.
var len = len(path)
when doslike:
result = (len > 1 and path[0] in {'/', '\\'}) or
(len > 2 and path[0] in Letters and path[1] == ':')
elif defined(macos):
result = len > 0 and path[0] != ':'
elif defined(RISCOS):
result = path[0] == '$'
elif defined(posix):
result = path[0] == '/'
proc sameFile*(path1, path2: string): bool {.rtl, extern: "nos$1".} = proc sameFile*(path1, path2: string): bool {.rtl, extern: "nos$1".} =
## Returns True if both pathname arguments refer to the same file or ## Returns True if both pathname arguments refer to the same file or
## directory (as indicated by device number and i-node number). ## directory (as indicated by device number and i-node number).

View File

@@ -1,7 +1,6 @@
Version 0.8.14 Version 0.8.14
============== ==============
- fix ``m*`` for generics
- optional indentation for 'case' statement - optional indentation for 'case' statement
- test the sort implementation again - test the sort implementation again
- export re-entrant and non-reentrant locks and condition vars; threads should - export re-entrant and non-reentrant locks and condition vars; threads should

View File

@@ -66,7 +66,8 @@ Library Additions
- Added ``strutils.unindent``. - Added ``strutils.unindent``.
- Added ``system.slurp`` for easy resource embedding. - Added ``system.slurp`` for easy resource embedding.
- Added ``system.running`` for threads. - Added ``system.running`` for threads.
- Added proc ``xmltree.innerText``. - Added ``xmltree.innerText``.
- Added ``os.isAbsolute``.
2011-07-10 Version 0.8.12 released 2011-07-10 Version 0.8.12 released