summary refs log tree commit diff stats
path: root/lib/system
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-05-01 20:11:55 +0200
committerAraq <rumpf_a@web.de>2011-05-01 20:11:55 +0200
commit6ff8752be53b7c0ad2c01615fdf1ab1bb619fb83 (patch)
tree6ad172b70b3b54063bc0dd6566a6c4ed0f5b0a99 /lib/system
parent0d75723f919931c8523715dbd537d6f86d8ac3dd (diff)
downloadNim-6ff8752be53b7c0ad2c01615fdf1ab1bb619fb83.tar.gz
cleaned up the tests; fixes #30; fixes #26
Diffstat (limited to 'lib/system')
-rwxr-xr-xlib/system/hti.nim4
-rwxr-xr-xlib/system/repr.nim14
2 files changed, 13 insertions, 5 deletions
diff --git a/lib/system/hti.nim b/lib/system/hti.nim
index 3343000ae..d22109061 100755
--- a/lib/system/hti.nim
+++ b/lib/system/hti.nim
@@ -45,7 +45,9 @@ type # This should be he same as ast.TTypeKind
 
   TNimTypeFlag = enum 
     ntfNoRefs = 0,     # type contains no tyRef, tySequence, tyString
-    ntfAcyclic = 1     # type cannot form a cycle
+    ntfAcyclic = 1,    # type cannot form a cycle
+    ntfEnumHole = 2    # enum has holes and thus `$` for them needs the slow
+                       # version
   TNimType {.compilerproc, final.} = object
     size: int
     kind: TNimKind
diff --git a/lib/system/repr.nim b/lib/system/repr.nim
index a70989cad..87588421f 100755
--- a/lib/system/repr.nim
+++ b/lib/system/repr.nim
@@ -1,7 +1,7 @@
 #
 #
 #            Nimrod's Runtime Library
-#        (c) Copyright 2010 Andreas Rumpf
+#        (c) Copyright 2011 Andreas Rumpf
 #
 #    See the file "copying.txt", included in this
 #    distribution, for details about the copyright.
@@ -53,10 +53,16 @@ proc reprChar(x: char): string {.compilerRtl.} =
   add result, "\'"
 
 proc reprEnum(e: int, typ: PNimType): string {.compilerRtl.} =
-  if e <% typ.node.len: # BUGFIX
-    result = $typ.node.sons[e].name
+  if ntfEnumHole notin typ.flags:
+    if e <% typ.node.len:
+      return $typ.node.sons[e].name
   else:
-    result = $e & " (invalid data!)"
+    # 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 == e: return $s[i].name
+  result = $e & " (invalid data!)"
 
 type
   pbyteArray = ptr array[0.. 0xffff, byte]