From bf7c34242697304157de2f72d1dec8c051ede4b5 Mon Sep 17 00:00:00 2001 From: Maurizio Tomasi Date: Thu, 5 Mar 2015 15:04:39 +0100 Subject: [PATCH 1/7] New templates for getting the limits of FP types added. New variable "FP_RADIX" and new templates "mantissaDigits", "digits", "minExponent", "maxExponent", "min10Exponent", "max10Exponent", "minimumPositiveValue", "maximumPositiveValue", and "epsilon" added to retrieve the limits of floating-point types. --- lib/pure/fenv.nim | 76 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/lib/pure/fenv.nim b/lib/pure/fenv.nim index 6f9085c921..f64358d388 100644 --- a/lib/pure/fenv.nim +++ b/lib/pure/fenv.nim @@ -101,3 +101,79 @@ proc feupdateenv*(envp: ptr Tfenv): cint {.importc, header: "".} ## Save current exceptions in temporary storage, install environment ## represented by object pointed to by `envp` and raise exceptions ## according to saved exceptions. + +var FP_RADIX* {. importc: "FLT_RADIX" header: "" .} : int + ## The (integer) value of the radix used to represent any floating + ## point type on the architecture used to build the program. + +var FLT_MANT_DIG {. importc: "FLT_MANT_DIG" header: "" .} : int +var FLT_DIG {. importc: "FLT_DIG" header: "" .} : int +var FLT_MIN_EXP {. importc: "FLT_MIN_EXP" header: "" .} : int +var FLT_MAX_EXP {. importc: "FLT_MAX_EXP" header: "" .} : int +var FLT_MIN_10_EXP {. importc: "FLT_MIN_10_EXP" header: "" .} : int +var FLT_MAX_10_EXP {. importc: "FLT_MAX_10_EXP" header: "" .} : int +var FLT_MIN {. importc: "FLT_MIN" header: "" .} : cfloat +var FLT_MAX {. importc: "FLT_MAX" header: "" .} : cfloat +var FLT_EPSILON {. importc: "FLT_EPSILON" header: "" .} : cfloat + +var DBL_MANT_DIG {. importc: "DBL_MANT_DIG" header: "" .} : int +var DBL_DIG {. importc: "DBL_DIG" header: "" .} : int +var DBL_MIN_EXP {. importc: "DBL_MIN_EXP" header: "" .} : int +var DBL_MAX_EXP {. importc: "DBL_MAX_EXP" header: "" .} : int +var DBL_MIN_10_EXP {. importc: "DBL_MIN_10_EXP" header: "" .} : int +var DBL_MAX_10_EXP {. importc: "DBL_MAX_10_EXP" header: "" .} : int +var DBL_MIN {. importc: "DBL_MIN" header: "" .} : cdouble +var DBL_MAX {. importc: "DBL_MAX" header: "" .} : cdouble +var DBL_EPSILON {. importc: "DBL_EPSILON" header: "" .} : cdouble + +template mantissaDigits*(T : typedesc[float32]) : int = FLT_MANT_DIG + ## Number of digits (in base ``floatingPointRadix``) in the mantissa + ## of 32-bit floating-point numbers. +template digits*(T : typedesc[float32]) : int = FLT_DIG + ## Number of decimal digits that can be represented for the + ## 32-bit floating-point type without losing precision. +template minExponent*(T : typedesc[float32]) : int = FLT_MIN_EXP + ## Minimum (negative) exponent for 32-bit floating-point numbers. +template maxExponent*(T : typedesc[float32]) : int = FLT_MAX_EXP + ## Maximum (positive) exponent for 32-bit floating-point numbers. +template min10Exponent*(T : typedesc[float32]) : int = FLT_MIN_10_EXP + ## Minimum (negative) exponent in base 10 for 32-bit floating-point + ## numbers. +template max10Exponent*(T : typedesc[float32]) : int = FLT_MAX_10_EXP + ## Maximum (positive) exponent in base 10 for 32-bit floating-point + ## numbers. +template minimumPositiveValue*(T : typedesc[float32]) : float32 = FLT_MIN + ## The smallest positive (nonzero) number that can be hold by a + ## 32-bit floating-point type. +template maximumPositiveValue*(T : typedesc[float32]) : float32 = FLT_MAX + ## The largest positive number that can be hold by a 32-bit + ## floating-point type. +template epsilon*(T : typedesc[float32]): float32 = FLT_EPSILON + ## The difference between 1.0 and the smallest number greater than + ## 1.0 that can be represented using a 32-bit floating-point type. + +template mantissaDigits*(T : typedesc[float64]) : int = DBL_MANT_DIG + ## Number of digits (in base ``floatingPointRadix``) in the mantissa + ## of 64-bit floating-point numbers. +template digits*(T : typedesc[float64]) : int = DBL_DIG + ## Number of decimal digits that can be represented for the + ## 64-bit floating-point type without losing precision. +template minExponent*(T : typedesc[float64]) : int = DBL_MIN_EXP + ## Minimum (negative) exponent for 64-bit floating-point numbers. +template maxExponent*(T : typedesc[float64]) : int = DBL_MAX_EXP + ## Maximum (positive) exponent for 64-bit floating-point numbers. +template min10Exponent*(T : typedesc[float64]) : int = DBL_MIN_10_EXP + ## Minimum (negative) exponent in base 10 for 64-bit floating-point + ## numbers. +template max10Exponent*(T : typedesc[float64]) : int = DBL_MAX_10_EXP + ## Maximum (positive) exponent in base 10 for 64-bit floating-point + ## numbers. +template minimumPositiveValue*(T : typedesc[float64]) : float64 = DBL_MIN + ## The smallest positive (nonzero) number that can be hold by a + ## 64-bit floating-point type. +template maximumPositiveValue*(T : typedesc[float64]) : float64 = DBL_MAX + ## The largest positive number that can be hold by a 64-bit + ## floating-point type. +template epsilon*(T : typedesc[float64]): float64 = DBL_EPSILON + ## The difference between 1.0 and the smallest number greater than + ## 1.0 that can be represented using a 64-bit floating-point type. From 9c113b52643beafcb102942b0c13ed68d965a602 Mon Sep 17 00:00:00 2001 From: Maurizio Tomasi Date: Thu, 5 Mar 2015 22:38:53 +0100 Subject: [PATCH 2/7] Grammar fixes in the docstrings --- lib/pure/fenv.nim | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/pure/fenv.nim b/lib/pure/fenv.nim index f64358d388..afb3fb8fe8 100644 --- a/lib/pure/fenv.nim +++ b/lib/pure/fenv.nim @@ -130,7 +130,7 @@ template mantissaDigits*(T : typedesc[float32]) : int = FLT_MANT_DIG ## Number of digits (in base ``floatingPointRadix``) in the mantissa ## of 32-bit floating-point numbers. template digits*(T : typedesc[float32]) : int = FLT_DIG - ## Number of decimal digits that can be represented for the + ## Number of decimal digits that can be represented in a ## 32-bit floating-point type without losing precision. template minExponent*(T : typedesc[float32]) : int = FLT_MIN_EXP ## Minimum (negative) exponent for 32-bit floating-point numbers. @@ -143,20 +143,20 @@ template max10Exponent*(T : typedesc[float32]) : int = FLT_MAX_10_EXP ## Maximum (positive) exponent in base 10 for 32-bit floating-point ## numbers. template minimumPositiveValue*(T : typedesc[float32]) : float32 = FLT_MIN - ## The smallest positive (nonzero) number that can be hold by a + ## The smallest positive (nonzero) number that can be represented in a ## 32-bit floating-point type. template maximumPositiveValue*(T : typedesc[float32]) : float32 = FLT_MAX - ## The largest positive number that can be hold by a 32-bit + ## The largest positive number that can be represented in a 32-bit ## floating-point type. template epsilon*(T : typedesc[float32]): float32 = FLT_EPSILON ## The difference between 1.0 and the smallest number greater than - ## 1.0 that can be represented using a 32-bit floating-point type. + ## 1.0 that can be represented in a 32-bit floating-point type. template mantissaDigits*(T : typedesc[float64]) : int = DBL_MANT_DIG ## Number of digits (in base ``floatingPointRadix``) in the mantissa ## of 64-bit floating-point numbers. template digits*(T : typedesc[float64]) : int = DBL_DIG - ## Number of decimal digits that can be represented for the + ## Number of decimal digits that can be represented in a ## 64-bit floating-point type without losing precision. template minExponent*(T : typedesc[float64]) : int = DBL_MIN_EXP ## Minimum (negative) exponent for 64-bit floating-point numbers. @@ -169,11 +169,11 @@ template max10Exponent*(T : typedesc[float64]) : int = DBL_MAX_10_EXP ## Maximum (positive) exponent in base 10 for 64-bit floating-point ## numbers. template minimumPositiveValue*(T : typedesc[float64]) : float64 = DBL_MIN - ## The smallest positive (nonzero) number that can be hold by a + ## The smallest positive (nonzero) number that can be represented in a ## 64-bit floating-point type. template maximumPositiveValue*(T : typedesc[float64]) : float64 = DBL_MAX - ## The largest positive number that can be hold by a 64-bit + ## The largest positive number that can be represented in a 64-bit ## floating-point type. template epsilon*(T : typedesc[float64]): float64 = DBL_EPSILON ## The difference between 1.0 and the smallest number greater than - ## 1.0 that can be represented using a 64-bit floating-point type. + ## 1.0 that can be represented in a 64-bit floating-point type. From 9735d5c3caeca85ad4826aebf0ba2dc543021882 Mon Sep 17 00:00:00 2001 From: krolik Date: Mon, 9 Mar 2015 12:55:02 +0200 Subject: [PATCH 3/7] Added implementation for Redis SCAN command --- lib/pure/redis.nim | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/pure/redis.nim b/lib/pure/redis.nim index 64d3e14701..9177ddee59 100644 --- a/lib/pure/redis.nim +++ b/lib/pure/redis.nim @@ -285,6 +285,30 @@ proc keys*(r: Redis, pattern: string): RedisList = r.sendCommand("KEYS", pattern) return r.readArray() +proc scan*(r: Redis, cursor: var BiggestInt): RedisList = + ## Find all keys matching the given pattern and yield it to client in portions + ## using default Redis values for MATCH and COUNT parameters + r.sendCommand("SCAN", $cursor) + let reply = r.readArray() + cursor = strutils.parseBiggestInt(reply[0]) + return reply[1..high(reply)] + +proc scan*(r: Redis, cursor: var BiggestInt, pattern: string): RedisList = + ## Find all keys matching the given pattern and yield it to client in portions + ## using cursor as a client query identifier. Using default Redis value for COUNT argument + r.sendCommand("SCAN", $cursor, ["MATCH", pattern]) + let reply = r.readArray() + cursor = strutils.parseBiggestInt(reply[0]) + return reply[1..high(reply)] + +proc scan*(r: Redis, cursor: var BiggestInt, pattern: string, count: int): RedisList = + ## Find all keys matching the given pattern and yield it to client in portions + ## using cursor as a client query identifier. + r.sendCommand("SCAN", $cursor, ["MATCH", pattern, "COUNT", $count]) + let reply = r.readArray() + cursor = strutils.parseBiggestInt(reply[0]) + return reply[1..high(reply)] + proc move*(r: Redis, key: string, db: int): bool = ## Move a key to another database. Returns `true` on a successful move. r.sendCommand("MOVE", key, $db) From cf1a801e314982d099f72760745edd0a24d47ecb Mon Sep 17 00:00:00 2001 From: Maurizio Tomasi Date: Wed, 11 Mar 2015 11:08:37 +0100 Subject: [PATCH 4/7] New template `fpRadix` instead of the exported var `FP_RADIX` --- lib/pure/fenv.nim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/pure/fenv.nim b/lib/pure/fenv.nim index afb3fb8fe8..fd0eab3104 100644 --- a/lib/pure/fenv.nim +++ b/lib/pure/fenv.nim @@ -102,7 +102,9 @@ proc feupdateenv*(envp: ptr Tfenv): cint {.importc, header: "".} ## represented by object pointed to by `envp` and raise exceptions ## according to saved exceptions. -var FP_RADIX* {. importc: "FLT_RADIX" header: "" .} : int +var FP_RADIX_INTERNAL {. importc: "FLT_RADIX" header: "" .} : int + +template fpRadix* : int = FLT_RADIX_INTERNAL ## The (integer) value of the radix used to represent any floating ## point type on the architecture used to build the program. From aa7e7ee270544adaf1ad34cfcf31cbabe9a6c70c Mon Sep 17 00:00:00 2001 From: def Date: Thu, 12 Mar 2015 21:17:39 +0100 Subject: [PATCH 5/7] Make readFile work with FIFO files --- lib/system/sysio.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/system/sysio.nim b/lib/system/sysio.nim index 48adb895dd..468af17139 100644 --- a/lib/system/sysio.nim +++ b/lib/system/sysio.nim @@ -154,7 +154,7 @@ proc readAll(file: File): TaintedString = proc readFile(filename: string): TaintedString = var f = open(filename) try: - result = readAllFile(f).TaintedString + result = readAll(f).TaintedString finally: close(f) From 7daf410f465b2d4e928edd55b0fc763b5243adb0 Mon Sep 17 00:00:00 2001 From: def Date: Thu, 12 Mar 2015 23:48:38 +0100 Subject: [PATCH 6/7] Improve error message for failed conversion in VM - Fixes #2045 - Old one: Error: conversion from unknown type to unknown type is invalid - New one: Error: conversion from -1 to [0..255] is invalid --- compiler/vm.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/vm.nim b/compiler/vm.nim index f0a0135e82..3b5c8e7f3b 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -814,7 +814,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = leValueConv(regs[ra].regToNode, regs[rc].regToNode)): stackTrace(c, tos, pc, errGenerated, msgKindToString(errIllegalConvFromXtoY) % [ - "unknown type" , "unknown type"]) + $regs[ra].regToNode, "[" & $regs[rb].regToNode & ".." & $regs[rc].regToNode & "]"]) of opcIndCall, opcIndCallAsgn: # dest = call regStart, n; where regStart = fn, arg1, ... let rb = instr.regB From 81327233170afe508abc2c1bf6542e9f7a3a7dc9 Mon Sep 17 00:00:00 2001 From: teroz Date: Fri, 13 Mar 2015 12:05:02 +0200 Subject: [PATCH 7/7] fixed log*(logger: RollingFileLogger, level: Level, frmt: string, args: varargs[string, ]) --- lib/pure/logging.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pure/logging.nim b/lib/pure/logging.nim index b64437c896..16c36e1f03 100644 --- a/lib/pure/logging.nim +++ b/lib/pure/logging.nim @@ -217,7 +217,7 @@ method log*(logger: RollingFileLogger, level: Level, logger.curLine = 0 logger.f = open(logger.baseName, logger.baseMode) - writeln(logger.f, LevelNames[level], " ", frmt % args) + writeln(logger.f, LevelNames[level], " ",substituteLog(logger.fmtStr), frmt % args) logger.curLine.inc # --------