diff options
Diffstat (limited to 'compiler/ccgutils.nim')
-rw-r--r-- | compiler/ccgutils.nim | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/compiler/ccgutils.nim b/compiler/ccgutils.nim index 310f7204a..1d8f0158b 100644 --- a/compiler/ccgutils.nim +++ b/compiler/ccgutils.nim @@ -22,19 +22,19 @@ proc getPragmaStmt*(n: PNode, w: TSpecialWord): PNode = of nkPragma: for i in 0 .. < n.len: if whichPragma(n[i]) == w: return n[i] - else: nil + else: discard proc stmtsContainPragma*(n: PNode, w: TSpecialWord): bool = result = getPragmaStmt(n, w) != nil -proc hashString*(s: string): biggestInt = +proc hashString*(s: string): BiggestInt = # has to be the same algorithm as system.hashString! if CPU[targetCPU].bit == 64: # we have to use the same bitwidth # as the target CPU var b = 0'i64 for i in countup(0, len(s) - 1): - b = b +% Ord(s[i]) + b = b +% ord(s[i]) b = b +% `shl`(b, 10) b = b xor `shr`(b, 6) b = b +% `shl`(b, 3) @@ -44,7 +44,7 @@ proc hashString*(s: string): biggestInt = else: var a = 0'i32 for i in countup(0, len(s) - 1): - a = a +% Ord(s[i]).int32 + a = a +% ord(s[i]).int32 a = a +% `shl`(a, 10'i32) a = a xor `shr`(a, 6'i32) a = a +% `shl`(a, 3'i32) @@ -57,7 +57,7 @@ var gCanonicalTypes: array[TTypeKind, PType] proc initTypeTables() = - for i in countup(low(TTypeKind), high(TTypeKind)): InitIdTable(gTypeTable[i]) + for i in countup(low(TTypeKind), high(TTypeKind)): initIdTable(gTypeTable[i]) proc resetCaches* = ## XXX: fix that more properly @@ -70,7 +70,7 @@ when false: for i in countup(low(TTypeKind), high(TTypeKind)): echo i, " ", gTypeTable[i].counter -proc GetUniqueType*(key: PType): PType = +proc getUniqueType*(key: PType): PType = # this is a hotspot in the compiler! if key == nil: return var k = key.kind @@ -86,12 +86,12 @@ proc GetUniqueType*(key: PType): PType = if result == nil: gCanonicalTypes[k] = key result = key - of tyTypeDesc, tyTypeClasses: - InternalError("value expected, but got a type") - of tyGenericParam: - InternalError("GetUniqueType") - of tyGenericInst, tyDistinct, tyOrdinal, tyMutable, tyConst, tyIter: - result = GetUniqueType(lastSon(key)) + of tyTypeDesc, tyTypeClasses, tyGenericParam, + tyFromExpr, tyFieldAccessor: + internalError("GetUniqueType") + of tyGenericInst, tyDistinct, tyOrdinal, tyMutable, + tyConst, tyIter, tyStatic: + result = getUniqueType(lastSon(key)) of tyArrayConstr, tyGenericInvokation, tyGenericBody, tyOpenArray, tyArray, tySet, tyRange, tyTuple, tyPtr, tyRef, tySequence, tyForward, tyVarargs, tyProxy, tyVar: @@ -102,51 +102,50 @@ proc GetUniqueType*(key: PType): PType = # we have to do a slow linear search because types may need # to be compared by their structure: - if IdTableHasObjectAsKey(gTypeTable[k], key): return key + if idTableHasObjectAsKey(gTypeTable[k], key): return key for h in countup(0, high(gTypeTable[k].data)): var t = PType(gTypeTable[k].data[h].key) if t != nil and sameBackendType(t, key): return t - IdTablePut(gTypeTable[k], key, key) + idTablePut(gTypeTable[k], key, key) result = key of tyObject: if tfFromGeneric notin key.flags: # fast case; lookup per id suffices: - result = PType(IdTableGet(gTypeTable[k], key)) + result = PType(idTableGet(gTypeTable[k], key)) if result == nil: - IdTablePut(gTypeTable[k], key, key) + idTablePut(gTypeTable[k], key, key) result = key else: # ugly slow case: need to compare by structure - if IdTableHasObjectAsKey(gTypeTable[k], key): return key + if idTableHasObjectAsKey(gTypeTable[k], key): return key for h in countup(0, high(gTypeTable[k].data)): var t = PType(gTypeTable[k].data[h].key) if t != nil and sameType(t, key): return t - IdTablePut(gTypeTable[k], key, key) + idTablePut(gTypeTable[k], key, key) result = key of tyEnum: - result = PType(IdTableGet(gTypeTable[k], key)) + result = PType(idTableGet(gTypeTable[k], key)) if result == nil: - IdTablePut(gTypeTable[k], key, key) + idTablePut(gTypeTable[k], key, key) result = key of tyProc: - # tyVar is not 100% correct, but would speeds things up a little: if key.callConv != ccClosure: result = key else: # ugh, we need the canon here: - if IdTableHasObjectAsKey(gTypeTable[k], key): return key + if idTableHasObjectAsKey(gTypeTable[k], key): return key for h in countup(0, high(gTypeTable[k].data)): var t = PType(gTypeTable[k].data[h].key) if t != nil and sameBackendType(t, key): return t - IdTablePut(gTypeTable[k], key, key) + idTablePut(gTypeTable[k], key, key) result = key -proc TableGetType*(tab: TIdTable, key: PType): PObject = +proc tableGetType*(tab: TIdTable, key: PType): PObject = # returns nil if we need to declare this type - result = IdTableGet(tab, key) + result = idTableGet(tab, key) if (result == nil) and (tab.counter > 0): # we have to do a slow linear search because types may need # to be compared by their structure: @@ -169,7 +168,7 @@ proc makeLLVMString*(s: string): PRope = for i in countup(0, len(s) - 1): if (i + 1) mod MaxLineLength == 0: app(result, toRope(res)) - setlen(res, 0) + setLen(res, 0) case s[i] of '\0'..'\x1F', '\x80'..'\xFF', '\"', '\\': add(res, '\\') @@ -178,4 +177,4 @@ proc makeLLVMString*(s: string): PRope = add(res, "\\00\"") app(result, toRope(res)) -InitTypeTables() +initTypeTables() |