[other] preparations for --styleCheck:error for the Nim compiler (#11478)
This commit is contained in:
parent
c7e1c665a1
commit
572b7c37a5
4 changed files with 45 additions and 43 deletions
|
|
@ -88,8 +88,6 @@ when defined(macosx):
|
||||||
const SIGBUS* = cint(10)
|
const SIGBUS* = cint(10)
|
||||||
elif defined(haiku):
|
elif defined(haiku):
|
||||||
const SIGBUS* = cint(30)
|
const SIGBUS* = cint(30)
|
||||||
else:
|
|
||||||
template SIGBUS*: untyped = SIGSEGV
|
|
||||||
|
|
||||||
when defined(nimSigSetjmp) and not defined(nimStdSetjmp):
|
when defined(nimSigSetjmp) and not defined(nimStdSetjmp):
|
||||||
proc c_longjmp*(jmpb: C_JmpBuf, retval: cint) {.
|
proc c_longjmp*(jmpb: C_JmpBuf, retval: cint) {.
|
||||||
|
|
@ -109,8 +107,8 @@ else:
|
||||||
proc c_setjmp*(jmpb: C_JmpBuf): cint {.
|
proc c_setjmp*(jmpb: C_JmpBuf): cint {.
|
||||||
header: "<setjmp.h>", importc: "setjmp".}
|
header: "<setjmp.h>", importc: "setjmp".}
|
||||||
|
|
||||||
type c_sighandler_t = proc (a: cint) {.noconv.}
|
type CSighandlerT = proc (a: cint) {.noconv.}
|
||||||
proc c_signal*(sign: cint, handler: proc (a: cint) {.noconv.}): c_sighandler_t {.
|
proc c_signal*(sign: cint, handler: proc (a: cint) {.noconv.}): CSighandlerT {.
|
||||||
importc: "signal", header: "<signal.h>", discardable.}
|
importc: "signal", header: "<signal.h>", discardable.}
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
|
||||||
|
|
@ -118,11 +118,11 @@ elif defined(windows) or defined(dos):
|
||||||
proc nimGetProcAddr(lib: LibHandle, name: cstring): ProcAddr =
|
proc nimGetProcAddr(lib: LibHandle, name: cstring): ProcAddr =
|
||||||
result = getProcAddress(cast[THINSTANCE](lib), name)
|
result = getProcAddress(cast[THINSTANCE](lib), name)
|
||||||
if result != nil: return
|
if result != nil: return
|
||||||
const decorated_length = 250
|
const decoratedLength = 250
|
||||||
var decorated: array[decorated_length, char]
|
var decorated: array[decoratedLength, char]
|
||||||
decorated[0] = '_'
|
decorated[0] = '_'
|
||||||
var m = 1
|
var m = 1
|
||||||
while m < (decorated_length - 5):
|
while m < (decoratedLength - 5):
|
||||||
if name[m - 1] == '\x00': break
|
if name[m - 1] == '\x00': break
|
||||||
decorated[m] = name[m - 1]
|
decorated[m] = name[m - 1]
|
||||||
inc(m)
|
inc(m)
|
||||||
|
|
|
||||||
|
|
@ -474,10 +474,10 @@ when defined(endb):
|
||||||
when defined(cpp) and appType != "lib" and
|
when defined(cpp) and appType != "lib" and
|
||||||
not defined(js) and not defined(nimscript) and
|
not defined(js) and not defined(nimscript) and
|
||||||
hostOS != "standalone" and not defined(noCppExceptions):
|
hostOS != "standalone" and not defined(noCppExceptions):
|
||||||
|
|
||||||
type
|
type
|
||||||
StdException {.importcpp: "std::exception", header: "<exception>".} = object
|
StdException {.importcpp: "std::exception", header: "<exception>".} = object
|
||||||
|
|
||||||
proc what(ex: StdException): cstring {.importcpp: "((char *)#.what())".}
|
proc what(ex: StdException): cstring {.importcpp: "((char *)#.what())".}
|
||||||
|
|
||||||
proc setTerminate(handler: proc() {.noconv.})
|
proc setTerminate(handler: proc() {.noconv.})
|
||||||
|
|
@ -497,7 +497,7 @@ when defined(cpp) and appType != "lib" and
|
||||||
msg = "Error: unhandled cpp exception: " & $e.what()
|
msg = "Error: unhandled cpp exception: " & $e.what()
|
||||||
except:
|
except:
|
||||||
msg = "Error: unhandled unknown cpp exception"
|
msg = "Error: unhandled unknown cpp exception"
|
||||||
|
|
||||||
when defined(genode):
|
when defined(genode):
|
||||||
# stderr not available by default, use the LOG session
|
# stderr not available by default, use the LOG session
|
||||||
echo msg
|
echo msg
|
||||||
|
|
@ -518,7 +518,7 @@ when not defined(noSignalHandler) and not defined(useNimRtl):
|
||||||
action("SIGABRT: Abnormal termination.\n")
|
action("SIGABRT: Abnormal termination.\n")
|
||||||
elif s == SIGFPE: action("SIGFPE: Arithmetic error.\n")
|
elif s == SIGFPE: action("SIGFPE: Arithmetic error.\n")
|
||||||
elif s == SIGILL: action("SIGILL: Illegal operation.\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")
|
action("SIGBUS: Illegal storage access. (Attempt to read from nil?)\n")
|
||||||
else:
|
else:
|
||||||
block platformSpecificSignal:
|
block platformSpecificSignal:
|
||||||
|
|
@ -553,7 +553,8 @@ when not defined(noSignalHandler) and not defined(useNimRtl):
|
||||||
c_signal(SIGABRT, signalHandler)
|
c_signal(SIGABRT, signalHandler)
|
||||||
c_signal(SIGFPE, signalHandler)
|
c_signal(SIGFPE, signalHandler)
|
||||||
c_signal(SIGILL, signalHandler)
|
c_signal(SIGILL, signalHandler)
|
||||||
c_signal(SIGBUS, signalHandler)
|
when declared(SIGBUS):
|
||||||
|
c_signal(SIGBUS, signalHandler)
|
||||||
when declared(SIGPIPE):
|
when declared(SIGPIPE):
|
||||||
c_signal(SIGPIPE, signalHandler)
|
c_signal(SIGPIPE, signalHandler)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -149,14 +149,14 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat,
|
||||||
kdigits, fdigits = 0
|
kdigits, fdigits = 0
|
||||||
exponent: int
|
exponent: int
|
||||||
integer: uint64
|
integer: uint64
|
||||||
frac_exponent = 0
|
fracExponent = 0
|
||||||
exp_sign = 1
|
expSign = 1
|
||||||
first_digit = -1
|
firstDigit = -1
|
||||||
has_sign = false
|
hasSign = false
|
||||||
|
|
||||||
# Sign?
|
# Sign?
|
||||||
if i < s.len and (s[i] == '+' or s[i] == '-'):
|
if i < s.len and (s[i] == '+' or s[i] == '-'):
|
||||||
has_sign = true
|
hasSign = true
|
||||||
if s[i] == '-':
|
if s[i] == '-':
|
||||||
sign = -1.0
|
sign = -1.0
|
||||||
inc(i)
|
inc(i)
|
||||||
|
|
@ -180,7 +180,7 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat,
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
if i < s.len and s[i] in {'0'..'9'}:
|
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?
|
# Integer part?
|
||||||
while i < s.len and s[i] in {'0'..'9'}:
|
while i < s.len and s[i] in {'0'..'9'}:
|
||||||
inc(kdigits)
|
inc(kdigits)
|
||||||
|
|
@ -194,16 +194,16 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat,
|
||||||
# if no integer part, Skip leading zeros
|
# if no integer part, Skip leading zeros
|
||||||
if kdigits <= 0:
|
if kdigits <= 0:
|
||||||
while i < s.len and s[i] == '0':
|
while i < s.len and s[i] == '0':
|
||||||
inc(frac_exponent)
|
inc(fracExponent)
|
||||||
inc(i)
|
inc(i)
|
||||||
while i < s.len and s[i] == '_': 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'}:
|
if firstDigit == -1 and i < s.len and s[i] in {'0'..'9'}:
|
||||||
first_digit = (s[i].ord - '0'.ord)
|
firstDigit = (s[i].ord - '0'.ord)
|
||||||
# get fractional part
|
# get fractional part
|
||||||
while i < s.len and s[i] in {'0'..'9'}:
|
while i < s.len and s[i] in {'0'..'9'}:
|
||||||
inc(fdigits)
|
inc(fdigits)
|
||||||
inc(frac_exponent)
|
inc(fracExponent)
|
||||||
integer = integer * 10'u64 + (s[i].ord - '0'.ord).uint64
|
integer = integer * 10'u64 + (s[i].ord - '0'.ord).uint64
|
||||||
inc(i)
|
inc(i)
|
||||||
while i < s.len and s[i] == '_': 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 has no digits: return error
|
||||||
if kdigits + fdigits <= 0 and
|
if kdigits + fdigits <= 0 and
|
||||||
(i == start or # no char consumed (empty string).
|
(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
|
return 0
|
||||||
|
|
||||||
if i+1 < s.len and s[i] in {'e', 'E'}:
|
if i+1 < s.len and s[i] in {'e', 'E'}:
|
||||||
inc(i)
|
inc(i)
|
||||||
if s[i] == '+' or s[i] == '-':
|
if s[i] == '+' or s[i] == '-':
|
||||||
if s[i] == '-':
|
if s[i] == '-':
|
||||||
exp_sign = -1
|
expSign = -1
|
||||||
|
|
||||||
inc(i)
|
inc(i)
|
||||||
if s[i] notin {'0'..'9'}:
|
if s[i] notin {'0'..'9'}:
|
||||||
|
|
@ -228,13 +228,13 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat,
|
||||||
inc(i)
|
inc(i)
|
||||||
while i < s.len and s[i] == '_': inc(i) # underscores are allowed and ignored
|
while i < s.len and s[i] == '_': inc(i) # underscores are allowed and ignored
|
||||||
|
|
||||||
var real_exponent = exp_sign*exponent - frac_exponent
|
var realExponent = expSign*exponent - fracExponent
|
||||||
let exp_negative = real_exponent < 0
|
let expNegative = realExponent < 0
|
||||||
var abs_exponent = abs(real_exponent)
|
var absExponent = abs(realExponent)
|
||||||
|
|
||||||
# if exponent greater than can be represented: +/- zero or infinity
|
# if exponent greater than can be represented: +/- zero or infinity
|
||||||
if abs_exponent > 999:
|
if absExponent > 999:
|
||||||
if exp_negative:
|
if expNegative:
|
||||||
number = 0.0*sign
|
number = 0.0*sign
|
||||||
else:
|
else:
|
||||||
number = Inf*sign
|
number = Inf*sign
|
||||||
|
|
@ -243,20 +243,20 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat,
|
||||||
# if integer is representable in 53 bits: fast path
|
# if integer is representable in 53 bits: fast path
|
||||||
# max fast path integer is 1<<53 - 1 or 8999999999999999 (16 digits)
|
# max fast path integer is 1<<53 - 1 or 8999999999999999 (16 digits)
|
||||||
let digits = kdigits + fdigits
|
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
|
# max float power of ten with set bits above the 53th bit is 10^22
|
||||||
if abs_exponent <= 22:
|
if absExponent <= 22:
|
||||||
if exp_negative:
|
if expNegative:
|
||||||
number = sign * integer.float / powtens[abs_exponent]
|
number = sign * integer.float / powtens[absExponent]
|
||||||
else:
|
else:
|
||||||
number = sign * integer.float * powtens[abs_exponent]
|
number = sign * integer.float * powtens[absExponent]
|
||||||
return i - start
|
return i - start
|
||||||
|
|
||||||
# if exponent is greater try to fit extra exponent above 22 by multiplying
|
# if exponent is greater try to fit extra exponent above 22 by multiplying
|
||||||
# integer part is there is space left.
|
# integer part is there is space left.
|
||||||
let slop = 15 - kdigits - fdigits
|
let slop = 15 - kdigits - fdigits
|
||||||
if abs_exponent <= 22 + slop and not exp_negative:
|
if absExponent <= 22 + slop and not expNegative:
|
||||||
number = sign * integer.float * powtens[slop] * powtens[abs_exponent-slop]
|
number = sign * integer.float * powtens[slop] * powtens[absExponent-slop]
|
||||||
return i - start
|
return i - start
|
||||||
|
|
||||||
# if failed: slow path with strtod.
|
# if failed: slow path with strtod.
|
||||||
|
|
@ -276,14 +276,17 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat,
|
||||||
inc(i)
|
inc(i)
|
||||||
|
|
||||||
# insert exponent
|
# insert exponent
|
||||||
t[ti] = 'E'; inc(ti)
|
t[ti] = 'E'
|
||||||
t[ti] = (if exp_negative: '-' else: '+'); inc(ti)
|
inc(ti)
|
||||||
inc(ti, 3)
|
t[ti] = if expNegative: '-' else: '+'
|
||||||
|
inc(ti, 4)
|
||||||
|
|
||||||
# insert adjusted exponent
|
# insert adjusted exponent
|
||||||
t[ti-1] = ('0'.ord + abs_exponent mod 10).char; abs_exponent = abs_exponent div 10
|
t[ti-1] = ('0'.ord + absExponent mod 10).char
|
||||||
t[ti-2] = ('0'.ord + abs_exponent mod 10).char; abs_exponent = abs_exponent div 10
|
absExponent = absExponent div 10
|
||||||
t[ti-3] = ('0'.ord + abs_exponent mod 10).char
|
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):
|
when defined(nimNoArrayToCstringConversion):
|
||||||
number = c_strtod(addr t, nil)
|
number = c_strtod(addr t, nil)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue