move more globals into the config object

This commit is contained in:
Andreas Rumpf 2018-05-13 14:19:42 +02:00
commit 297038f704
6 changed files with 101 additions and 93 deletions

View file

@ -2025,7 +2025,7 @@ template genStmtListExprImpl(exprOrStmt) {.dirty.} =
let theMacro = it[0].sym let theMacro = it[0].sym
add p.s(cpsStmts), initFrameNoDebug(p, frameName, add p.s(cpsStmts), initFrameNoDebug(p, frameName,
makeCString theMacro.name.s, makeCString theMacro.name.s,
theMacro.info.quotedFilename, it.info.line.int) quotedFilename(p.config, theMacro.info), it.info.line.int)
else: else:
genStmts(p, it) genStmts(p, it)
if n.len > 0: exprOrStmt if n.len > 0: exprOrStmt

View file

@ -225,7 +225,7 @@ proc genLineDir(p: BProc, t: PNode) =
(p.prc == nil or sfPure notin p.prc.flags) and tt.info.fileIndex != InvalidFileIDX: (p.prc == nil or sfPure notin p.prc.flags) and tt.info.fileIndex != InvalidFileIDX:
if freshLineInfo(p, tt.info): if freshLineInfo(p, tt.info):
linefmt(p, cpsStmts, "nimln_($1, $2);$n", linefmt(p, cpsStmts, "nimln_($1, $2);$n",
line.rope, tt.info.quotedFilename) line.rope, quotedFilename(p.config, tt.info))
proc postStmtActions(p: BProc) {.inline.} = proc postStmtActions(p: BProc) {.inline.} =
add(p.s(cpsStmts), p.module.injectStmt) add(p.s(cpsStmts), p.module.injectStmt)
@ -771,7 +771,7 @@ proc genProcAux(m: BModule, prc: PSym) =
if optStackTrace in prc.options: if optStackTrace in prc.options:
add(generatedProc, p.s(cpsLocals)) add(generatedProc, p.s(cpsLocals))
var procname = makeCString(prc.name.s) var procname = makeCString(prc.name.s)
add(generatedProc, initFrame(p, procname, prc.info.quotedFilename)) add(generatedProc, initFrame(p, procname, quotedFilename(p.config, prc.info)))
else: else:
add(generatedProc, p.s(cpsLocals)) add(generatedProc, p.s(cpsLocals))
if optProfiler in prc.options: if optProfiler in prc.options:
@ -1151,7 +1151,7 @@ proc genInitCode(m: BModule) =
incl m.flags, frameDeclared incl m.flags, frameDeclared
if preventStackTrace notin m.flags: if preventStackTrace notin m.flags:
var procname = makeCString(m.module.name.s) var procname = makeCString(m.module.name.s)
add(prc, initFrame(m.initProc, procname, m.module.info.quotedFilename)) add(prc, initFrame(m.initProc, procname, quotedFilename(m.config, m.module.info)))
else: else:
add(prc, ~"\tTFrame FR_; FR_.len = 0;$N") add(prc, ~"\tTFrame FR_; FR_.len = 0;$N")

View file

@ -380,11 +380,11 @@ proc getConfigVar(conf: ConfigRef; c: TSystemCC, suffix: string): string =
# use ``cpu.os.cc`` for cross compilation, unless ``--compileOnly`` is given # use ``cpu.os.cc`` for cross compilation, unless ``--compileOnly`` is given
# for niminst support # for niminst support
let fullSuffix = let fullSuffix =
if gCmd == cmdCompileToCpp: if conf.cmd == cmdCompileToCpp:
".cpp" & suffix ".cpp" & suffix
elif gCmd == cmdCompileToOC: elif conf.cmd == cmdCompileToOC:
".objc" & suffix ".objc" & suffix
elif gCmd == cmdCompileToJS: elif conf.cmd == cmdCompileToJS:
".js" & suffix ".js" & suffix
else: else:
suffix suffix
@ -535,7 +535,7 @@ proc needsExeExt(conf: ConfigRef): bool {.inline.} =
(platform.hostOS == osWindows) (platform.hostOS == osWindows)
proc getCompilerExe(conf: ConfigRef; compiler: TSystemCC; cfile: string): string = proc getCompilerExe(conf: ConfigRef; compiler: TSystemCC; cfile: string): string =
result = if gCmd == cmdCompileToCpp and not cfile.endsWith(".c"): result = if conf.cmd == cmdCompileToCpp and not cfile.endsWith(".c"):
CC[compiler].cppCompiler CC[compiler].cppCompiler
else: else:
CC[compiler].compilerExe CC[compiler].compilerExe
@ -546,7 +546,7 @@ proc getCompilerExe(conf: ConfigRef; compiler: TSystemCC; cfile: string): string
proc getLinkerExe(conf: ConfigRef; compiler: TSystemCC): string = proc getLinkerExe(conf: ConfigRef; compiler: TSystemCC): string =
result = if CC[compiler].linkerExe.len > 0: CC[compiler].linkerExe result = if CC[compiler].linkerExe.len > 0: CC[compiler].linkerExe
elif gMixedMode and gCmd != cmdCompileToCpp: CC[compiler].cppCompiler elif gMixedMode and conf.cmd != cmdCompileToCpp: CC[compiler].cppCompiler
else: getCompilerExe(conf, compiler, "") else: getCompilerExe(conf, compiler, "")
proc getCompileCFileCmd*(conf: ConfigRef; cfile: Cfile): string = proc getCompileCFileCmd*(conf: ConfigRef; cfile: Cfile): string =
@ -610,7 +610,7 @@ proc footprint(conf: ConfigRef; cfile: Cfile): SecureHash =
getCompileCFileCmd(conf, cfile)) getCompileCFileCmd(conf, cfile))
proc externalFileChanged(conf: ConfigRef; cfile: Cfile): bool = proc externalFileChanged(conf: ConfigRef; cfile: Cfile): bool =
if gCmd notin {cmdCompileToC, cmdCompileToCpp, cmdCompileToOC, cmdCompileToLLVM}: if conf.cmd notin {cmdCompileToC, cmdCompileToCpp, cmdCompileToOC, cmdCompileToLLVM}:
return false return false
var hashFile = toGeneratedFile(conf, conf.withPackageName(cfile.cname), "sha1") var hashFile = toGeneratedFile(conf, conf.withPackageName(cfile.cname), "sha1")

View file

@ -99,7 +99,6 @@ proc newFileInfo(fullPath, projPath: string): TFileInfo =
result.shortName = fileName.changeFileExt("") result.shortName = fileName.changeFileExt("")
result.quotedName = fileName.makeCString result.quotedName = fileName.makeCString
result.quotedFullName = fullPath.makeCString result.quotedFullName = fullPath.makeCString
if optEmbedOrigSrc in gGlobalOptions or true:
result.lines = @[] result.lines = @[]
when defined(nimpretty): when defined(nimpretty):
if result.fullPath.len > 0: if result.fullPath.len > 0:
@ -268,10 +267,10 @@ template toFilename*(info: TLineInfo): string =
template toFullPath*(info: TLineInfo): string = template toFullPath*(info: TLineInfo): string =
info.fileIndex.toFullPath info.fileIndex.toFullPath
proc toMsgFilename*(info: TLineInfo): string = proc toMsgFilename*(conf: ConfigRef; info: TLineInfo): string =
if info.fileIndex.int32 < 0: if info.fileIndex.int32 < 0:
result = "???" result = "???"
elif gListFullPaths: elif optListFullPaths in conf.globalOptions:
result = fileInfos[info.fileIndex.int32].fullPath result = fileInfos[info.fileIndex.int32].fullPath
else: else:
result = fileInfos[info.fileIndex.int32].projPath result = fileInfos[info.fileIndex.int32].projPath
@ -306,7 +305,7 @@ type
msgSkipHook ## skip message hook even if it is present msgSkipHook ## skip message hook even if it is present
MsgFlags* = set[MsgFlag] MsgFlags* = set[MsgFlag]
proc msgWriteln*(s: string, flags: MsgFlags = {}) = proc msgWriteln*(conf: ConfigRef; s: string, flags: MsgFlags = {}) =
## Writes given message string to stderr by default. ## Writes given message string to stderr by default.
## If ``--stdout`` option is given, writes to stdout instead. If message hook ## If ``--stdout`` option is given, writes to stdout instead. If message hook
## is present, then it is used to output message rather than stderr/stdout. ## is present, then it is used to output message rather than stderr/stdout.
@ -318,7 +317,7 @@ proc msgWriteln*(s: string, flags: MsgFlags = {}) =
if not isNil(writelnHook) and msgSkipHook notin flags: if not isNil(writelnHook) and msgSkipHook notin flags:
writelnHook(s) writelnHook(s)
elif optStdout in gGlobalOptions or msgStdout in flags: elif optStdout in conf.globalOptions or msgStdout in flags:
if eStdOut in errorOutputs: if eStdOut in errorOutputs:
writeLine(stdout, s) writeLine(stdout, s)
flushFile(stdout) flushFile(stdout)
@ -359,13 +358,13 @@ template callWritelnHook(args: varargs[string, `$`]) =
template styledMsgWriteln*(args: varargs[typed]) = template styledMsgWriteln*(args: varargs[typed]) =
if not isNil(writelnHook): if not isNil(writelnHook):
callIgnoringStyle(callWritelnHook, nil, args) callIgnoringStyle(callWritelnHook, nil, args)
elif optStdout in gGlobalOptions: elif optStdout in conf.globalOptions:
if eStdOut in errorOutputs: if eStdOut in errorOutputs:
callIgnoringStyle(writeLine, stdout, args) callIgnoringStyle(writeLine, stdout, args)
flushFile(stdout) flushFile(stdout)
else: else:
if eStdErr in errorOutputs: if eStdErr in errorOutputs:
if optUseColors in gGlobalOptions: if optUseColors in conf.globalOptions:
callStyledWriteLineStderr(args) callStyledWriteLineStderr(args)
else: else:
callIgnoringStyle(writeLine, stderr, args) callIgnoringStyle(writeLine, stderr, args)
@ -405,14 +404,14 @@ proc quit(conf: ConfigRef; msg: TMsgKind) =
proc handleError(conf: ConfigRef; msg: TMsgKind, eh: TErrorHandling, s: string) = proc handleError(conf: ConfigRef; msg: TMsgKind, eh: TErrorHandling, s: string) =
if msg >= fatalMin and msg <= fatalMax: if msg >= fatalMin and msg <= fatalMax:
if gCmd == cmdIdeTools: log(s) if conf.cmd == cmdIdeTools: log(s)
quit(conf, msg) quit(conf, msg)
if msg >= errMin and msg <= errMax: if msg >= errMin and msg <= errMax:
inc(conf.errorCounter) inc(conf.errorCounter)
options.gExitcode = 1'i8 conf.exitcode = 1'i8
if conf.errorCounter >= conf.errorMax: if conf.errorCounter >= conf.errorMax:
quit(conf, msg) quit(conf, msg)
elif eh == doAbort and gCmd != cmdIdeTools: elif eh == doAbort and conf.cmd != cmdIdeTools:
quit(conf, msg) quit(conf, msg)
elif eh == doRaise: elif eh == doRaise:
raiseRecoverableError(s) raiseRecoverableError(s)
@ -433,7 +432,7 @@ proc writeContext(conf: ConfigRef; lastinfo: TLineInfo) =
Severity.Error) Severity.Error)
else: else:
styledMsgWriteln(styleBright, styledMsgWriteln(styleBright,
PosFormat % [toMsgFilename(msgContext[i]), PosFormat % [toMsgFilename(conf, msgContext[i]),
coordToStr(msgContext[i].line.int), coordToStr(msgContext[i].line.int),
coordToStr(msgContext[i].col+1)], coordToStr(msgContext[i].col+1)],
resetStyle, resetStyle,
@ -441,7 +440,7 @@ proc writeContext(conf: ConfigRef; lastinfo: TLineInfo) =
info = msgContext[i] info = msgContext[i]
proc ignoreMsgBecauseOfIdeTools(conf: ConfigRef; msg: TMsgKind): bool = proc ignoreMsgBecauseOfIdeTools(conf: ConfigRef; msg: TMsgKind): bool =
msg >= errGenerated and gCmd == cmdIdeTools and optIdeDebug notin gGlobalOptions msg >= errGenerated and conf.cmd == cmdIdeTools and optIdeDebug notin conf.globalOptions
proc rawMessage*(conf: ConfigRef; msg: TMsgKind, args: openArray[string]) = proc rawMessage*(conf: ConfigRef; msg: TMsgKind, args: openArray[string]) =
var var
@ -457,7 +456,7 @@ proc rawMessage*(conf: ConfigRef; msg: TMsgKind, args: openArray[string]) =
color = ErrorColor color = ErrorColor
of warnMin..warnMax: of warnMin..warnMax:
sev = Severity.Warning sev = Severity.Warning
if optWarns notin gOptions: return if optWarns notin conf.options: return
if msg notin conf.notes: return if msg notin conf.notes: return
writeContext(conf, unknownLineInfo()) writeContext(conf, unknownLineInfo())
title = WarningTitle title = WarningTitle
@ -466,7 +465,7 @@ proc rawMessage*(conf: ConfigRef; msg: TMsgKind, args: openArray[string]) =
inc(conf.warnCounter) inc(conf.warnCounter)
of hintMin..hintMax: of hintMin..hintMax:
sev = Severity.Hint sev = Severity.Hint
if optHints notin gOptions: return if optHints notin conf.options: return
if msg notin conf.notes: return if msg notin conf.notes: return
title = HintTitle title = HintTitle
color = HintColor color = HintColor
@ -489,20 +488,20 @@ proc rawMessage*(conf: ConfigRef; msg: TMsgKind, arg: string) =
rawMessage(conf, msg, [arg]) rawMessage(conf, msg, [arg])
proc resetAttributes*(conf: ConfigRef) = proc resetAttributes*(conf: ConfigRef) =
if {optUseColors, optStdout} * gGlobalOptions == {optUseColors}: if {optUseColors, optStdout} * conf.globalOptions == {optUseColors}:
terminal.resetAttributes(stderr) terminal.resetAttributes(stderr)
proc writeSurroundingSrc(conf: ConfigRef; info: TLineInfo) = proc writeSurroundingSrc(conf: ConfigRef; info: TLineInfo) =
const indent = " " const indent = " "
msgWriteln(indent & $sourceLine(conf, info)) msgWriteln(conf, indent & $sourceLine(conf, info))
msgWriteln(indent & spaces(info.col) & '^') msgWriteln(conf, indent & spaces(info.col) & '^')
proc formatMsg*(info: TLineInfo, msg: TMsgKind, arg: string): string = proc formatMsg*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string): string =
let title = case msg let title = case msg
of warnMin..warnMax: WarningTitle of warnMin..warnMax: WarningTitle
of hintMin..hintMax: HintTitle of hintMin..hintMax: HintTitle
else: ErrorTitle else: ErrorTitle
result = PosFormat % [toMsgFilename(info), coordToStr(info.line.int), result = PosFormat % [toMsgFilename(conf, info), coordToStr(info.line.int),
coordToStr(info.col+1)] & coordToStr(info.col+1)] &
title & title &
getMessageStr(msg, arg) getMessageStr(msg, arg)
@ -527,7 +526,7 @@ proc liMessage(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string,
lastError = info lastError = info
of warnMin..warnMax: of warnMin..warnMax:
sev = Severity.Warning sev = Severity.Warning
ignoreMsg = optWarns notin gOptions or msg notin conf.notes ignoreMsg = optWarns notin conf.options or msg notin conf.notes
if not ignoreMsg: writeContext(conf, info) if not ignoreMsg: writeContext(conf, info)
title = WarningTitle title = WarningTitle
color = WarningColor color = WarningColor
@ -535,7 +534,7 @@ proc liMessage(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string,
inc(conf.warnCounter) inc(conf.warnCounter)
of hintMin..hintMax: of hintMin..hintMax:
sev = Severity.Hint sev = Severity.Hint
ignoreMsg = optHints notin gOptions or msg notin conf.notes ignoreMsg = optHints notin conf.options or msg notin conf.notes
title = HintTitle title = HintTitle
color = HintColor color = HintColor
if msg != hintUserRaw: kind = HintsToStr[ord(msg) - ord(hintMin)] if msg != hintUserRaw: kind = HintsToStr[ord(msg) - ord(hintMin)]
@ -543,7 +542,7 @@ proc liMessage(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string,
# NOTE: currently line info line numbers start with 1, # NOTE: currently line info line numbers start with 1,
# but column numbers start with 0, however most editors expect # but column numbers start with 0, however most editors expect
# first column to be 1, so we need to +1 here # first column to be 1, so we need to +1 here
let x = PosFormat % [toMsgFilename(info), coordToStr(info.line.int), let x = PosFormat % [toMsgFilename(conf, info), coordToStr(info.line.int),
coordToStr(info.col+1)] coordToStr(info.col+1)]
let s = getMessageStr(msg, arg) let s = getMessageStr(msg, arg)
@ -585,12 +584,12 @@ proc message*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") =
liMessage(conf, info, msg, arg, doNothing) liMessage(conf, info, msg, arg, doNothing)
proc internalError*(conf: ConfigRef; info: TLineInfo, errMsg: string) = proc internalError*(conf: ConfigRef; info: TLineInfo, errMsg: string) =
if gCmd == cmdIdeTools and structuredErrorHook.isNil: return if conf.cmd == cmdIdeTools and structuredErrorHook.isNil: return
writeContext(conf, info) writeContext(conf, info)
liMessage(conf, info, errInternal, errMsg, doAbort) liMessage(conf, info, errInternal, errMsg, doAbort)
proc internalError*(conf: ConfigRef; errMsg: string) = proc internalError*(conf: ConfigRef; errMsg: string) =
if gCmd == cmdIdeTools and structuredErrorHook.isNil: return if conf.cmd == cmdIdeTools and structuredErrorHook.isNil: return
writeContext(conf, unknownLineInfo()) writeContext(conf, unknownLineInfo())
rawMessage(conf, errInternal, errMsg) rawMessage(conf, errInternal, errMsg)
@ -619,9 +618,9 @@ proc sourceLine*(conf: ConfigRef; i: TLineInfo): Rope =
result = fileInfos[i.fileIndex.int32].lines[i.line.int-1] result = fileInfos[i.fileIndex.int32].lines[i.line.int-1]
proc quotedFilename*(i: TLineInfo): Rope = proc quotedFilename*(conf: ConfigRef; i: TLineInfo): Rope =
assert i.fileIndex.int32 >= 0 assert i.fileIndex.int32 >= 0
if optExcessiveStackTrace in gGlobalOptions: if optExcessiveStackTrace in conf.globalOptions:
result = fileInfos[i.fileIndex.int32].quotedFullName result = fileInfos[i.fileIndex.int32].quotedFullName
else: else:
result = fileInfos[i.fileIndex.int32].quotedName result = fileInfos[i.fileIndex.int32].quotedName
@ -634,21 +633,21 @@ ropes.errorHandler = proc (err: RopesError, msg: string, useWarning: bool) =
rawMessage(newPartialConfigRef(), if useWarning: warnCannotOpenFile else: errCannotOpenFile, msg) rawMessage(newPartialConfigRef(), if useWarning: warnCannotOpenFile else: errCannotOpenFile, msg)
proc listWarnings*(conf: ConfigRef) = proc listWarnings*(conf: ConfigRef) =
msgWriteln("Warnings:") msgWriteln(conf, "Warnings:")
for warn in warnMin..warnMax: for warn in warnMin..warnMax:
msgWriteln(" [$1] $2" % [ msgWriteln(conf, " [$1] $2" % [
if warn in conf.notes: "x" else: " ", if warn in conf.notes: "x" else: " ",
configuration.WarningsToStr[ord(warn) - ord(warnMin)] configuration.WarningsToStr[ord(warn) - ord(warnMin)]
]) ])
proc listHints*(conf: ConfigRef) = proc listHints*(conf: ConfigRef) =
msgWriteln("Hints:") msgWriteln(conf, "Hints:")
for hint in hintMin..hintMax: for hint in hintMin..hintMax:
msgWriteln(" [$1] $2" % [ msgWriteln(conf, " [$1] $2" % [
if hint in conf.notes: "x" else: " ", if hint in conf.notes: "x" else: " ",
configuration.HintsToStr[ord(hint) - ord(hintMin)] configuration.HintsToStr[ord(hint) - ord(hintMin)]
]) ])
# enable colors by default on terminals # enable colors by default on terminals
if terminal.isatty(stderr): #if terminal.isatty(stderr):
incl(gGlobalOptions, optUseColors) # incl(gGlobalOptions, optUseColors)

View file

@ -70,6 +70,11 @@ type # please make sure we have under 32 options
optIdeTerse # idetools: use terse descriptions optIdeTerse # idetools: use terse descriptions
optNoCppExceptions # use C exception handling even with CPP optNoCppExceptions # use C exception handling even with CPP
optExcessiveStackTrace # fully qualified module filenames optExcessiveStackTrace # fully qualified module filenames
opWholeProject # for 'doc2': output any dependency
optListFullPaths
optNoNimblePath
optDynlibOverrideAll
optUseNimNamespace
TGlobalOptions* = set[TGlobalOption] TGlobalOptions* = set[TGlobalOption]
@ -111,8 +116,22 @@ type
destructor, destructor,
notnil notnil
SymbolFilesOption* = enum
disabledSf, enabledSf, writeOnlySf, readOnlySf, v2Sf
ConfigRef* = ref object ## eventually all global configuration should be moved here ConfigRef* = ref object ## eventually all global configuration should be moved here
linesCompiled*: int # all lines that have been compiled linesCompiled*: int # all lines that have been compiled
options*: TOptions
globalOptions*: TGlobalOptions
exitcode*: int8
cmd*: TCommands # the command
selectedGC*: TGCMode # the selected GC
verbosity*: int # how verbose the compiler is
numberOfProcessors*: int # number of processors
evalExpr*: string # expression for idetools --eval
lastCmdTime*: float # when caas is enabled, we measure each command
symbolFiles*: SymbolFilesOption
cppDefines*: HashSet[string] cppDefines*: HashSet[string]
headerFile*: string headerFile*: string
features*: set[Feature] features*: set[Feature]
@ -154,6 +173,17 @@ type
const oldExperimentalFeatures* = {implicitDeref, dotOperators, callOperator, parallel} const oldExperimentalFeatures* = {implicitDeref, dotOperators, callOperator, parallel}
const
ChecksOptions* = {optObjCheck, optFieldCheck, optRangeCheck, optNilCheck,
optOverflowCheck, optBoundsCheck, optAssert, optNaNCheck, optInfCheck,
optMoveCheck}
DefaultOptions* = {optObjCheck, optFieldCheck, optRangeCheck,
optBoundsCheck, optOverflowCheck, optAssert, optWarns,
optHints, optStackTrace, optLineTrace,
optPatterns, optNilCheck, optMoveCheck}
DefaultGlobalOptions* = {optThreadAnalysis, optUseColors}
template newPackageCache*(): untyped = template newPackageCache*(): untyped =
newStringTable(when FileSystemCaseSensitive: newStringTable(when FileSystemCaseSensitive:
modeCaseInsensitive modeCaseInsensitive
@ -161,7 +191,13 @@ template newPackageCache*(): untyped =
modeCaseSensitive) modeCaseSensitive)
proc newConfigRef*(): ConfigRef = proc newConfigRef*(): ConfigRef =
result = ConfigRef(cppDefines: initSet[string](), result = ConfigRef(
selectedGC: gcRefc,
verbosity: 1,
options: DefaultOptions,
globalOptions: DefaultGlobalOptions,
evalExpr: "",
cppDefines: initSet[string](),
headerFile: "", features: {}, foreignPackageNotes: {hintProcessing, warnUnknownMagic, headerFile: "", features: {}, foreignPackageNotes: {hintProcessing, warnUnknownMagic,
hintQuitCalled, hintExecuting}, hintQuitCalled, hintExecuting},
notes: NotesVerbosity[1], mainPackageNotes: NotesVerbosity[1], notes: NotesVerbosity[1], mainPackageNotes: NotesVerbosity[1],
@ -188,7 +224,12 @@ proc newConfigRef*(): ConfigRef =
proc newPartialConfigRef*(): ConfigRef = proc newPartialConfigRef*(): ConfigRef =
## create a new ConfigRef that is only good enough for error reporting. ## create a new ConfigRef that is only good enough for error reporting.
result = ConfigRef(foreignPackageNotes: {hintProcessing, warnUnknownMagic, result = ConfigRef(
selectedGC: gcRefc,
verbosity: 1,
options: DefaultOptions,
globalOptions: DefaultGlobalOptions,
foreignPackageNotes: {hintProcessing, warnUnknownMagic,
hintQuitCalled, hintExecuting}, hintQuitCalled, hintExecuting},
notes: NotesVerbosity[1], mainPackageNotes: NotesVerbosity[1]) notes: NotesVerbosity[1], mainPackageNotes: NotesVerbosity[1])
@ -234,48 +275,15 @@ proc isDefined*(conf: ConfigRef; symbol: string): bool =
osDragonfly, osMacosx} osDragonfly, osMacosx}
else: discard else: discard
const proc importantComments*(conf: ConfigRef): bool {.inline.} = conf.cmd in {cmdDoc, cmdIdeTools}
ChecksOptions* = {optObjCheck, optFieldCheck, optRangeCheck, optNilCheck, proc usesNativeGC*(conf: ConfigRef): bool {.inline.} = conf.selectedGC >= gcRefc
optOverflowCheck, optBoundsCheck, optAssert, optNaNCheck, optInfCheck,
optMoveCheck}
var
gOptions*: TOptions = {optObjCheck, optFieldCheck, optRangeCheck,
optBoundsCheck, optOverflowCheck, optAssert, optWarns,
optHints, optStackTrace, optLineTrace,
optPatterns, optNilCheck, optMoveCheck}
gGlobalOptions*: TGlobalOptions = {optThreadAnalysis}
gExitcode*: int8
gCmd*: TCommands = cmdNone # the command
gSelectedGC* = gcRefc # the selected GC
#headerFile*: string = ""
gVerbosity* = 1 # how verbose the compiler is
gNumberOfProcessors*: int # number of processors
gWholeProject*: bool # for 'doc2': output any dependency
gEvalExpr* = "" # expression for idetools --eval
gLastCmdTime*: float # when caas is enabled, we measure each command
gListFullPaths*: bool
gPreciseStack*: bool
gNoNimblePath*: bool
gDynlibOverrideAll*: bool
useNimNamespace*: bool
type
SymbolFilesOption* = enum
disabledSf, enabledSf, writeOnlySf, readOnlySf, v2Sf
var gSymbolFiles*: SymbolFilesOption
proc importantComments*(conf: ConfigRef): bool {.inline.} = gCmd in {cmdDoc, cmdIdeTools}
proc usesNativeGC*(conf: ConfigRef): bool {.inline.} = gSelectedGC >= gcRefc
template preciseStack*(conf: ConfigRef): bool = gPreciseStack
template compilationCachePresent*(conf: ConfigRef): untyped = template compilationCachePresent*(conf: ConfigRef): untyped =
gSymbolFiles in {enabledSf, writeOnlySf} conf.symbolFiles in {enabledSf, writeOnlySf}
# {optCaasEnabled, optSymbolFiles} * gGlobalOptions != {} # {optCaasEnabled, optSymbolFiles} * gGlobalOptions != {}
template optPreserveOrigSource*(conf: ConfigRef): untyped = template optPreserveOrigSource*(conf: ConfigRef): untyped =
optEmbedOrigSrc in gGlobalOptions optEmbedOrigSrc in conf.globalOptions
const const
genSubDir* = "nimcache" genSubDir* = "nimcache"
@ -374,7 +382,7 @@ proc removeTrailingDirSep*(path: string): string =
result = path result = path
proc disableNimblePath*(conf: ConfigRef) = proc disableNimblePath*(conf: ConfigRef) =
gNoNimblePath = true incl conf.globalOptions, optNoNimblePath
conf.lazyPaths.setLen(0) conf.lazyPaths.setLen(0)
include packagehandling include packagehandling
@ -503,7 +511,8 @@ proc inclDynlibOverride*(conf: ConfigRef; lib: string) =
conf.dllOverrides[lib.canonDynlibName] = "true" conf.dllOverrides[lib.canonDynlibName] = "true"
proc isDynlibOverride*(conf: ConfigRef; lib: string): bool = proc isDynlibOverride*(conf: ConfigRef; lib: string): bool =
result = gDynlibOverrideAll or conf.dllOverrides.hasKey(lib.canonDynlibName) result = optDynlibOverrideAll in conf.globalOptions or
conf.dllOverrides.hasKey(lib.canonDynlibName)
proc binaryStrSearch*(x: openArray[string], y: string): int = proc binaryStrSearch*(x: openArray[string], y: string): int =
var a = 0 var a = 0

View file

@ -61,7 +61,7 @@ proc stackTraceAux(c: PCtx; x: PStackFrame; pc: int; recursionLimit=100) =
while x != nil: while x != nil:
inc calls inc calls
x = x.next x = x.next
msgWriteln($calls & " calls omitted\n") msgWriteln(c.config, $calls & " calls omitted\n")
return return
stackTraceAux(c, x.next, x.comesFrom, recursionLimit-1) stackTraceAux(c, x.next, x.comesFrom, recursionLimit-1)
var info = c.debug[pc] var info = c.debug[pc]
@ -78,11 +78,11 @@ proc stackTraceAux(c: PCtx; x: PStackFrame; pc: int; recursionLimit=100) =
if x.prc != nil: if x.prc != nil:
for k in 1..max(1, 25-s.len): add(s, ' ') for k in 1..max(1, 25-s.len): add(s, ' ')
add(s, x.prc.name.s) add(s, x.prc.name.s)
msgWriteln(s) msgWriteln(c.config, s)
proc stackTrace(c: PCtx, tos: PStackFrame, pc: int, proc stackTrace(c: PCtx, tos: PStackFrame, pc: int,
msg: string, n: PNode = nil) = msg: string, n: PNode = nil) =
msgWriteln("stack trace: (most recent call last)") msgWriteln(c.config, "stack trace: (most recent call last)")
stackTraceAux(c, tos, pc) stackTraceAux(c, tos, pc)
# XXX test if we want 'globalError' for every mode # XXX test if we want 'globalError' for every mode
let lineInfo = if n == nil: c.debug[pc] else: n.info let lineInfo = if n == nil: c.debug[pc] else: n.info
@ -402,7 +402,7 @@ template handleJmpBack() {.dirty.} =
if allowInfiniteLoops in c.features: if allowInfiniteLoops in c.features:
c.loopIterations = MaxLoopIterations c.loopIterations = MaxLoopIterations
else: else:
msgWriteln("stack trace: (most recent call last)") msgWriteln(c.config, "stack trace: (most recent call last)")
stackTraceAux(c, tos, pc) stackTraceAux(c, tos, pc)
globalError(c.config, c.debug[pc], errTooManyIterations) globalError(c.config, c.debug[pc], errTooManyIterations)
dec(c.loopIterations) dec(c.loopIterations)
@ -907,13 +907,13 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
of opcEcho: of opcEcho:
let rb = instr.regB let rb = instr.regB
if rb == 1: if rb == 1:
msgWriteln(regs[ra].node.strVal, {msgStdout}) msgWriteln(c.config, regs[ra].node.strVal, {msgStdout})
else: else:
var outp = "" var outp = ""
for i in ra..ra+rb-1: for i in ra..ra+rb-1:
#if regs[i].kind != rkNode: debug regs[i] #if regs[i].kind != rkNode: debug regs[i]
outp.add(regs[i].node.strVal) outp.add(regs[i].node.strVal)
msgWriteln(outp, {msgStdout}) msgWriteln(c.config, outp, {msgStdout})
of opcContainsSet: of opcContainsSet:
decodeBC(rkInt) decodeBC(rkInt)
regs[ra].intVal = ord(inSet(regs[rb].node, regs[rc].regToNode)) regs[ra].intVal = ord(inSet(regs[rb].node, regs[rc].regToNode))
@ -1355,11 +1355,11 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
c.debug[pc].toFullPath, c.debug[pc].line.int, c.debug[pc].toFullPath, c.debug[pc].line.int,
proc (conf: ConfigRef; info: TLineInfo; msg: TMsgKind; arg: string) = proc (conf: ConfigRef; info: TLineInfo; msg: TMsgKind; arg: string) =
if error.isNil and msg <= errMax: if error.isNil and msg <= errMax:
error = formatMsg(info, msg, arg)) error = formatMsg(conf, info, msg, arg))
if not error.isNil: if not error.isNil:
c.errorFlag = error c.errorFlag = error
elif sonsLen(ast) != 1: elif sonsLen(ast) != 1:
c.errorFlag = formatMsg(c.debug[pc], errGenerated, c.errorFlag = formatMsg(c.config, c.debug[pc], errGenerated,
"expected expression, but got multiple statements") "expected expression, but got multiple statements")
else: else:
regs[ra].node = ast.sons[0] regs[ra].node = ast.sons[0]
@ -1370,7 +1370,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
c.debug[pc].toFullPath, c.debug[pc].line.int, c.debug[pc].toFullPath, c.debug[pc].line.int,
proc (conf: ConfigRef; info: TLineInfo; msg: TMsgKind; arg: string) = proc (conf: ConfigRef; info: TLineInfo; msg: TMsgKind; arg: string) =
if error.isNil and msg <= errMax: if error.isNil and msg <= errMax:
error = formatMsg(info, msg, arg)) error = formatMsg(conf, info, msg, arg))
if not error.isNil: if not error.isNil:
c.errorFlag = error c.errorFlag = error
else: else: