summary refs log tree commit diff stats
path: root/lib/system
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2019-06-12 08:35:32 +0200
committerGitHub <noreply@github.com>2019-06-12 08:35:32 +0200
commit572b7c37a5e537ecf198b2761c7c0a7b2e2400f6 (patch)
tree1fec5b9b9611e2f3fd4525dfb6e8adec21de5d4d /lib/system
parentc7e1c665a1d399272bef35395a6c364b9f98d64a (diff)
downloadNim-572b7c37a5e537ecf198b2761c7c0a7b2e2400f6.tar.gz
[other] preparations for --styleCheck:error for the Nim compiler (#11478)
Diffstat (limited to 'lib/system')
-rw-r--r--lib/system/ansi_c.nim6
-rw-r--r--lib/system/dyncalls.nim6
-rw-r--r--lib/system/excpt.nim13
-rw-r--r--lib/system/strmantle.nim63
4 files changed, 45 insertions, 43 deletions
diff --git a/lib/system/ansi_c.nim b/lib/system/ansi_c.nim
index 99f66961d..febcbdcd4 100644
--- a/lib/system/ansi_c.nim
+++ b/lib/system/ansi_c.nim
@@ -88,8 +88,6 @@ when defined(macosx):
   const SIGBUS* = cint(10)
 elif defined(haiku):
   const SIGBUS* = cint(30)
-else:
-  template SIGBUS*: untyped = SIGSEGV
 
 when defined(nimSigSetjmp) and not defined(nimStdSetjmp):
   proc c_longjmp*(jmpb: C_JmpBuf, retval: cint) {.
@@ -109,8 +107,8 @@ else:
   proc c_setjmp*(jmpb: C_JmpBuf): cint {.
     header: "<setjmp.h>", importc: "setjmp".}
 
-type c_sighandler_t = proc (a: cint) {.noconv.}
-proc c_signal*(sign: cint, handler: proc (a: cint) {.noconv.}): c_sighandler_t {.
+type CSighandlerT = proc (a: cint) {.noconv.}
+proc c_signal*(sign: cint, handler: proc (a: cint) {.noconv.}): CSighandlerT {.
   importc: "signal", header: "<signal.h>", discardable.}
 
 type
diff --git a/lib/system/dyncalls.nim b/lib/system/dyncalls.nim
index 7868ba273..d16dbdf92 100644
--- a/lib/system/dyncalls.nim
+++ b/lib/system/dyncalls.nim
@@ -118,11 +118,11 @@ elif defined(windows) or defined(dos):
   proc nimGetProcAddr(lib: LibHandle, name: cstring): ProcAddr =
     result = getProcAddress(cast[THINSTANCE](lib), name)
     if result != nil: return
-    const decorated_length = 250
-    var decorated: array[decorated_length, char]
+    const decoratedLength = 250
+    var decorated: array[decoratedLength, char]
     decorated[0] = '_'
     var m = 1
-    while m < (decorated_length - 5):
+    while m < (decoratedLength - 5):
       if name[m - 1] == '\x00': break
       decorated[m] = name[m - 1]
       inc(m)
diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim
index b59840f77..2a925fd29 100644
--- a/lib/system/excpt.nim
+++ b/lib/system/excpt.nim
@@ -474,10 +474,10 @@ when defined(endb):
 when defined(cpp) and appType != "lib" and
     not defined(js) and not defined(nimscript) and
     hostOS != "standalone" and not defined(noCppExceptions):
-      
-  type 
+
+  type
     StdException {.importcpp: "std::exception", header: "<exception>".} = object
-      
+
   proc what(ex: StdException): cstring {.importcpp: "((char *)#.what())".}
 
   proc setTerminate(handler: proc() {.noconv.})
@@ -497,7 +497,7 @@ when defined(cpp) and appType != "lib" and
       msg = "Error: unhandled cpp exception: " & $e.what()
     except:
       msg = "Error: unhandled unknown cpp exception"
-      
+
     when defined(genode):
       # stderr not available by default, use the LOG session
       echo msg
@@ -518,7 +518,7 @@ when not defined(noSignalHandler) and not defined(useNimRtl):
         action("SIGABRT: Abnormal termination.\n")
       elif s == SIGFPE: action("SIGFPE: Arithmetic error.\n")
       elif s == SIGILL: action("SIGILL: Illegal operation.\n")
-      elif s == SIGBUS:
+      elif (when declared(SIGBUS): s == SIGBUS else: false):
         action("SIGBUS: Illegal storage access. (Attempt to read from nil?)\n")
       else:
         block platformSpecificSignal:
@@ -553,7 +553,8 @@ when not defined(noSignalHandler) and not defined(useNimRtl):
     c_signal(SIGABRT, signalHandler)
     c_signal(SIGFPE, signalHandler)
     c_signal(SIGILL, signalHandler)
-    c_signal(SIGBUS, signalHandler)
+    when declared(SIGBUS):
+      c_signal(SIGBUS, signalHandler)
     when declared(SIGPIPE):
       c_signal(SIGPIPE, signalHandler)
 
diff --git a/lib/system/strmantle.nim b/lib/system/strmantle.nim
index 457e0eab5..66477923c 100644
--- a/lib/system/strmantle.nim
+++ b/lib/system/strmantle.nim
@@ -149,14 +149,14 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat,
     kdigits, fdigits = 0
     exponent: int
     integer: uint64
-    frac_exponent = 0
-    exp_sign = 1
-    first_digit = -1
-    has_sign = false
+    fracExponent = 0
+    expSign = 1
+    firstDigit = -1
+    hasSign = false
 
   # Sign?
   if i < s.len and (s[i] == '+' or s[i] == '-'):
-    has_sign = true
+    hasSign = true
     if s[i] == '-':
       sign = -1.0
     inc(i)
@@ -180,7 +180,7 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat,
     return 0
 
   if i < s.len and s[i] in {'0'..'9'}:
-    first_digit = (s[i].ord - '0'.ord)
+    firstDigit = (s[i].ord - '0'.ord)
   # Integer part?
   while i < s.len and s[i] in {'0'..'9'}:
     inc(kdigits)
@@ -194,16 +194,16 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat,
     # if no integer part, Skip leading zeros
     if kdigits <= 0:
       while i < s.len and s[i] == '0':
-        inc(frac_exponent)
+        inc(fracExponent)
         inc(i)
         while i < s.len and s[i] == '_': inc(i)
 
-    if first_digit == -1 and i < s.len and s[i] in {'0'..'9'}:
-      first_digit = (s[i].ord - '0'.ord)
+    if firstDigit == -1 and i < s.len and s[i] in {'0'..'9'}:
+      firstDigit = (s[i].ord - '0'.ord)
     # get fractional part
     while i < s.len and s[i] in {'0'..'9'}:
       inc(fdigits)
-      inc(frac_exponent)
+      inc(fracExponent)
       integer = integer * 10'u64 + (s[i].ord - '0'.ord).uint64
       inc(i)
       while i < s.len and s[i] == '_': inc(i)
@@ -211,14 +211,14 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat,
   # if has no digits: return error
   if kdigits + fdigits <= 0 and
      (i == start or # no char consumed (empty string).
-     (i == start + 1 and has_sign)): # or only '+' or '-
+     (i == start + 1 and hasSign)): # or only '+' or '-
     return 0
 
   if i+1 < s.len and s[i] in {'e', 'E'}:
     inc(i)
     if s[i] == '+' or s[i] == '-':
       if s[i] == '-':
-        exp_sign = -1
+        expSign = -1
 
       inc(i)
     if s[i] notin {'0'..'9'}:
@@ -228,13 +228,13 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat,
       inc(i)
       while i < s.len and s[i] == '_': inc(i) # underscores are allowed and ignored
 
-  var real_exponent = exp_sign*exponent - frac_exponent
-  let exp_negative = real_exponent < 0
-  var abs_exponent = abs(real_exponent)
+  var realExponent = expSign*exponent - fracExponent
+  let expNegative = realExponent < 0
+  var absExponent = abs(realExponent)
 
   # if exponent greater than can be represented: +/- zero or infinity
-  if abs_exponent > 999:
-    if exp_negative:
+  if absExponent > 999:
+    if expNegative:
       number = 0.0*sign
     else:
       number = Inf*sign
@@ -243,20 +243,20 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat,
   # if integer is representable in 53 bits:  fast path
   # max fast path integer is  1<<53 - 1 or  8999999999999999 (16 digits)
   let digits = kdigits + fdigits
-  if digits <= 15 or (digits <= 16 and first_digit <= 8):
+  if digits <= 15 or (digits <= 16 and firstDigit <= 8):
     # max float power of ten with set bits above the 53th bit is 10^22
-    if abs_exponent <= 22:
-      if exp_negative:
-        number = sign * integer.float / powtens[abs_exponent]
+    if absExponent <= 22:
+      if expNegative:
+        number = sign * integer.float / powtens[absExponent]
       else:
-        number = sign * integer.float * powtens[abs_exponent]
+        number = sign * integer.float * powtens[absExponent]
       return i - start
 
     # if exponent is greater try to fit extra exponent above 22 by multiplying
     # integer part is there is space left.
     let slop = 15 - kdigits - fdigits
-    if  abs_exponent <= 22 + slop and not exp_negative:
-      number = sign * integer.float * powtens[slop] * powtens[abs_exponent-slop]
+    if  absExponent <= 22 + slop and not expNegative:
+      number = sign * integer.float * powtens[slop] * powtens[absExponent-slop]
       return i - start
 
   # if failed: slow path with strtod.
@@ -276,14 +276,17 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat,
       inc(i)
 
   # insert exponent
-  t[ti] = 'E'; inc(ti)
-  t[ti] = (if exp_negative: '-' else: '+'); inc(ti)
-  inc(ti, 3)
+  t[ti] = 'E'
+  inc(ti)
+  t[ti] = if expNegative: '-' else: '+'
+  inc(ti, 4)
 
   # insert adjusted exponent
-  t[ti-1] = ('0'.ord + abs_exponent mod 10).char; abs_exponent = abs_exponent div 10
-  t[ti-2] = ('0'.ord + abs_exponent mod 10).char; abs_exponent = abs_exponent div 10
-  t[ti-3] = ('0'.ord + abs_exponent mod 10).char
+  t[ti-1] = ('0'.ord + absExponent mod 10).char
+  absExponent = absExponent div 10
+  t[ti-2] = ('0'.ord + absExponent mod 10).char
+  absExponent = absExponent div 10
+  t[ti-3] = ('0'.ord + absExponent mod 10).char
 
   when defined(nimNoArrayToCstringConversion):
     number = c_strtod(addr t, nil)