summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-07-03 00:59:36 +0200
committerAraq <rumpf_a@web.de>2012-07-03 00:59:36 +0200
commit8ef48a34e5916deccd58a312228c7d2efe39d170 (patch)
tree1b14e5b5f720b66fba11746ea5515e66c467a137 /compiler
parent2e2650c708e5ad163aac1be11e0e434cc3126e48 (diff)
downloadNim-8ef48a34e5916deccd58a312228c7d2efe39d170.tar.gz
fixes #150; next steps for proper unsigned support
Diffstat (limited to 'compiler')
-rwxr-xr-xcompiler/transf.nim3
-rwxr-xr-xcompiler/types.nim13
2 files changed, 9 insertions, 7 deletions
diff --git a/compiler/transf.nim b/compiler/transf.nim
index 7c2353c54..19530b82a 100755
--- a/compiler/transf.nim
+++ b/compiler/transf.nim
@@ -390,7 +390,8 @@ proc transformConv(c: PTransf, n: PNode): PTransNode =
   var dest = skipTypes(n.typ, abstractVarRange)
   var source = skipTypes(n.sons[1].typ, abstractVarRange)
   case dest.kind
-  of tyInt..tyInt64, tyEnum, tyChar, tyBool, tyUInt..tyUInt64: 
+  of tyInt..tyInt64, tyEnum, tyChar, tyBool, tyUInt8..tyUInt32: 
+    # we don't include uint and uint64 here as these are no ordinal types ;-)
     if not isOrdinalType(source):
       # XXX int64 -> float conversion?
       result = transformSons(c, n)
diff --git a/compiler/types.nim b/compiler/types.nim
index 88b8f5ac6..9b4b869e4 100755
--- a/compiler/types.nim
+++ b/compiler/types.nim
@@ -140,9 +140,10 @@ proc skipTypes(t: PType, kinds: TTypeKinds): PType =
   result = t
   while result.kind in kinds: result = lastSon(result)
   
-proc isOrdinalType(t: PType): bool = 
+proc isOrdinalType(t: PType): bool =
   assert(t != nil)
-  result = (t.Kind in {tyChar, tyInt..tyInt64, tyUInt..tyUInt64, tyBool, tyEnum}) or
+  # caution: uint, uint64 are no ordinal types!
+  result = t.Kind in {tyChar,tyInt..tyInt64,tyUInt8..tyUInt32,tyBool,tyEnum} or
       (t.Kind in {tyRange, tyOrdinal, tyConst, tyMutable, tyGenericInst}) and
        isOrdinalType(t.sons[0])
 
@@ -532,10 +533,10 @@ proc lastOrd(t: PType): biggestInt =
   of tyUInt: 
     if platform.intSize == 4: result = 0xFFFFFFFF
     else: result = 0x7FFFFFFFFFFFFFFF'i64
-  of tyUInt8: result = 0x7F # XXX: Fix these
-  of tyUInt16: result = 0x7FFF
-  of tyUInt32: result = 0x7FFFFFFF
-  of tyUInt64: result = 0x7FFFFFFFFFFFFFFF'i64
+  of tyUInt8: result = 0xFF
+  of tyUInt16: result = 0xFFFF
+  of tyUInt32: result = 0xFFFFFFFF
+  of tyUInt64: result = -1
   of tyEnum: 
     assert(t.n.sons[sonsLen(t.n) - 1].kind == nkSym)
     result = t.n.sons[sonsLen(t.n) - 1].sym.position