Merge branch 'devel' into range_float_type
This commit is contained in:
commit
e2a4a43acc
15 changed files with 145 additions and 78 deletions
|
|
@ -1622,7 +1622,7 @@ iterator items*(n: PNode): PNode =
|
||||||
for i in 0..<n.safeLen: yield n.sons[i]
|
for i in 0..<n.safeLen: yield n.sons[i]
|
||||||
|
|
||||||
iterator pairs*(n: PNode): tuple[i: int, n: PNode] =
|
iterator pairs*(n: PNode): tuple[i: int, n: PNode] =
|
||||||
for i in 0..<n.len: yield (i, n.sons[i])
|
for i in 0..<n.safeLen: yield (i, n.sons[i])
|
||||||
|
|
||||||
proc isAtom*(n: PNode): bool {.inline.} =
|
proc isAtom*(n: PNode): bool {.inline.} =
|
||||||
result = n.kind >= nkNone and n.kind <= nkNilLit
|
result = n.kind >= nkNone and n.kind <= nkNilLit
|
||||||
|
|
|
||||||
|
|
@ -652,6 +652,7 @@ proc processSwitch(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
|
||||||
of "genscript", "gendeps":
|
of "genscript", "gendeps":
|
||||||
expectNoArg(switch, arg, pass, info)
|
expectNoArg(switch, arg, pass, info)
|
||||||
incl(gGlobalOptions, optGenScript)
|
incl(gGlobalOptions, optGenScript)
|
||||||
|
incl(gGlobalOptions, optCompileOnly)
|
||||||
of "colors": processOnOffSwitchG({optUseColors}, arg, pass, info)
|
of "colors": processOnOffSwitchG({optUseColors}, arg, pass, info)
|
||||||
of "lib":
|
of "lib":
|
||||||
expectArg(switch, arg, pass, info)
|
expectArg(switch, arg, pass, info)
|
||||||
|
|
|
||||||
|
|
@ -470,8 +470,9 @@ proc execExternalProgram*(cmd: string, msg = hintExecuting) =
|
||||||
|
|
||||||
proc generateScript(projectFile: string, script: Rope) =
|
proc generateScript(projectFile: string, script: Rope) =
|
||||||
let (dir, name, ext) = splitFile(projectFile)
|
let (dir, name, ext) = splitFile(projectFile)
|
||||||
writeRope(script, dir / addFileExt("compile_" & name,
|
writeRope(script, getNimcacheDir() / addFileExt("compile_" & name,
|
||||||
platform.OS[targetOS].scriptExt))
|
platform.OS[targetOS].scriptExt))
|
||||||
|
copyFile(libpath / "nimbase.h", getNimcacheDir() / "nimbase.h")
|
||||||
|
|
||||||
proc getOptSpeed(c: TSystemCC): string =
|
proc getOptSpeed(c: TSystemCC): string =
|
||||||
result = getConfigVar(c, ".options.speed")
|
result = getConfigVar(c, ".options.speed")
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,8 @@ Advanced options:
|
||||||
--noLinking compile Nim and generated files but do not link
|
--noLinking compile Nim and generated files but do not link
|
||||||
--noMain do not generate a main procedure
|
--noMain do not generate a main procedure
|
||||||
--genScript generate a compile script (in the 'nimcache'
|
--genScript generate a compile script (in the 'nimcache'
|
||||||
subdirectory named 'compile_$$project$$scriptext')
|
subdirectory named 'compile_$$project$$scriptext'),
|
||||||
|
implies --compileOnly
|
||||||
--genDeps generate a '.deps' file containing the dependencies
|
--genDeps generate a '.deps' file containing the dependencies
|
||||||
--os:SYMBOL set the target operating system (cross-compilation)
|
--os:SYMBOL set the target operating system (cross-compilation)
|
||||||
--cpu:SYMBOL set the target processor (cross-compilation)
|
--cpu:SYMBOL set the target processor (cross-compilation)
|
||||||
|
|
|
||||||
|
|
@ -102,32 +102,33 @@ proc feupdateenv*(envp: ptr Tfenv): cint {.importc, header: "<fenv.h>".}
|
||||||
## represented by object pointed to by `envp` and raise exceptions
|
## represented by object pointed to by `envp` and raise exceptions
|
||||||
## according to saved exceptions.
|
## according to saved exceptions.
|
||||||
|
|
||||||
var FP_RADIX_INTERNAL {. importc: "FLT_RADIX" header: "<float.h>" .} : int
|
const
|
||||||
|
FLT_RADIX = 2 ## the radix of the exponent representation
|
||||||
|
|
||||||
template fpRadix* : int = FP_RADIX_INTERNAL
|
FLT_MANT_DIG = 24 ## the number of base FLT_RADIX digits in the mantissa part of a float
|
||||||
|
FLT_DIG = 6 ## the number of digits of precision of a float
|
||||||
|
FLT_MIN_EXP = -125 # the minimum value of base FLT_RADIX in the exponent part of a float
|
||||||
|
FLT_MAX_EXP = 128 # the maximum value of base FLT_RADIX in the exponent part of a float
|
||||||
|
FLT_MIN_10_EXP = -37 ## the minimum value in base 10 of the exponent part of a float
|
||||||
|
FLT_MAX_10_EXP = 38 ## the maximum value in base 10 of the exponent part of a float
|
||||||
|
FLT_MIN = 1.17549435e-38'f32 ## the minimum value of a float
|
||||||
|
FLT_MAX = 3.40282347e+38'f32 ## the maximum value of a float
|
||||||
|
FLT_EPSILON = 1.19209290e-07'f32 ## the difference between 1 and the least value greater than 1 of a float
|
||||||
|
|
||||||
|
DBL_MANT_DIG = 53 ## the number of base FLT_RADIX digits in the mantissa part of a double
|
||||||
|
DBL_DIG = 15 ## the number of digits of precision of a double
|
||||||
|
DBL_MIN_EXP = -1021 ## the minimum value of base FLT_RADIX in the exponent part of a double
|
||||||
|
DBL_MAX_EXP = 1024 ## the maximum value of base FLT_RADIX in the exponent part of a double
|
||||||
|
DBL_MIN_10_EXP = -307 ## the minimum value in base 10 of the exponent part of a double
|
||||||
|
DBL_MAX_10_EXP = 308 ## the maximum value in base 10 of the exponent part of a double
|
||||||
|
DBL_MIN = 2.2250738585072014E-308 ## the minimal value of a double
|
||||||
|
DBL_MAX = 1.7976931348623157E+308 ## the minimal value of a double
|
||||||
|
DBL_EPSILON = 2.2204460492503131E-16 ## the difference between 1 and the least value greater than 1 of a double
|
||||||
|
|
||||||
|
template fpRadix* : int = FLT_RADIX
|
||||||
## The (integer) value of the radix used to represent any floating
|
## The (integer) value of the radix used to represent any floating
|
||||||
## point type on the architecture used to build the program.
|
## point type on the architecture used to build the program.
|
||||||
|
|
||||||
var FLT_MANT_DIG {. importc: "FLT_MANT_DIG" header: "<float.h>" .} : int
|
|
||||||
var FLT_DIG {. importc: "FLT_DIG" header: "<float.h>" .} : int
|
|
||||||
var FLT_MIN_EXP {. importc: "FLT_MIN_EXP" header: "<float.h>" .} : int
|
|
||||||
var FLT_MAX_EXP {. importc: "FLT_MAX_EXP" header: "<float.h>" .} : int
|
|
||||||
var FLT_MIN_10_EXP {. importc: "FLT_MIN_10_EXP" header: "<float.h>" .} : int
|
|
||||||
var FLT_MAX_10_EXP {. importc: "FLT_MAX_10_EXP" header: "<float.h>" .} : int
|
|
||||||
var FLT_MIN {. importc: "FLT_MIN" header: "<float.h>" .} : cfloat
|
|
||||||
var FLT_MAX {. importc: "FLT_MAX" header: "<float.h>" .} : cfloat
|
|
||||||
var FLT_EPSILON {. importc: "FLT_EPSILON" header: "<float.h>" .} : cfloat
|
|
||||||
|
|
||||||
var DBL_MANT_DIG {. importc: "DBL_MANT_DIG" header: "<float.h>" .} : int
|
|
||||||
var DBL_DIG {. importc: "DBL_DIG" header: "<float.h>" .} : int
|
|
||||||
var DBL_MIN_EXP {. importc: "DBL_MIN_EXP" header: "<float.h>" .} : int
|
|
||||||
var DBL_MAX_EXP {. importc: "DBL_MAX_EXP" header: "<float.h>" .} : int
|
|
||||||
var DBL_MIN_10_EXP {. importc: "DBL_MIN_10_EXP" header: "<float.h>" .} : int
|
|
||||||
var DBL_MAX_10_EXP {. importc: "DBL_MAX_10_EXP" header: "<float.h>" .} : int
|
|
||||||
var DBL_MIN {. importc: "DBL_MIN" header: "<float.h>" .} : cdouble
|
|
||||||
var DBL_MAX {. importc: "DBL_MAX" header: "<float.h>" .} : cdouble
|
|
||||||
var DBL_EPSILON {. importc: "DBL_EPSILON" header: "<float.h>" .} : cdouble
|
|
||||||
|
|
||||||
template mantissaDigits*(T : typedesc[float32]) : int = FLT_MANT_DIG
|
template mantissaDigits*(T : typedesc[float32]) : int = FLT_MANT_DIG
|
||||||
## Number of digits (in base ``floatingPointRadix``) in the mantissa
|
## Number of digits (in base ``floatingPointRadix``) in the mantissa
|
||||||
## of 32-bit floating-point numbers.
|
## of 32-bit floating-point numbers.
|
||||||
|
|
@ -179,3 +180,11 @@ template maximumPositiveValue*(T : typedesc[float64]) : float64 = DBL_MAX
|
||||||
template epsilon*(T : typedesc[float64]): float64 = DBL_EPSILON
|
template epsilon*(T : typedesc[float64]): float64 = DBL_EPSILON
|
||||||
## The difference between 1.0 and the smallest number greater than
|
## The difference between 1.0 and the smallest number greater than
|
||||||
## 1.0 that can be represented in a 64-bit floating-point type.
|
## 1.0 that can be represented in a 64-bit floating-point type.
|
||||||
|
|
||||||
|
|
||||||
|
when isMainModule:
|
||||||
|
func is_significant(x: float): bool =
|
||||||
|
if x > minimumPositiveValue(float) and x < maximumPositiveValue(float): true
|
||||||
|
else: false
|
||||||
|
|
||||||
|
doAssert is_significant(10.0)
|
||||||
|
|
|
||||||
|
|
@ -73,13 +73,19 @@
|
||||||
## progress of the HTTP request.
|
## progress of the HTTP request.
|
||||||
##
|
##
|
||||||
## .. code-block:: Nim
|
## .. code-block:: Nim
|
||||||
## var client = newAsyncHttpClient()
|
## import asyncdispatch, httpclient
|
||||||
|
##
|
||||||
## proc onProgressChanged(total, progress, speed: BiggestInt) {.async.} =
|
## proc onProgressChanged(total, progress, speed: BiggestInt) {.async.} =
|
||||||
## echo("Downloaded ", progress, " of ", total)
|
## echo("Downloaded ", progress, " of ", total)
|
||||||
## echo("Current rate: ", speed div 1000, "kb/s")
|
## echo("Current rate: ", speed div 1000, "kb/s")
|
||||||
|
##
|
||||||
|
## proc asyncProc() {.async.} =
|
||||||
|
## var client = newAsyncHttpClient()
|
||||||
## client.onProgressChanged = onProgressChanged
|
## client.onProgressChanged = onProgressChanged
|
||||||
## discard await client.getContent("http://speedtest-ams2.digitalocean.com/100mb.test")
|
## discard await client.getContent("http://speedtest-ams2.digitalocean.com/100mb.test")
|
||||||
##
|
##
|
||||||
|
## waitFor asyncProc()
|
||||||
|
##
|
||||||
## If you would like to remove the callback simply set it to ``nil``.
|
## If you would like to remove the callback simply set it to ``nil``.
|
||||||
##
|
##
|
||||||
## .. code-block:: Nim
|
## .. code-block:: Nim
|
||||||
|
|
@ -739,10 +745,11 @@ proc downloadFile*(url: string, outputFilename: string,
|
||||||
proc generateHeaders(requestUrl: Uri, httpMethod: string,
|
proc generateHeaders(requestUrl: Uri, httpMethod: string,
|
||||||
headers: HttpHeaders, body: string, proxy: Proxy): string =
|
headers: HttpHeaders, body: string, proxy: Proxy): string =
|
||||||
# GET
|
# GET
|
||||||
result = httpMethod.toUpperAscii()
|
let upperMethod = httpMethod.toUpperAscii()
|
||||||
|
result = upperMethod
|
||||||
result.add ' '
|
result.add ' '
|
||||||
|
|
||||||
if proxy.isNil or (not proxy.isNil and requestUrl.scheme == "https"):
|
if proxy.isNil or requestUrl.scheme == "https":
|
||||||
# /path?query
|
# /path?query
|
||||||
if requestUrl.path[0] != '/': result.add '/'
|
if requestUrl.path[0] != '/': result.add '/'
|
||||||
result.add(requestUrl.path)
|
result.add(requestUrl.path)
|
||||||
|
|
@ -768,7 +775,9 @@ proc generateHeaders(requestUrl: Uri, httpMethod: string,
|
||||||
add(result, "Connection: Keep-Alive\c\L")
|
add(result, "Connection: Keep-Alive\c\L")
|
||||||
|
|
||||||
# Content length header.
|
# Content length header.
|
||||||
if body.len > 0 and not headers.hasKey("Content-Length"):
|
const requiresBody = ["POST", "PUT", "PATCH"]
|
||||||
|
let needsContentLength = body.len > 0 or upperMethod in requiresBody
|
||||||
|
if needsContentLength and not headers.hasKey("Content-Length"):
|
||||||
add(result, "Content-Length: " & $body.len & "\c\L")
|
add(result, "Content-Length: " & $body.len & "\c\L")
|
||||||
|
|
||||||
# Proxy auth header.
|
# Proxy auth header.
|
||||||
|
|
|
||||||
|
|
@ -696,7 +696,7 @@ proc getBiggestInt*(n: JsonNode, default: BiggestInt = 0): BiggestInt =
|
||||||
else: return n.num
|
else: return n.num
|
||||||
|
|
||||||
proc getNum*(n: JsonNode, default: BiggestInt = 0): BiggestInt {.deprecated.} =
|
proc getNum*(n: JsonNode, default: BiggestInt = 0): BiggestInt {.deprecated.} =
|
||||||
## Deprecated - use getInt or getBiggestInt instead
|
## **Deprecated since v0.18.2:** use ``getInt`` or ``getBiggestInt`` instead.
|
||||||
getBiggestInt(n, default)
|
getBiggestInt(n, default)
|
||||||
|
|
||||||
proc getFloat*(n: JsonNode, default: float = 0.0): float =
|
proc getFloat*(n: JsonNode, default: float = 0.0): float =
|
||||||
|
|
@ -710,7 +710,7 @@ proc getFloat*(n: JsonNode, default: float = 0.0): float =
|
||||||
else: return default
|
else: return default
|
||||||
|
|
||||||
proc getFNum*(n: JsonNode, default: float = 0.0): float {.deprecated.} =
|
proc getFNum*(n: JsonNode, default: float = 0.0): float {.deprecated.} =
|
||||||
## Deprecated - use getFloat instead
|
## **Deprecated since v0.18.2:** use ``getFloat`` instead.
|
||||||
getFloat(n, default)
|
getFloat(n, default)
|
||||||
|
|
||||||
proc getBool*(n: JsonNode, default: bool = false): bool =
|
proc getBool*(n: JsonNode, default: bool = false): bool =
|
||||||
|
|
@ -721,7 +721,7 @@ proc getBool*(n: JsonNode, default: bool = false): bool =
|
||||||
else: return n.bval
|
else: return n.bval
|
||||||
|
|
||||||
proc getBVal*(n: JsonNode, default: bool = false): bool {.deprecated.} =
|
proc getBVal*(n: JsonNode, default: bool = false): bool {.deprecated.} =
|
||||||
## Deprecated - use getBVal instead
|
## **Deprecated since v0.18.2:** use ``getBool`` instead.
|
||||||
getBool(n, default)
|
getBool(n, default)
|
||||||
|
|
||||||
proc getFields*(n: JsonNode,
|
proc getFields*(n: JsonNode,
|
||||||
|
|
@ -947,7 +947,7 @@ proc contains*(node: JsonNode, val: JsonNode): bool =
|
||||||
find(node.elems, val) >= 0
|
find(node.elems, val) >= 0
|
||||||
|
|
||||||
proc existsKey*(node: JsonNode, key: string): bool {.deprecated.} = node.hasKey(key)
|
proc existsKey*(node: JsonNode, key: string): bool {.deprecated.} = node.hasKey(key)
|
||||||
## Deprecated for `hasKey`
|
## **Deprecated:** use `hasKey` instead.
|
||||||
|
|
||||||
proc `[]=`*(obj: JsonNode, key: string, val: JsonNode) {.inline.} =
|
proc `[]=`*(obj: JsonNode, key: string, val: JsonNode) {.inline.} =
|
||||||
## Sets a field from a `JObject`.
|
## Sets a field from a `JObject`.
|
||||||
|
|
|
||||||
|
|
@ -192,7 +192,7 @@ when not defined(nimscript):
|
||||||
## Initializes the random number generator with a "random"
|
## Initializes the random number generator with a "random"
|
||||||
## number, i.e. a tickcount. Note: Does not work for NimScript.
|
## number, i.e. a tickcount. Note: Does not work for NimScript.
|
||||||
let now = times.getTime()
|
let now = times.getTime()
|
||||||
randomize(convert(Seconds, Nanoseconds, now.toUnix) + now.nanoseconds)
|
randomize(convert(Seconds, Nanoseconds, now.toUnix) + now.nanosecond)
|
||||||
|
|
||||||
{.pop.}
|
{.pop.}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ type
|
||||||
|
|
||||||
Time* = object ## Represents a point in time.
|
Time* = object ## Represents a point in time.
|
||||||
seconds: int64
|
seconds: int64
|
||||||
nanoseconds: NanosecondRange
|
nanosecond: NanosecondRange
|
||||||
|
|
||||||
DateTime* = object of RootObj ## Represents a time in different parts.
|
DateTime* = object of RootObj ## Represents a time in different parts.
|
||||||
## Although this type can represent leap
|
## Although this type can represent leap
|
||||||
|
|
@ -159,7 +159,7 @@ type
|
||||||
## This type should be prefered over ``TimeInterval`` unless
|
## This type should be prefered over ``TimeInterval`` unless
|
||||||
## non-static time units is needed.
|
## non-static time units is needed.
|
||||||
seconds: int64
|
seconds: int64
|
||||||
nanoseconds: NanosecondRange
|
nanosecond: NanosecondRange
|
||||||
|
|
||||||
TimeUnit* = enum ## Different units of time.
|
TimeUnit* = enum ## Different units of time.
|
||||||
Nanoseconds, Microseconds, Milliseconds, Seconds, Minutes, Hours, Days, Weeks, Months, Years
|
Nanoseconds, Microseconds, Milliseconds, Seconds, Minutes, Hours, Days, Weeks, Months, Years
|
||||||
|
|
@ -223,21 +223,21 @@ proc normalize[T: Duration|Time](seconds, nanoseconds: int64): T =
|
||||||
## a ``Duration`` or ``Time``. A normalized ``Duration|Time`` has a
|
## a ``Duration`` or ``Time``. A normalized ``Duration|Time`` has a
|
||||||
## positive nanosecond part in the range ``NanosecondRange``.
|
## positive nanosecond part in the range ``NanosecondRange``.
|
||||||
result.seconds = seconds + convert(Nanoseconds, Seconds, nanoseconds)
|
result.seconds = seconds + convert(Nanoseconds, Seconds, nanoseconds)
|
||||||
var nanoseconds = nanoseconds mod convert(Seconds, Nanoseconds, 1)
|
var nanosecond = nanoseconds mod convert(Seconds, Nanoseconds, 1)
|
||||||
if nanoseconds < 0:
|
if nanosecond < 0:
|
||||||
nanoseconds += convert(Seconds, Nanoseconds, 1)
|
nanosecond += convert(Seconds, Nanoseconds, 1)
|
||||||
result.seconds -= 1
|
result.seconds -= 1
|
||||||
result.nanoseconds = nanoseconds.int
|
result.nanosecond = nanosecond.int
|
||||||
|
|
||||||
proc initTime*(unix: int64, nanoseconds: NanosecondRange): Time =
|
proc initTime*(unix: int64, nanosecond: NanosecondRange): Time =
|
||||||
## Create a ``Time`` from a unix timestamp and a nanosecond part.
|
## Create a ``Time`` from a unix timestamp and a nanosecond part.
|
||||||
result.seconds = unix
|
result.seconds = unix
|
||||||
result.nanoseconds = nanoseconds
|
result.nanosecond = nanosecond
|
||||||
|
|
||||||
proc nanoseconds*(time: Time): NanosecondRange =
|
proc nanosecond*(time: Time): NanosecondRange =
|
||||||
## Get the fractional part of a ``Time`` as the number
|
## Get the fractional part of a ``Time`` as the number
|
||||||
## of nanoseconds of the second.
|
## of nanoseconds of the second.
|
||||||
time.nanoseconds
|
time.nanosecond
|
||||||
|
|
||||||
proc initDuration*(nanoseconds, microseconds, milliseconds,
|
proc initDuration*(nanoseconds, microseconds, milliseconds,
|
||||||
seconds, minutes, hours, days, weeks: int64 = 0): Duration =
|
seconds, minutes, hours, days, weeks: int64 = 0): Duration =
|
||||||
|
|
@ -281,7 +281,7 @@ proc milliseconds*(dur: Duration): int {.inline.} =
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
let dur = initDuration(seconds = 1, milliseconds = 1)
|
let dur = initDuration(seconds = 1, milliseconds = 1)
|
||||||
doAssert dur.milliseconds == 1
|
doAssert dur.milliseconds == 1
|
||||||
convert(Nanoseconds, Milliseconds, dur.nanoseconds)
|
convert(Nanoseconds, Milliseconds, dur.nanosecond)
|
||||||
|
|
||||||
proc microseconds*(dur: Duration): int {.inline.} =
|
proc microseconds*(dur: Duration): int {.inline.} =
|
||||||
## Number of whole microseconds represented by the **fractional**
|
## Number of whole microseconds represented by the **fractional**
|
||||||
|
|
@ -289,7 +289,7 @@ proc microseconds*(dur: Duration): int {.inline.} =
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
let dur = initDuration(seconds = 1, microseconds = 1)
|
let dur = initDuration(seconds = 1, microseconds = 1)
|
||||||
doAssert dur.microseconds == 1
|
doAssert dur.microseconds == 1
|
||||||
convert(Nanoseconds, Microseconds, dur.nanoseconds)
|
convert(Nanoseconds, Microseconds, dur.nanosecond)
|
||||||
|
|
||||||
proc nanoseconds*(dur: Duration): int {.inline.} =
|
proc nanoseconds*(dur: Duration): int {.inline.} =
|
||||||
## Number of whole nanoseconds represented by the **fractional**
|
## Number of whole nanoseconds represented by the **fractional**
|
||||||
|
|
@ -297,14 +297,14 @@ proc nanoseconds*(dur: Duration): int {.inline.} =
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
let dur = initDuration(seconds = 1, nanoseconds = 1)
|
let dur = initDuration(seconds = 1, nanoseconds = 1)
|
||||||
doAssert dur.nanoseconds == 1
|
doAssert dur.nanoseconds == 1
|
||||||
dur.nanoseconds
|
dur.nanosecond
|
||||||
|
|
||||||
proc fractional*(dur: Duration): Duration {.inline.} =
|
proc fractional*(dur: Duration): Duration {.inline.} =
|
||||||
## The fractional part of duration, as a duration.
|
## The fractional part of duration, as a duration.
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
let dur = initDuration(seconds = 1, nanoseconds = 5)
|
let dur = initDuration(seconds = 1, nanoseconds = 5)
|
||||||
doAssert dur.fractional == initDuration(nanoseconds = 5)
|
doAssert dur.fractional == initDuration(nanoseconds = 5)
|
||||||
initDuration(nanoseconds = dur.nanoseconds)
|
initDuration(nanoseconds = dur.nanosecond)
|
||||||
|
|
||||||
const DurationZero* = initDuration() ## Zero value for durations. Useful for comparisons.
|
const DurationZero* = initDuration() ## Zero value for durations. Useful for comparisons.
|
||||||
##
|
##
|
||||||
|
|
@ -322,7 +322,7 @@ proc `$`*(dur: Duration): string =
|
||||||
doAssert $initDuration(milliseconds = -1500) == "-1 second and -500 milliseconds"
|
doAssert $initDuration(milliseconds = -1500) == "-1 second and -500 milliseconds"
|
||||||
var parts = newSeq[string]()
|
var parts = newSeq[string]()
|
||||||
var remS = dur.seconds
|
var remS = dur.seconds
|
||||||
var remNs = dur.nanoseconds.int
|
var remNs = dur.nanosecond.int
|
||||||
|
|
||||||
# Normally ``nanoseconds`` should always be positive, but
|
# Normally ``nanoseconds`` should always be positive, but
|
||||||
# that makes no sense when printing.
|
# that makes no sense when printing.
|
||||||
|
|
@ -387,7 +387,7 @@ proc fromWinTime*(win: int64): Time =
|
||||||
|
|
||||||
proc toWinTime*(t: Time): int64 =
|
proc toWinTime*(t: Time): int64 =
|
||||||
## Convert ``t`` to a Windows file time (100-nanosecond intervals since ``1601-01-01T00:00:00Z``).
|
## Convert ``t`` to a Windows file time (100-nanosecond intervals since ``1601-01-01T00:00:00Z``).
|
||||||
result = t.seconds * rateDiff + epochDiff + t.nanoseconds div 100
|
result = t.seconds * rateDiff + epochDiff + t.nanosecond div 100
|
||||||
|
|
||||||
proc isLeapYear*(year: int): bool =
|
proc isLeapYear*(year: int): bool =
|
||||||
## Returns true if ``year`` is a leap year.
|
## Returns true if ``year`` is a leap year.
|
||||||
|
|
@ -473,21 +473,21 @@ proc localZoneInfoFromTz(adjTime: Time): ZonedTime {.tags: [], raises: [], benig
|
||||||
{. pragma: operator, rtl, noSideEffect, benign .}
|
{. pragma: operator, rtl, noSideEffect, benign .}
|
||||||
|
|
||||||
template subImpl[T: Duration|Time](a: Duration|Time, b: Duration|Time): T =
|
template subImpl[T: Duration|Time](a: Duration|Time, b: Duration|Time): T =
|
||||||
normalize[T](a.seconds - b.seconds, a.nanoseconds - b.nanoseconds)
|
normalize[T](a.seconds - b.seconds, a.nanosecond - b.nanosecond)
|
||||||
|
|
||||||
template addImpl[T: Duration|Time](a: Duration|Time, b: Duration|Time): T =
|
template addImpl[T: Duration|Time](a: Duration|Time, b: Duration|Time): T =
|
||||||
normalize[T](a.seconds + b.seconds, a.nanoseconds + b.nanoseconds)
|
normalize[T](a.seconds + b.seconds, a.nanosecond + b.nanosecond)
|
||||||
|
|
||||||
template ltImpl(a: Duration|Time, b: Duration|Time): bool =
|
template ltImpl(a: Duration|Time, b: Duration|Time): bool =
|
||||||
a.seconds < b.seconds or (
|
a.seconds < b.seconds or (
|
||||||
a.seconds == b.seconds and a.nanoseconds < b.nanoseconds)
|
a.seconds == b.seconds and a.nanosecond < b.nanosecond)
|
||||||
|
|
||||||
template lqImpl(a: Duration|Time, b: Duration|Time): bool =
|
template lqImpl(a: Duration|Time, b: Duration|Time): bool =
|
||||||
a.seconds <= b.seconds or (
|
a.seconds < b.seconds or (
|
||||||
a.seconds == b.seconds and a.nanoseconds <= b.seconds)
|
a.seconds == b.seconds and a.nanosecond <= b.nanosecond)
|
||||||
|
|
||||||
template eqImpl(a: Duration|Time, b: Duration|Time): bool =
|
template eqImpl(a: Duration|Time, b: Duration|Time): bool =
|
||||||
a.seconds == b.seconds and a.nanoseconds == b.nanoseconds
|
a.seconds == b.seconds and a.nanosecond == b.nanosecond
|
||||||
|
|
||||||
proc `+`*(a, b: Duration): Duration {.operator.} =
|
proc `+`*(a, b: Duration): Duration {.operator.} =
|
||||||
## Add two durations together.
|
## Add two durations together.
|
||||||
|
|
@ -507,7 +507,7 @@ proc `-`*(a: Duration): Duration {.operator.} =
|
||||||
## Reverse a duration.
|
## Reverse a duration.
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
doAssert -initDuration(seconds = 1) == initDuration(seconds = -1)
|
doAssert -initDuration(seconds = 1) == initDuration(seconds = -1)
|
||||||
normalize[Duration](-a.seconds, -a.nanoseconds)
|
normalize[Duration](-a.seconds, -a.nanosecond)
|
||||||
|
|
||||||
proc `<`*(a, b: Duration): bool {.operator.} =
|
proc `<`*(a, b: Duration): bool {.operator.} =
|
||||||
## Note that a duration can be negative,
|
## Note that a duration can be negative,
|
||||||
|
|
@ -530,7 +530,7 @@ proc `*`*(a: int64, b: Duration): Duration {.operator} =
|
||||||
## Multiply a duration by some scalar.
|
## Multiply a duration by some scalar.
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
doAssert 5 * initDuration(seconds = 1) == initDuration(seconds = 5)
|
doAssert 5 * initDuration(seconds = 1) == initDuration(seconds = 5)
|
||||||
normalize[Duration](a * b.seconds, a * b.nanoseconds)
|
normalize[Duration](a * b.seconds, a * b.nanosecond)
|
||||||
|
|
||||||
proc `*`*(a: Duration, b: int64): Duration {.operator} =
|
proc `*`*(a: Duration, b: int64): Duration {.operator} =
|
||||||
## Multiply a duration by some scalar.
|
## Multiply a duration by some scalar.
|
||||||
|
|
@ -544,7 +544,7 @@ proc `div`*(a: Duration, b: int64): Duration {.operator} =
|
||||||
doAssert initDuration(seconds = 3) div 2 == initDuration(milliseconds = 1500)
|
doAssert initDuration(seconds = 3) div 2 == initDuration(milliseconds = 1500)
|
||||||
doAssert initDuration(nanoseconds = 3) div 2 == initDuration(nanoseconds = 1)
|
doAssert initDuration(nanoseconds = 3) div 2 == initDuration(nanoseconds = 1)
|
||||||
let carryOver = convert(Seconds, Nanoseconds, a.seconds mod b)
|
let carryOver = convert(Seconds, Nanoseconds, a.seconds mod b)
|
||||||
normalize[Duration](a.seconds div b, (a.nanoseconds + carryOver) div b)
|
normalize[Duration](a.seconds div b, (a.nanosecond + carryOver) div b)
|
||||||
|
|
||||||
proc `-`*(a, b: Time): Duration {.operator, extern: "ntDiffTime".} =
|
proc `-`*(a, b: Time): Duration {.operator, extern: "ntDiffTime".} =
|
||||||
## Computes the duration between two points in time.
|
## Computes the duration between two points in time.
|
||||||
|
|
@ -600,7 +600,7 @@ proc abs*(a: Duration): Duration =
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
doAssert initDuration(milliseconds = -1500).abs ==
|
doAssert initDuration(milliseconds = -1500).abs ==
|
||||||
initDuration(milliseconds = 1500)
|
initDuration(milliseconds = 1500)
|
||||||
initDuration(seconds = abs(a.seconds), nanoseconds = -a.nanoseconds)
|
initDuration(seconds = abs(a.seconds), nanoseconds = -a.nanosecond)
|
||||||
|
|
||||||
proc toTime*(dt: DateTime): Time {.tags: [], raises: [], benign.} =
|
proc toTime*(dt: DateTime): Time {.tags: [], raises: [], benign.} =
|
||||||
## Converts a broken-down time structure to
|
## Converts a broken-down time structure to
|
||||||
|
|
@ -650,7 +650,7 @@ proc initDateTime(zt: ZonedTime, zone: Timezone): DateTime =
|
||||||
hour: hour,
|
hour: hour,
|
||||||
minute: minute,
|
minute: minute,
|
||||||
second: second,
|
second: second,
|
||||||
nanosecond: zt.adjTime.nanoseconds,
|
nanosecond: zt.adjTime.nanosecond,
|
||||||
weekday: getDayOfWeek(d, m, y),
|
weekday: getDayOfWeek(d, m, y),
|
||||||
yearday: getDayOfYear(d, m, y),
|
yearday: getDayOfYear(d, m, y),
|
||||||
isDst: zt.isDst,
|
isDst: zt.isDst,
|
||||||
|
|
@ -809,7 +809,7 @@ else:
|
||||||
# as a result of offset changes (normally due to dst)
|
# as a result of offset changes (normally due to dst)
|
||||||
let utcUnix = adjTime.seconds + utcOffset
|
let utcUnix = adjTime.seconds + utcOffset
|
||||||
let (finalOffset, dst) = getLocalOffsetAndDst(utcUnix)
|
let (finalOffset, dst) = getLocalOffsetAndDst(utcUnix)
|
||||||
result.adjTime = initTime(utcUnix - finalOffset, adjTime.nanoseconds)
|
result.adjTime = initTime(utcUnix - finalOffset, adjTime.nanosecond)
|
||||||
result.utcOffset = finalOffset
|
result.utcOffset = finalOffset
|
||||||
result.isDst = dst
|
result.isDst = dst
|
||||||
|
|
||||||
|
|
@ -1806,7 +1806,7 @@ proc toSeconds*(time: Time): float {.tags: [], raises: [], benign, deprecated.}
|
||||||
## Returns the time in seconds since the unix epoch.
|
## Returns the time in seconds since the unix epoch.
|
||||||
##
|
##
|
||||||
## **Deprecated since v0.18.0:** use ``fromUnix`` instead
|
## **Deprecated since v0.18.0:** use ``fromUnix`` instead
|
||||||
time.seconds.float + time.nanoseconds / convert(Seconds, Nanoseconds, 1)
|
time.seconds.float + time.nanosecond / convert(Seconds, Nanoseconds, 1)
|
||||||
|
|
||||||
proc getLocalTime*(time: Time): DateTime {.tags: [], raises: [], benign, deprecated.} =
|
proc getLocalTime*(time: Time): DateTime {.tags: [], raises: [], benign, deprecated.} =
|
||||||
## Converts the calendar time `time` to broken-time representation,
|
## Converts the calendar time `time` to broken-time representation,
|
||||||
|
|
@ -1853,7 +1853,7 @@ when defined(JS):
|
||||||
## version 0.8.10.** Use ``epochTime`` or ``cpuTime`` instead.
|
## version 0.8.10.** Use ``epochTime`` or ``cpuTime`` instead.
|
||||||
let dur = getTime() - start
|
let dur = getTime() - start
|
||||||
result = (convert(Seconds, Milliseconds, dur.seconds) +
|
result = (convert(Seconds, Milliseconds, dur.seconds) +
|
||||||
convert(Nanoseconds, Milliseconds, dur.nanoseconds)).int
|
convert(Nanoseconds, Milliseconds, dur.nanosecond)).int
|
||||||
else:
|
else:
|
||||||
proc getStartMilsecs*(): int {.deprecated, tags: [TimeEffect], benign.} =
|
proc getStartMilsecs*(): int {.deprecated, tags: [TimeEffect], benign.} =
|
||||||
when defined(macosx):
|
when defined(macosx):
|
||||||
|
|
|
||||||
5
tests/flags/tgenscript.nim
Normal file
5
tests/flags/tgenscript.nim
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
discard """
|
||||||
|
file: "tgenscript.nim"
|
||||||
|
"""
|
||||||
|
|
||||||
|
echo "--genscript"
|
||||||
|
|
@ -367,6 +367,10 @@ suite "ttimes":
|
||||||
check d(seconds = 0) - d(milliseconds = 1500) == d(milliseconds = -1500)
|
check d(seconds = 0) - d(milliseconds = 1500) == d(milliseconds = -1500)
|
||||||
check d(milliseconds = -1500) == d(seconds = -1, milliseconds = -500)
|
check d(milliseconds = -1500) == d(seconds = -1, milliseconds = -500)
|
||||||
check d(seconds = -1, milliseconds = 500) == d(milliseconds = -500)
|
check d(seconds = -1, milliseconds = 500) == d(milliseconds = -500)
|
||||||
|
check initDuration(seconds = 1, nanoseconds = 2) <=
|
||||||
|
initDuration(seconds = 1, nanoseconds = 3)
|
||||||
|
check (initDuration(seconds = 1, nanoseconds = 3) <=
|
||||||
|
initDuration(seconds = 1, nanoseconds = 1)).not
|
||||||
|
|
||||||
test "large/small dates":
|
test "large/small dates":
|
||||||
discard initDateTime(1, mJan, -35_000, 12, 00, 00, utc())
|
discard initDateTime(1, mJan, -35_000, 12, 00, 00, utc())
|
||||||
|
|
@ -413,7 +417,7 @@ suite "ttimes":
|
||||||
|
|
||||||
test "fromWinTime/toWinTime":
|
test "fromWinTime/toWinTime":
|
||||||
check 0.fromUnix.toWinTime.fromWinTime.toUnix == 0
|
check 0.fromUnix.toWinTime.fromWinTime.toUnix == 0
|
||||||
check (-1).fromWinTime.nanoseconds == convert(Seconds, Nanoseconds, 1) - 100
|
check (-1).fromWinTime.nanosecond == convert(Seconds, Nanoseconds, 1) - 100
|
||||||
check -1.fromWinTime.toWinTime == -1
|
check -1.fromWinTime.toWinTime == -1
|
||||||
# One nanosecond is discarded due to differences in time resolution
|
# One nanosecond is discarded due to differences in time resolution
|
||||||
check initTime(0, 101).toWinTime.fromWinTime.nanoseconds == 100
|
check initTime(0, 101).toWinTime.fromWinTime.nanosecond == 100
|
||||||
|
|
@ -13,7 +13,7 @@ type
|
||||||
CommitId = distinct string
|
CommitId = distinct string
|
||||||
|
|
||||||
proc `$`*(id: MachineId): string {.borrow.}
|
proc `$`*(id: MachineId): string {.borrow.}
|
||||||
proc `$`(id: CommitId): string {.borrow.}
|
#proc `$`(id: CommitId): string {.borrow.} # not used
|
||||||
|
|
||||||
var
|
var
|
||||||
thisMachine: MachineId
|
thisMachine: MachineId
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,26 @@ proc compileRodFiles(r: var TResults, cat: Category, options: string) =
|
||||||
test "gtkex1", true
|
test "gtkex1", true
|
||||||
test "gtkex2"
|
test "gtkex2"
|
||||||
|
|
||||||
|
# --------------------- flags tests -------------------------------------------
|
||||||
|
|
||||||
|
proc flagTests(r: var TResults, cat: Category, options: string) =
|
||||||
|
# --genscript
|
||||||
|
const filename = "tests"/"flags"/"tgenscript"
|
||||||
|
const genopts = " --genscript"
|
||||||
|
let nimcache = nimcacheDir(filename, genopts, targetC)
|
||||||
|
testSpec r, makeTest(filename, genopts, cat)
|
||||||
|
|
||||||
|
when defined(windows):
|
||||||
|
testExec r, makeTest(filename, " cmd /c cd " & nimcache &
|
||||||
|
" && compile_tgenscript.bat", cat)
|
||||||
|
|
||||||
|
when defined(linux):
|
||||||
|
testExec r, makeTest(filename, " sh -c \"cd " & nimcache &
|
||||||
|
" && sh compile_tgenscript.sh\"", cat)
|
||||||
|
|
||||||
|
# Run
|
||||||
|
testExec r, makeTest(filename, " " & nimcache / "tgenscript", cat)
|
||||||
|
|
||||||
# --------------------- DLL generation tests ----------------------------------
|
# --------------------- DLL generation tests ----------------------------------
|
||||||
|
|
||||||
proc safeCopyFile(src, dest: string) =
|
proc safeCopyFile(src, dest: string) =
|
||||||
|
|
@ -323,7 +343,7 @@ var nimbleDir = getEnv("NIMBLE_DIR").string
|
||||||
if nimbleDir.len == 0: nimbleDir = getHomeDir() / ".nimble"
|
if nimbleDir.len == 0: nimbleDir = getHomeDir() / ".nimble"
|
||||||
let
|
let
|
||||||
nimbleExe = findExe("nimble")
|
nimbleExe = findExe("nimble")
|
||||||
packageDir = nimbleDir / "pkgs"
|
#packageDir = nimbleDir / "pkgs" # not used
|
||||||
packageIndex = nimbleDir / "packages.json"
|
packageIndex = nimbleDir / "packages.json"
|
||||||
|
|
||||||
proc waitForExitEx(p: Process): int =
|
proc waitForExitEx(p: Process): int =
|
||||||
|
|
@ -407,9 +427,9 @@ proc `&.?`(a, b: string): string =
|
||||||
# candidate for the stdlib?
|
# candidate for the stdlib?
|
||||||
result = if b.startswith(a): b else: a & b
|
result = if b.startswith(a): b else: a & b
|
||||||
|
|
||||||
proc `&?.`(a, b: string): string =
|
#proc `&?.`(a, b: string): string = # not used
|
||||||
# candidate for the stdlib?
|
# candidate for the stdlib?
|
||||||
result = if a.endswith(b): a else: a & b
|
#result = if a.endswith(b): a else: a & b
|
||||||
|
|
||||||
proc processSingleTest(r: var TResults, cat: Category, options, test: string) =
|
proc processSingleTest(r: var TResults, cat: Category, options, test: string) =
|
||||||
let test = "tests" & DirSep &.? cat.string / test
|
let test = "tests" & DirSep &.? cat.string / test
|
||||||
|
|
@ -429,6 +449,8 @@ proc processCategory(r: var TResults, cat: Category, options: string) =
|
||||||
jsTests(r, cat, options)
|
jsTests(r, cat, options)
|
||||||
of "dll":
|
of "dll":
|
||||||
dllTests(r, cat, options)
|
dllTests(r, cat, options)
|
||||||
|
of "flags":
|
||||||
|
flagTests(r, cat, options)
|
||||||
of "gc":
|
of "gc":
|
||||||
gcTests(r, cat, options)
|
gcTests(r, cat, options)
|
||||||
of "longgc":
|
of "longgc":
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ proc generateAllTestsContent(outfile: File, allResults: AllTests,
|
||||||
|
|
||||||
proc generateHtml*(filename: string, onlyFailing: bool) =
|
proc generateHtml*(filename: string, onlyFailing: bool) =
|
||||||
let
|
let
|
||||||
currentTime = getTime().getLocalTime()
|
currentTime = getTime().local()
|
||||||
timestring = htmlQuote format(currentTime, "yyyy-MM-dd HH:mm:ss 'UTC'zzz")
|
timestring = htmlQuote format(currentTime, "yyyy-MM-dd HH:mm:ss 'UTC'zzz")
|
||||||
var outfile = open(filename, fmWrite)
|
var outfile = open(filename, fmWrite)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ import
|
||||||
|
|
||||||
const
|
const
|
||||||
resultsFile = "testresults.html"
|
resultsFile = "testresults.html"
|
||||||
jsonFile = "testresults.json"
|
#jsonFile = "testresults.json" # not used
|
||||||
Usage = """Usage:
|
Usage = """Usage:
|
||||||
tester [options] command [arguments]
|
tester [options] command [arguments]
|
||||||
|
|
||||||
|
|
@ -150,11 +150,11 @@ proc initResults: TResults =
|
||||||
result.skipped = 0
|
result.skipped = 0
|
||||||
result.data = ""
|
result.data = ""
|
||||||
|
|
||||||
proc readResults(filename: string): TResults =
|
#proc readResults(filename: string): TResults = # not used
|
||||||
result = marshal.to[TResults](readFile(filename).string)
|
# result = marshal.to[TResults](readFile(filename).string)
|
||||||
|
|
||||||
proc writeResults(filename: string, r: TResults) =
|
#proc writeResults(filename: string, r: TResults) = # not used
|
||||||
writeFile(filename, $$r)
|
# writeFile(filename, $$r)
|
||||||
|
|
||||||
proc `$`(x: TResults): string =
|
proc `$`(x: TResults): string =
|
||||||
result = ("Tests passed: $1 / $3 <br />\n" &
|
result = ("Tests passed: $1 / $3 <br />\n" &
|
||||||
|
|
@ -404,6 +404,21 @@ proc testC(r: var TResults, test: TTest) =
|
||||||
if exitCode != 0: given.err = reExitCodesDiffer
|
if exitCode != 0: given.err = reExitCodesDiffer
|
||||||
if given.err == reSuccess: inc(r.passed)
|
if given.err == reSuccess: inc(r.passed)
|
||||||
|
|
||||||
|
proc testExec(r: var TResults, test: TTest) =
|
||||||
|
# runs executable or script, just goes by exit code
|
||||||
|
inc(r.total)
|
||||||
|
let (outp, errC) = execCmdEx(test.options.strip())
|
||||||
|
var given: TSpec
|
||||||
|
specDefaults(given)
|
||||||
|
if errC == 0:
|
||||||
|
given.err = reSuccess
|
||||||
|
else:
|
||||||
|
given.err = reExitCodesDiffer
|
||||||
|
given.msg = outp.string
|
||||||
|
|
||||||
|
if given.err == reSuccess: inc(r.passed)
|
||||||
|
r.addResult(test, targetC, "", given.msg, given.err)
|
||||||
|
|
||||||
proc makeTest(test, options: string, cat: Category, action = actionCompile,
|
proc makeTest(test, options: string, cat: Category, action = actionCompile,
|
||||||
env: string = ""): TTest =
|
env: string = ""): TTest =
|
||||||
# start with 'actionCompile', will be overwritten in the spec:
|
# start with 'actionCompile', will be overwritten in the spec:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue