distinguish between 'defined' and 'declared'
This commit is contained in:
parent
b1c8461a3b
commit
dd806cafa0
36 changed files with 155 additions and 96 deletions
|
|
@ -219,7 +219,7 @@ when not defined(JS):
|
|||
|
||||
proc randomize(seed: int) =
|
||||
srand(cint(seed))
|
||||
when defined(srand48): srand48(seed)
|
||||
when declared(srand48): srand48(seed)
|
||||
proc random(max: int): int =
|
||||
result = int(rand()) mod max
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ const
|
|||
withThreads = compileOption("threads")
|
||||
tickCountCorrection = 50_000
|
||||
|
||||
when not defined(system.TStackTrace):
|
||||
when not declared(system.TStackTrace):
|
||||
type TStackTrace = array [0..20, cstring]
|
||||
|
||||
# We use a simple hash table of bounded size to keep track of the stack traces:
|
||||
|
|
@ -146,7 +146,7 @@ proc `//`(a, b: int): string =
|
|||
result = format("$1/$2 = $3%", a, b, formatFloat(a / b * 100.0, ffDefault, 2))
|
||||
|
||||
proc writeProfile() {.noconv.} =
|
||||
when defined(system.TStackTrace):
|
||||
when declared(system.TStackTrace):
|
||||
system.profilerHook = nil
|
||||
const filename = "profile_results.txt"
|
||||
echo "writing " & filename & "..."
|
||||
|
|
@ -189,16 +189,16 @@ var
|
|||
disabled: int
|
||||
|
||||
proc disableProfiling*() =
|
||||
when defined(system.TStackTrace):
|
||||
when declared(system.TStackTrace):
|
||||
atomicDec disabled
|
||||
system.profilerHook = nil
|
||||
|
||||
proc enableProfiling*() =
|
||||
when defined(system.TStackTrace):
|
||||
when declared(system.TStackTrace):
|
||||
if atomicInc(disabled) >= 0:
|
||||
system.profilerHook = hook
|
||||
|
||||
when defined(system.TStackTrace):
|
||||
when declared(system.TStackTrace):
|
||||
system.profilerHook = hook
|
||||
addQuitProc(writeProfile)
|
||||
|
||||
|
|
|
|||
|
|
@ -997,7 +997,7 @@ proc moveFile*(source, dest: string) {.rtl, extern: "nos$1",
|
|||
if c_rename(source, dest) != 0'i32:
|
||||
raise newException(EOS, $strerror(errno))
|
||||
|
||||
when not defined(ENOENT) and not defined(Windows):
|
||||
when not declared(ENOENT) and not defined(Windows):
|
||||
when NoFakeVars:
|
||||
const ENOENT = cint(2) # 2 on most systems including Solaris
|
||||
else:
|
||||
|
|
@ -1615,11 +1615,11 @@ when defined(nimdoc):
|
|||
##
|
||||
## **Availability**: On Posix there is no portable way to get the command
|
||||
## line from a DLL and thus the proc isn't defined in this environment. You
|
||||
## can test for its availability with `defined() <system.html#defined>`_.
|
||||
## can test for its availability with `declared() <system.html#declared>`_.
|
||||
## Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## when defined(paramCount):
|
||||
## when declared(paramCount):
|
||||
## # Use paramCount() here
|
||||
## else:
|
||||
## # Do something else!
|
||||
|
|
@ -1638,11 +1638,11 @@ when defined(nimdoc):
|
|||
##
|
||||
## **Availability**: On Posix there is no portable way to get the command
|
||||
## line from a DLL and thus the proc isn't defined in this environment. You
|
||||
## can test for its availability with `defined() <system.html#defined>`_.
|
||||
## can test for its availability with `declared() <system.html#declared>`_.
|
||||
## Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## when defined(paramStr):
|
||||
## when declared(paramStr):
|
||||
## # Use paramStr() here
|
||||
## else:
|
||||
## # Do something else!
|
||||
|
|
@ -1682,7 +1682,7 @@ elif not defined(createNimRtl):
|
|||
# Docstring in nimdoc block.
|
||||
result = cmdCount-1
|
||||
|
||||
when defined(paramCount) or defined(nimdoc):
|
||||
when declared(paramCount) or defined(nimdoc):
|
||||
proc commandLineParams*(): seq[TaintedString] =
|
||||
## Convenience proc which returns the command line parameters.
|
||||
##
|
||||
|
|
@ -1691,11 +1691,11 @@ when defined(paramCount) or defined(nimdoc):
|
|||
##
|
||||
## **Availability**: On Posix there is no portable way to get the command
|
||||
## line from a DLL and thus the proc isn't defined in this environment. You
|
||||
## can test for its availability with `defined() <system.html#defined>`_.
|
||||
## can test for its availability with `declared() <system.html#declared>`_.
|
||||
## Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## when defined(commandLineParams):
|
||||
## when declared(commandLineParams):
|
||||
## # Use commandLineParams() here
|
||||
## else:
|
||||
## # Do something else!
|
||||
|
|
@ -1714,7 +1714,7 @@ when defined(linux) or defined(solaris) or defined(bsd) or defined(aix):
|
|||
|
||||
when not (defined(windows) or defined(macosx)):
|
||||
proc getApplHeuristic(): string =
|
||||
when defined(paramStr):
|
||||
when declared(paramStr):
|
||||
result = string(paramStr(0))
|
||||
# POSIX guaranties that this contains the executable
|
||||
# as it has been executed by the calling process
|
||||
|
|
|
|||
|
|
@ -643,7 +643,7 @@ elif not defined(useNimRtl):
|
|||
data.workingDir = workingDir
|
||||
|
||||
|
||||
when defined(posix_spawn) and not defined(useFork) and
|
||||
when declared(posix_spawn) and not defined(useFork) and
|
||||
not defined(useClone) and not defined(linux):
|
||||
pid = startProcessAuxSpawn(data)
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ type
|
|||
## or the argument, ``value`` is not "" if
|
||||
## the option was given a value
|
||||
|
||||
when defined(os.paramCount):
|
||||
when declared(os.paramCount):
|
||||
# we cannot provide this for NimRtl creation on Posix, because we can't
|
||||
# access the command line arguments then!
|
||||
|
||||
|
|
@ -127,7 +127,7 @@ proc cmdLineRest*(p: TOptParser): TaintedString {.
|
|||
## retrieves the rest of the command line that has not been parsed yet.
|
||||
result = strip(substr(p.cmd, p.pos, len(p.cmd) - 1)).TaintedString
|
||||
|
||||
when defined(initOptParser):
|
||||
when declared(initOptParser):
|
||||
|
||||
iterator getopt*(): tuple[kind: TCmdLineKind, key, val: TaintedString] =
|
||||
## This is an convenience iterator for iterating over the command line.
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ proc cmdLineRest*(p: TOptParser): TaintedString {.rtl, extern: "npo$1", deprecat
|
|||
type
|
||||
TGetoptResult* = tuple[kind: TCmdLineKind, key, val: TaintedString]
|
||||
|
||||
when defined(paramCount):
|
||||
when declared(paramCount):
|
||||
iterator getopt*(): TGetoptResult =
|
||||
## This is an convenience iterator for iterating over the command line.
|
||||
## This uses the TOptParser object. Example:
|
||||
|
|
|
|||
|
|
@ -870,7 +870,7 @@ template `=~`*(s: string, pattern: TPeg): bool =
|
|||
## echo("syntax error")
|
||||
##
|
||||
bind maxSubpatterns
|
||||
when not definedInScope(matches):
|
||||
when not declaredInScope(matches):
|
||||
var matches {.inject.}: array[0..MaxSubpatterns-1, string]
|
||||
match(s, pattern, matches)
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
import
|
||||
macros
|
||||
|
||||
when defined(stdout):
|
||||
when declared(stdout):
|
||||
import os
|
||||
|
||||
when not defined(ECMAScript):
|
||||
|
|
@ -99,7 +99,7 @@ template fail* =
|
|||
when not defined(ECMAScript):
|
||||
if AbortOnError: quit(1)
|
||||
|
||||
when defined(TestStatusIMPL):
|
||||
when declared(TestStatusIMPL):
|
||||
TestStatusIMPL = FAILED
|
||||
else:
|
||||
program_result += 1
|
||||
|
|
@ -188,7 +188,7 @@ macro expect*(exceptions: varargs[expr], body: stmt): stmt {.immediate.} =
|
|||
result = getAst(expectBody(errorTypes, exp.lineinfo, body))
|
||||
|
||||
|
||||
when defined(stdout):
|
||||
when declared(stdout):
|
||||
## Reading settings
|
||||
var envOutLvl = os.getEnv("NIMTEST_OUTPUT_LVL").string
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue