diff options
author | Araq <rumpf_a@web.de> | 2014-08-11 20:38:28 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-08-11 20:38:28 +0200 |
commit | dd806cafa0193acb9e79fdd47ec6810da3c48272 (patch) | |
tree | b42f7aacdd844e9402a3308e363f71e14db8b78a /compiler | |
parent | b1c8461a3b738cb4383b2e23ba24f36960a8604c (diff) | |
download | Nim-dd806cafa0193acb9e79fdd47ec6810da3c48272.tar.gz |
distinguish between 'defined' and 'declared'
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/commands.nim | 3 | ||||
-rw-r--r-- | compiler/condsyms.nim | 46 | ||||
-rw-r--r-- | compiler/llstream.nim | 2 | ||||
-rw-r--r-- | compiler/nimrod.nim | 2 | ||||
-rw-r--r-- | compiler/semexprs.nim | 14 | ||||
-rw-r--r-- | compiler/testability.nim | 2 | ||||
-rw-r--r-- | compiler/vm.nim | 4 |
7 files changed, 63 insertions, 10 deletions
diff --git a/compiler/commands.nim b/compiler/commands.nim index 7219c168a..c15cc674c 100644 --- a/compiler/commands.nim +++ b/compiler/commands.nim @@ -315,6 +315,9 @@ proc processSwitch(switch, arg: string, pass: TCmdLinePass, info: TLineInfo) = of "undef", "u": expectArg(switch, arg, pass, info) undefSymbol(arg) + of "symbol": + expectArg(switch, arg, pass, info) + declareSymbol(arg) of "compile": expectArg(switch, arg, pass, info) if pass in {passCmd2, passPP}: processCompile(arg) diff --git a/compiler/condsyms.nim b/compiler/condsyms.nim index 76026a59d..5eb951e26 100644 --- a/compiler/condsyms.nim +++ b/compiler/condsyms.nim @@ -19,6 +19,9 @@ var gSymbols: PStringTable proc defineSymbol*(symbol: string) = gSymbols[symbol] = "true" +proc declareSymbol*(symbol: string) = + gSymbols[symbol] = "unknown" + proc undefSymbol*(symbol: string) = gSymbols[symbol] = "false" @@ -27,6 +30,7 @@ proc isDefined*(symbol: string): bool = result = gSymbols[symbol] == "true" proc isDefined*(symbol: PIdent): bool = isDefined(symbol.s) +proc isDeclared*(symbol: PIdent): bool = gSymbols.hasKey(symbol.s) iterator definedSymbolNames*: string = for key, val in pairs(gSymbols): @@ -37,6 +41,36 @@ proc countDefinedSymbols*(): int = for key, val in pairs(gSymbols): if val == "true": inc(result) +# For ease of bootstrapping, we keep there here and not in the global config +# file for now: +const + additionalSymbols = """ + x86 itanium x8664 + msdos mswindows win32 unix posix sunos bsd macintosh RISCOS doslike hpux + mac + + hppa hp9000 hp9000s300 hp9000s700 hp9000s800 hp9000s820 ELATE sparcv9 + + ecmascript js nimrodvm nimffi nimdoc cpp objc + gcc llvmgcc clang lcc bcc dmc wcc vcc tcc pcc ucc icl + boehmgc gcmarkandsweep gcgenerational nogc gcUseBitvectors + endb profiler + executable guiapp consoleapp library dll staticlib + + quick nimbabel + release debug + useWinAnsi useFork useNimRtl useMalloc useRealtimeGC ssl memProfiler + nodejs kwin + + usesysassert usegcassert tinyC useFFI + useStdoutAsStdmsg createNimRtl + booting fulldebug corruption nimsuperops noSignalHandler useGnuReadline + noCaas noDocGen noBusyWaiting nativeStackTrace useNodeIds selftest + reportMissedDeadlines avoidTimeMachine useClone ignoreAllocationSize + debugExecProcesses pcreDll useLipzipSrc + preventDeadlocks UNICODE winUnicode trackGcHeaders posixRealtime + """.split + proc initDefines*() = gSymbols = newStringTable(modeStyleInsensitive) defineSymbol("nimrod") # 'nimrod' is always defined @@ -53,6 +87,17 @@ proc initDefines*() = defineSymbol("nimparsebiggestfloatmagic") # add platform specific symbols: + for c in low(CPU)..high(CPU): + declareSymbol("cpu" & $CPU[c].bit) + declareSymbol(normalize(EndianToStr[CPU[c].endian])) + declareSymbol(CPU[c].name) + for o in low(platform.OS)..high(platform.OS): + declareSymbol(platform.OS[o].name) + + for a in additionalSymbols: + declareSymbol(a) + + # ----------------------------------------------------------- case targetCPU of cpuI386: defineSymbol("x86") of cpuIa64: defineSymbol("itanium") @@ -88,5 +133,6 @@ proc initDefines*() = defineSymbol(normalize(EndianToStr[CPU[targetCPU].endian])) defineSymbol(CPU[targetCPU].name) defineSymbol(platform.OS[targetOS].name) + declareSymbol("emulatedthreadvars") if platform.OS[targetOS].props.contains(ospLacksThreadVars): defineSymbol("emulatedthreadvars") diff --git a/compiler/llstream.nim b/compiler/llstream.nim index 86bfeaabd..5aefd468a 100644 --- a/compiler/llstream.nim +++ b/compiler/llstream.nim @@ -77,7 +77,7 @@ proc llStreamClose(s: PLLStream) = of llsFile: close(s.f) -when not defined(readLineFromStdin): +when not declared(readLineFromStdin): # fallback implementation: proc readLineFromStdin(prompt: string, line: var string): bool = stdout.write(prompt) diff --git a/compiler/nimrod.nim b/compiler/nimrod.nim index ea7621b09..618d98698 100644 --- a/compiler/nimrod.nim +++ b/compiler/nimrod.nim @@ -79,7 +79,7 @@ proc handleCmdLine() = var ex = quoteShell(binPath) execExternalProgram(ex & ' ' & service.arguments) -when defined(GC_setMaxPause): +when declared(GC_setMaxPause): GC_setMaxPause 2_000 when compileOption("gc", "v2") or compileOption("gc", "refc"): diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 7e97eb293..ad8554500 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -1393,10 +1393,16 @@ proc semDefined(c: PContext, n: PNode, onlyCurrentScope: bool): PNode = checkSonsLen(n, 2) # we replace this node by a 'true' or 'false' node: result = newIntNode(nkIntLit, 0) - if lookUpForDefined(c, n.sons[1], onlyCurrentScope) != nil: - result.intVal = 1 - elif not onlyCurrentScope and (n.sons[1].kind == nkIdent) and - condsyms.isDefined(n.sons[1].ident): + if not onlyCurrentScope and considerQuotedIdent(n[0]).s == "defined": + if n.sons[1].kind != nkIdent: + localError(n.info, "obsolete usage of 'defined', use 'declared' instead") + elif condsyms.isDefined(n.sons[1].ident): + result.intVal = 1 + elif not condsyms.isDeclared(n.sons[1].ident): + message(n.info, warnUser, + "undeclared conditional symbol; use --symbol to declare it: " & + n[1].ident.s) + elif lookUpForDefined(c, n.sons[1], onlyCurrentScope) != nil: result.intVal = 1 result.info = n.info result.typ = getSysType(tyBool) diff --git a/compiler/testability.nim b/compiler/testability.nim index ceefd0a5e..4587a5344 100644 --- a/compiler/testability.nim +++ b/compiler/testability.nim @@ -1,5 +1,5 @@ template tests*(body: stmt) {.immediate.} = when defined(selftest): - when not defined(unittest): import unittest + when not declared(unittest): import unittest body diff --git a/compiler/vm.nim b/compiler/vm.nim index aedbb92b4..a06d10f81 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -87,9 +87,7 @@ proc bailOut(c: PCtx; tos: PStackFrame) = when not defined(nimComputedGoto): {.pragma: computedGoto.} -proc myreset(n: var TFullReg) = - when defined(system.reset): - reset(n) +proc myreset(n: var TFullReg) = reset(n) template ensureKind(k: expr) {.immediate, dirty.} = if regs[ra].kind != k: |