make tests green

This commit is contained in:
Araq
2016-11-03 14:52:47 +01:00
parent 3b43cff0f8
commit c0b8a79315
3 changed files with 31 additions and 13 deletions

View File

@@ -37,7 +37,8 @@ proc hashOwner(s: PSym): SigHash =
result = gDebugInfo.register(p.name.s, m.name.s)
proc idOrSig(m: BModule; s: PSym): BiggestInt =
if s.kind in routineKinds and s.typ != nil and sfExported in s.flags:
if s.kind in routineKinds and s.typ != nil and sfExported in s.flags and
s.typ.callConv != ccInline:
# signatures for exported routines are reliable enough to
# produce a unique name and this means produced C++ is more stable wrt
# Nim changes:
@@ -113,17 +114,19 @@ proc getTypeName(m: BModule; typ: PType): Rope =
result = typ.sym.loc.r
else:
if typ.loc.r == nil:
when false:
when true:
# doesn't work yet and would require bigger rewritings
let h = hashType(typ, {considerParamNames})
let h = hashType(typ, {considerParamNames})# and 0x0fff_ffffu32
let sig =
if m.hashConflicts.containsOrIncl(cast[int](h)):
if m.hashConflicts.containsOrIncl(cast[int](h)) and false:
BiggestInt typ.id
else:
BiggestInt h
else:
let sig = BiggestInt typ.id
typ.loc.r = typ.typeName & sig.rope
typ.loc.r = typ.typeName & sig.rope #& ("_" & m.module.name.s)
if typ.kind != tySet:
typ.loc.r.add "_" & m.module.name.s
result = typ.loc.r
if result == nil: internalError("getTypeName: " & $typ.kind)

View File

@@ -43,13 +43,13 @@ type
# Ported to Nim by Erik O'Leary
type
Sha1State = array[0 .. 5-1, uint32]
Sha1State* = array[0 .. 5-1, uint32]
Sha1Buffer = array[0 .. 80-1, uint32]
template clearBuffer(w: Sha1Buffer, len = 16) =
zeroMem(addr(w), len * sizeof(uint32))
proc init(result: var Sha1State) =
proc init*(result: var Sha1State) =
result[0] = 0x67452301'u32
result[1] = 0xefcdab89'u32
result[2] = 0x98badcfe'u32
@@ -112,7 +112,7 @@ proc innerHash(state: var Sha1State, w: var Sha1Buffer) =
wrap state[3], d
wrap state[4], e
template computeInternal(src: untyped) =
proc sha1(src: cstring; len: int): Sha1Digest =
#Initialize state
var state: Sha1State
init(state)
@@ -121,10 +121,10 @@ template computeInternal(src: untyped) =
var w: Sha1Buffer
#Loop through all complete 64byte blocks.
let byteLen = src.len
let byteLen = len
let endOfFullBlocks = byteLen - 64
var endCurrentBlock = 0
var currentBlock = 0
var currentBlock = 0
while currentBlock <= endOfFullBlocks:
endCurrentBlock = currentBlock + 64
@@ -169,9 +169,24 @@ template computeInternal(src: untyped) =
for i in 0 .. Sha1DigestSize-1:
result[i] = uint8((int(state[i shr 2]) shr ((3-(i and 3)) * 8)) and 255)
proc sha1(src: string) : Sha1Digest =
proc sha1(src: string): Sha1Digest =
## Calculate SHA1 from input string
computeInternal(src)
sha1(src, src.len)
proc `!&`*(h: Hash, val: int): Hash {.inline.} =
## mixes a hash value `h` with `val` to produce a new hash value. This is
## only needed if you need to implement a hash proc for a new datatype.
result = h +% val
result = result +% result shl 10
result = result xor (result shr 6)
proc `!$`*(h: Hash): Hash {.inline.} =
## finishes the computation of the hash value. This is
## only needed if you need to implement a hash proc for a new datatype.
proc
proc hashData*(data: pointer, size: int): Hash =
proc secureHash*(str: string): SecureHash = SecureHash(sha1(str))
proc secureHashFile*(filename: string): SecureHash = secureHash(readFile(filename))

View File

@@ -108,7 +108,7 @@ proc rawGet(t: StringTableRef, key: string): int =
h = nextTry(h, high(t.data))
result = - 1
template get(t: StringTableRef, key: string): stmt {.immediate.} =
template get(t: StringTableRef, key: string) =
var index = rawGet(t, key)
if index >= 0: result = t.data[index].val
else: