diff options
author | Rostyslav Dzinko <rostislav.dzinko@gmail.com> | 2016-07-05 19:05:31 +0300 |
---|---|---|
committer | Rostyslav Dzinko <rostislav.dzinko@gmail.com> | 2016-07-05 19:05:31 +0300 |
commit | e94c0ea4c84f5bdbe3fb2d40da35c7ae92d66cd7 (patch) | |
tree | 23f62a235e923a14433bd6305f1ae9449f7dcf2c /lib/system/repr.nim | |
parent | b439e3b4d973e62c3a2605ba1b7a99a1bf181b08 (diff) | |
download | Nim-e94c0ea4c84f5bdbe3fb2d40da35c7ae92d66cd7.tar.gz |
Fixed reprEnum function on 32-bit systems
Diffstat (limited to 'lib/system/repr.nim')
-rw-r--r-- | lib/system/repr.nim | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/lib/system/repr.nim b/lib/system/repr.nim index 4da4781ef..1b80cf2f8 100644 --- a/lib/system/repr.nim +++ b/lib/system/repr.nim @@ -73,23 +73,20 @@ proc reprChar(x: char): string {.compilerRtl.} = add result, "\'" proc reprEnum(e: int, typ: PNimType): string {.compilerRtl.} = - # we read an 'int' but this may have been too large, so mask the other bits: - let b = (sizeof(int)-typ.size)*8 # bits - let m = 1 shl (b-1) # mask - var o = e and ((1 shl b)-1) # clear upper bits - o = (o xor m) - m # sign extend - # XXX we need a proper narrowing based on signedness here - #e and ((1 shl (typ.size*8)) - 1) + ## Return string representation for enumeration values + var n = typ.node if ntfEnumHole notin typ.flags: - if o <% typ.node.len: - return $typ.node.sons[o].name + let o = e - n.sons[0].offset + if o >= 0 and o <% typ.node.len: + return $n.sons[o].name else: # ugh we need a slow linear search: - var n = typ.node var s = n.sons for i in 0 .. n.len-1: - if s[i].offset == o: return $s[i].name - result = $o & " (invalid data!)" + if s[i].offset == e: + return $s[i].name + + result = $e & " (invalid data!)" type PByteArray = ptr array[0.. 0xffff, int8] |