summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2012-06-14 17:33:00 +0300
committerZahary Karadjov <zahary@gmail.com>2012-06-14 17:33:00 +0300
commitb11fe5d0b477c58524ed3fc02ede6f13acef9622 (patch)
tree04c53a9dc422f6037e6bdb0472fafeda4c103a61 /compiler
parent308cfc49b8e2d429c2f15fe13645cf2413d67582 (diff)
downloadNim-b11fe5d0b477c58524ed3fc02ede6f13acef9622.tar.gz
more uint related fixes
Diffstat (limited to 'compiler')
-rwxr-xr-xcompiler/ast.nim3
-rwxr-xr-xcompiler/ccgthreadvars.nim7
-rwxr-xr-xcompiler/lexer.nim4
-rwxr-xr-xcompiler/semexprs.nim14
-rwxr-xr-xcompiler/sigmatch.nim2
5 files changed, 21 insertions, 9 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim
index eb258e383..a99357a47 100755
--- a/compiler/ast.nim
+++ b/compiler/ast.nim
@@ -329,7 +329,8 @@ type
     tfEnumHasHoles,   # enum cannot be mapped into a range
     tfShallow,        # type can be shallow copied on assignment
     tfThread,         # proc type is marked as ``thread``
-    tfLiteral         # type represents literal value
+    tfUniIntLit       # type represents literal value that could be either
+                      # singed or unsigned integer (e.g. 100)
     tfFromGeneric     # type is an instantiation of a generic; this is needed
                       # because for instantiations of objects, structural
                       # type equality has to be used
diff --git a/compiler/ccgthreadvars.nim b/compiler/ccgthreadvars.nim
index 900343b65..4785402e7 100755
--- a/compiler/ccgthreadvars.nim
+++ b/compiler/ccgthreadvars.nim
@@ -19,9 +19,10 @@ proc AccessThreadLocalVar(p: BProc, s: PSym) =
   if emulatedThreadVars() and not p.ThreadVarAccessed:
     p.ThreadVarAccessed = true
     p.module.usesThreadVars = true
-    lineF(p, cpsLocals, "NimThreadVars* NimTV;$n")
-    lineCg(p, cpsInit, "NimTV = (NimThreadVars*) #GetThreadLocalVars();$n")
-
+    appf(p.procSec(cpsLocals), "\tNimThreadVars* NimTV;$n")
+    app(p.procSec(cpsInit),
+      ropecg(p.module, "\tNimTV = (NimThreadVars*) #GetThreadLocalVars();$n"))
+    
 var
   nimtv: PRope                 # nimrod thread vars; the struct body
   nimtvDeps: seq[PType] = @[]  # type deps: every module needs whole struct
diff --git a/compiler/lexer.nim b/compiler/lexer.nim
index 73a818e32..afa52d621 100755
--- a/compiler/lexer.nim
+++ b/compiler/lexer.nim
@@ -403,6 +403,10 @@ proc GetNumber(L: var TLexer): TToken =
       of tkInt8Lit: result.iNumber = biggestInt(int8(toU8(int(xi))))
       of tkInt16Lit: result.iNumber = biggestInt(toU16(int(xi)))
       of tkInt32Lit: result.iNumber = biggestInt(toU32(xi))
+      of tkUIntLit, tkUInt64Lit: result.iNumber = xi
+      of tkUInt8Lit: result.iNumber = biggestInt(int8(toU8(int(xi))))
+      of tkUInt16Lit: result.iNumber = biggestInt(toU16(int(xi)))
+      of tkUInt32Lit: result.iNumber = biggestInt(toU32(xi))
       of tkFloat32Lit: 
         result.fNumber = (cast[PFloat32](addr(xi)))[] 
         # note: this code is endian neutral!
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index 8910e54c2..cd97e74b1 100755
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -1283,9 +1283,9 @@ proc semMacroStmt(c: PContext, n: PNode, semCheck = true): PNode =
     GlobalError(n.info, errInvalidExpressionX, 
                 renderTree(a, {renderNoComments}))
 
-proc litIntType(kind: TTypeKind): PType =
+proc uniIntType(kind: TTypeKind): PType =
   result = getSysType(kind).copyType(getCurrOwner(), true)
-  result.flags.incl(tfLiteral)
+  result.flags.incl(tfUniIntLit)
 
 template memoize(e: expr): expr =
   var `*guard` {.global.} = false
@@ -1317,9 +1317,15 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
     if result.typ == nil: 
       let i = result.intVal
       if i >= low(int32) and i <= high(int32):
-        result.typ = litIntType(tyInt).memoize
+        if i >= 0:
+          result.typ = uniIntType(tyInt).memoize
+        else:
+          result.typ = getSysType(tyInt)
       else:
-        result.typ = litIntType(tyInt64).memoize
+        if i >= 0:
+          result.typ = uniIntType(tyInt64).memoize
+        else:
+          result.typ = getSysType(tyInt64)
   of nkInt8Lit: 
     if result.typ == nil: result.typ = getSysType(tyInt8)
   of nkInt16Lit: 
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim
index 168936ed4..7e985e981 100755
--- a/compiler/sigmatch.nim
+++ b/compiler/sigmatch.nim
@@ -164,7 +164,7 @@ proc handleRange(f, a: PType, min, max: TTypeKind): TTypeRelation =
     if k == f.kind: result = isSubtype
     elif f.kind == tyInt and k in {tyInt..tyInt32}: result = isIntConv
     elif f.kind == tyUInt and k in {tyUInt..tyUInt32}: result = isIntConv
-    elif f.kind in {tyUInt..tyUInt64} and k == tyInt and tfLiteral in a.flags:
+    elif f.kind in {tyUInt..tyUInt64} and k == tyInt and tfUniIntLit in a.flags:
       result = isIntConv
     elif k >= min and k <= max: result = isConvertible
     else: result = isNone