Merge branch 'araq' of github.com:nim-lang/Nim into araq

This commit is contained in:
Andreas Rumpf 2017-09-15 16:08:16 +02:00
commit 053b0ad6f3
13 changed files with 49 additions and 165 deletions

View file

@ -669,7 +669,7 @@ proc astGenRepr*(n: NimNode): string {.compileTime, benign.} =
t = x
result = newString(len)
for j in countdown(len-1, 0):
result[j] = HexChars[t and 0xF]
result[j] = HexChars[int(t and 0xF)]
t = t shr 4
# handle negative overflow
if t == 0 and x < 0: t = -1

View file

@ -78,10 +78,10 @@ proc encode(dest: var MD5Block, src: cstring) =
proc decode(dest: var openArray[uint8], src: openArray[uint32]) =
var i = 0
for j in 0..high(src):
dest[i] = src[j] and 0xff'u32
dest[i+1] = src[j] shr 8 and 0xff'u32
dest[i+2] = src[j] shr 16 and 0xff'u32
dest[i+3] = src[j] shr 24 and 0xff'u32
dest[i] = uint8(src[j] and 0xff'u32)
dest[i+1] = uint8(src[j] shr 8 and 0xff'u32)
dest[i+2] = uint8(src[j] shr 16 and 0xff'u32)
dest[i+3] = uint8(src[j] shr 24 and 0xff'u32)
inc(i, 4)
proc transform(buffer: pointer, state: var MD5State) =
@ -216,8 +216,8 @@ proc `$`*(d: MD5Digest): string =
const digits = "0123456789abcdef"
result = ""
for i in 0..15:
add(result, digits[(d[i] shr 4) and 0xF])
add(result, digits[d[i] and 0xF])
add(result, digits[(d[i].int shr 4) and 0xF])
add(result, digits[d[i].int and 0xF])
proc getMD5*(s: string): string =
## computes an MD5 value of `s` and returns its string representation

View file

@ -148,13 +148,13 @@ proc sha1(src: cstring; len: int): Sha1Digest =
while lastBlockBytes < endCurrentBlock:
var value = uint32(src[lastBlockBytes + currentBlock]) shl
((3'u32 - (lastBlockBytes and 3)) shl 3)
((3'u32 - uint32(lastBlockBytes and 3)) shl 3)
w[lastBlockBytes shr 2] = w[lastBlockBytes shr 2] or value
inc(lastBlockBytes)
w[lastBlockBytes shr 2] = w[lastBlockBytes shr 2] or (
0x80'u32 shl ((3'u32 - (lastBlockBytes and 3)) shl 3)
0x80'u32 shl ((3'u32 - uint32(lastBlockBytes and 3)) shl 3)
)
if endCurrentBlock >= 56:

View file

@ -887,7 +887,7 @@ proc toHex*(x: BiggestInt, len: Positive): string {.noSideEffect,
n = x
result = newString(len)
for j in countdown(len-1, 0):
result[j] = HexChars[n and 0xF]
result[j] = HexChars[(n and 0xF).int]
n = n shr 4
# handle negative overflow
if n == 0 and x < 0: n = -1

View file

@ -1909,7 +1909,7 @@ const
NimMinor*: int = 17
## is the minor number of Nim's version.
NimPatch*: int = 2
NimPatch*: int = 3
## is the patch number of Nim's version.
NimVersion*: string = $NimMajor & "." & $NimMinor & "." & $NimPatch

View file

@ -38,20 +38,29 @@ proc chckRange(i, a, b: int): int {.inline, compilerproc, benign.}
proc chckRangeF(x, a, b: float): float {.inline, compilerproc, benign.}
proc chckNil(p: pointer) {.noinline, compilerproc, benign.}
type
GcFrame = ptr GcFrameHeader
GcFrameHeader {.compilerproc.} = object
len: int
prev: ptr GcFrameHeader
var
framePtr {.threadvar.}: PFrame
excHandler {.threadvar.}: PSafePoint
# list of exception handlers
# a global variable for the root of all try blocks
currException {.threadvar.}: ref Exception
gcFramePtr {.threadvar.}: GcFrame
type
FrameState = tuple[framePtr: PFrame, excHandler: PSafePoint, currException: ref Exception]
FrameState = tuple[gcFramePtr: GcFrame, framePtr: PFrame,
excHandler: PSafePoint, currException: ref Exception]
proc getFrameState*(): FrameState {.compilerRtl, inl.} =
return (framePtr, excHandler, currException)
return (gcFramePtr, framePtr, excHandler, currException)
proc setFrameState*(state: FrameState) {.compilerRtl, inl.} =
gcFramePtr = state.gcFramePtr
framePtr = state.framePtr
excHandler = state.excHandler
currException = state.currException
@ -64,6 +73,14 @@ proc popFrame {.compilerRtl, inl.} =
proc setFrame*(s: PFrame) {.compilerRtl, inl.} =
framePtr = s
proc getGcFrame*(): GcFrame {.compilerRtl, inl.} = gcFramePtr
proc popGcFrame*() {.compilerRtl, inl.} = gcFramePtr = gcFramePtr.prev
proc setGcFrame*(s: GcFrame) {.compilerRtl, inl.} = gcFramePtr = s
proc pushGcFrame*(s: GcFrame) {.compilerRtl, inl.} =
s.prev = gcFramePtr
zeroMem(cast[pointer](cast[int](s)+%sizeof(GcFrameHeader)), s.len*sizeof(pointer))
gcFramePtr = s
proc pushSafePoint(s: PSafePoint) {.compilerRtl, inl.} =
s.hasRaiseAction = false
s.prev = excHandler