summary refs log tree commit diff stats
diff options
context:
space:
mode:
-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
-rwxr-xr-xlib/core/typeinfo.nim9
-rwxr-xr-xlib/pure/marshal.nim222
-rw-r--r--lib/pure/unicode.nim6
-rwxr-xr-xlib/system/hti.nim4
-rwxr-xr-xlib/windows/windows.nim13
-rwxr-xr-xlib/wrappers/sdl/sdl.nim4
-rw-r--r--tests/reject/tenummix.nim2
12 files changed, 151 insertions, 139 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
diff --git a/lib/core/typeinfo.nim b/lib/core/typeinfo.nim
index ca2b68cc3..549e4724a 100755
--- a/lib/core/typeinfo.nim
+++ b/lib/core/typeinfo.nim
@@ -43,8 +43,13 @@ type
     akFloat = 36,       ## any represents a float
     akFloat32 = 37,     ## any represents a float32
     akFloat64 = 38,     ## any represents a float64
-    akFloat128 = 39     ## any represents a float128
-
+    akFloat128 = 39,    ## any represents a float128
+    akUInt = 40,        ## any represents an unsigned int
+    akUInt8 = 41,       ## any represents an unsigned int8
+    akUInt16 = 42,      ## any represents an unsigned in16
+    akUInt32 = 43,      ## any represents an unsigned int32
+    akUInt64 = 44,      ## any represents an unsigned int64
+    
   TAny* = object {.pure.} ## can represent any nimrod value; NOTE: the wrapped
                           ## value can be modified with its wrapper! This means
                           ## that ``TAny`` keeps a non-traced pointer to its
diff --git a/lib/pure/marshal.nim b/lib/pure/marshal.nim
index fd67fb849..e8c30331a 100755
--- a/lib/pure/marshal.nim
+++ b/lib/pure/marshal.nim
@@ -8,25 +8,25 @@
 #

 

 ## This module contains procs for serialization and deseralization of 

-## arbitrary Nimrod data structures. The serialization format uses JSON.
-##
-## **Restriction**: For objects their type is **not** serialized. This means
-## essentially that it does not work if the object has some other runtime
-## type than its compiletime type:
-##
-## .. code-block:: nimrod
-## 
-##   type 
-##     TA = object
-##     TB = object of TA
-##       f: int
-##
-##   var
-##     a: ref TA
-##     b: ref TB
-##
-##   new(b)
-##   a = b
+## arbitrary Nimrod data structures. The serialization format uses JSON.

+##

+## **Restriction**: For objects their type is **not** serialized. This means

+## essentially that it does not work if the object has some other runtime

+## type than its compiletime type:

+##

+## .. code-block:: nimrod

+## 

+##   type 

+##     TA = object

+##     TB = object of TA

+##       f: int

+##

+##   var

+##     a: ref TA

+##     b: ref TB

+##

+##   new(b)

+##   a = b

 ##   echo($$a[]) # produces "{}", not "{f: 0}"

 

 import streams, typeinfo, json, intsets, tables

@@ -86,7 +86,7 @@ proc storeAny(s: PStream, a: TAny, stored: var TIntSet) =
     var x = getString(a)

     if IsNil(x): s.write("null")

     else: s.write(escapeJson(x))

-  of akInt..akInt64: s.write($getBiggestInt(a))

+  of akInt..akInt64, akUInt..akUInt64: s.write($getBiggestInt(a))

   of akFloat..akFloat128: s.write($getBiggestFloat(a))

 

 proc loadAny(p: var TJsonParser, a: TAny, t: var TTable[biggestInt, pointer]) =

@@ -128,18 +128,18 @@ proc loadAny(p: var TJsonParser, a: TAny, t: var TTable[biggestInt, pointer]) =
       next(p)

     of jsonArrayStart:

       next(p)

-      invokeNewSeq(a, 0)
-      var i = 0
+      invokeNewSeq(a, 0)

+      var i = 0

       while p.kind != jsonArrayEnd and p.kind != jsonEof:

-        extendSeq(a)
+        extendSeq(a)

         loadAny(p, a[i], t)

         inc(i)

       if p.kind == jsonArrayEnd: next(p)

       else: raiseParseErr(p, "")

-    else:
+    else:

       raiseParseErr(p, "'[' expected for a seq")

   of akObject, akTuple:

-    if a.kind == akObject: setObjectRuntimeType(a)
+    if a.kind == akObject: setObjectRuntimeType(a)

     if p.kind != jsonObjectStart: raiseParseErr(p, "'{' expected for an object")

     next(p)

     while p.kind != jsonObjectEnd and p.kind != jsonEof:

@@ -169,13 +169,13 @@ proc loadAny(p: var TJsonParser, a: TAny, t: var TTable[biggestInt, pointer]) =
       next(p)

     of jsonArrayStart:

       next(p)

-      if a.kind == akRef: invokeNew(a)
-      else: setPointer(a, alloc0(a.baseTypeSize))      
-      if p.kind == jsonInt:
-        t[p.getInt] = getPointer(a)
-        next(p)
-      else: raiseParseErr(p, "index for ref type expected")
-      loadAny(p, a[], t)
+      if a.kind == akRef: invokeNew(a)

+      else: setPointer(a, alloc0(a.baseTypeSize))      

+      if p.kind == jsonInt:

+        t[p.getInt] = getPointer(a)

+        next(p)

+      else: raiseParseErr(p, "index for ref type expected")

+      loadAny(p, a[], t)

       if p.kind == jsonArrayEnd: next(p)

       else: raiseParseErr(p, "']' end of ref-address pair expected")

     else: raiseParseErr(p, "int for pointer type expected")

@@ -197,7 +197,7 @@ proc loadAny(p: var TJsonParser, a: TAny, t: var TTable[biggestInt, pointer]) =
       setString(a, p.str)

       next(p)

     else: raiseParseErr(p, "string expected")

-  of akInt..akInt64: 

+  of akInt..akInt64, akUInt..akUInt64: 

     if p.kind == jsonInt:

       setBiggestInt(a, getInt(p))

       next(p)

@@ -208,7 +208,7 @@ proc loadAny(p: var TJsonParser, a: TAny, t: var TTable[biggestInt, pointer]) =
       setBiggestFloat(a, getFloat(p))

       next(p)

       return

-    raiseParseErr(p, "float expected")
+    raiseParseErr(p, "float expected")

   of akRange: loadAny(p, a.skipRange, t)

 

 proc loadAny(s: PStream, a: TAny, t: var TTable[biggestInt, pointer]) =

@@ -220,7 +220,7 @@ proc loadAny(s: PStream, a: TAny, t: var TTable[biggestInt, pointer]) =
 

 proc load*[T](s: PStream, data: var T) =

   ## loads `data` from the stream `s`. Raises `EIO` in case of an error.

-  var tab = initTable[biggestInt, pointer]()
+  var tab = initTable[biggestInt, pointer]()

   loadAny(s, toAny(data), tab)

 

 proc store*[T](s: PStream, data: T) =

@@ -229,91 +229,91 @@ proc store*[T](s: PStream, data: T) =
   var d: T

   shallowCopy(d, data)

   storeAny(s, toAny(d), stored)

-
-proc `$$`*[T](x: T): string =
-  ## returns a string representation of `x`.
+

+proc `$$`*[T](x: T): string =

+  ## returns a string representation of `x`.

   var stored = initIntSet()

   var d: T

   shallowCopy(d, x)

-  var s = newStringStream()
+  var s = newStringStream()

   storeAny(s, toAny(d), stored)

-  result = s.data
-
-proc to*[T](data: string): T =
-  ## reads data and transforms it to a ``T``.
-  var tab = initTable[biggestInt, pointer]()
+  result = s.data

+

+proc to*[T](data: string): T =

+  ## reads data and transforms it to a ``T``.

+  var tab = initTable[biggestInt, pointer]()

   loadAny(newStringStream(data), toAny(result), tab)

   

-when isMainModule:
-  template testit(x: expr) = echo($$to[type(x)]($$x))
-
+when isMainModule:

+  template testit(x: expr) = echo($$to[type(x)]($$x))

+

   var x: array[0..4, array[0..4, string]] = [

     ["test", "1", "2", "3", "4"], ["test", "1", "2", "3", "4"], 

     ["test", "1", "2", "3", "4"], ["test", "1", "2", "3", "4"], 

     ["test", "1", "2", "3", "4"]]

   testit(x)

-  var test2: tuple[name: string, s: int] = ("tuple test", 56)
-  testit(test2)
-  
-  type
-    TE = enum
-      blah, blah2
-  
-    TestObj = object
-      test, asd: int
-      case test2: TE
-      of blah:
-        help: string
-      else:
-        nil
-        
-    PNode = ref TNode
-    TNode = object
-      next, prev: PNode
-      data: string
-
-  proc buildList(): PNode =
-    new(result)
-    new(result.next)
-    new(result.prev)
-    result.data = "middle"
-    result.next.data = "next"
-    result.prev.data = "prev"
-    result.next.next = result.prev
-    result.next.prev = result
-    result.prev.next = result
-    result.prev.prev = result.next
-
-  var test3: TestObj
-  test3.test = 42
-  test3.test2 = blah
-  testit(test3)
-
-  var test4: ref tuple[a, b: string]
-  new(test4)
-  test4.a = "ref string test: A"
-  test4.b = "ref string test: B"
-  testit(test4)
-  
-  var test5 = @[(0,1),(2,3),(4,5)]
-  testit(test5)
-
-  var test6: set[char] = {'A'..'Z', '_'}
-  testit(test6)
-
-  var test7 = buildList()
-  echo($$test7)
-  testit(test7)
-
-  type 
-    TA = object
-    TB = object of TA
-      f: int
-
-  var
-    a: ref TA
-    b: ref TB
-  new(b)
-  a = b
+  var test2: tuple[name: string, s: int] = ("tuple test", 56)

+  testit(test2)

+  

+  type

+    TE = enum

+      blah, blah2

+  

+    TestObj = object

+      test, asd: int

+      case test2: TE

+      of blah:

+        help: string

+      else:

+        nil

+        

+    PNode = ref TNode

+    TNode = object

+      next, prev: PNode

+      data: string

+

+  proc buildList(): PNode =

+    new(result)

+    new(result.next)

+    new(result.prev)

+    result.data = "middle"

+    result.next.data = "next"

+    result.prev.data = "prev"

+    result.next.next = result.prev

+    result.next.prev = result

+    result.prev.next = result

+    result.prev.prev = result.next

+

+  var test3: TestObj

+  test3.test = 42

+  test3.test2 = blah

+  testit(test3)

+

+  var test4: ref tuple[a, b: string]

+  new(test4)

+  test4.a = "ref string test: A"

+  test4.b = "ref string test: B"

+  testit(test4)

+  

+  var test5 = @[(0,1),(2,3),(4,5)]

+  testit(test5)

+

+  var test6: set[char] = {'A'..'Z', '_'}

+  testit(test6)

+

+  var test7 = buildList()

+  echo($$test7)

+  testit(test7)

+

+  type 

+    TA = object

+    TB = object of TA

+      f: int

+

+  var

+    a: ref TA

+    b: ref TB

+  new(b)

+  a = b

   echo($$a[]) # produces "{}", not "{f: 0}"

-
+

diff --git a/lib/pure/unicode.nim b/lib/pure/unicode.nim
index e11cd5fe3..f76573788 100644
--- a/lib/pure/unicode.nim
+++ b/lib/pure/unicode.nim
@@ -18,9 +18,9 @@ type
   TRune* = distinct irune   ## type that can hold any Unicode character
   TRune16* = distinct int16 ## 16 bit Unicode character
   
-proc `<=%`*(a, b: TRune): bool {.borrow.}
-proc `<%`*(a, b: TRune): bool {.borrow.}
-proc `==`*(a, b: TRune): bool {.borrow.}
+proc `<=%`*(a, b: TRune): bool = return int(a) <=% int(b)
+proc `<%`*(a, b: TRune): bool = return int(a) <% int(b)
+proc `==`*(a, b: TRune): bool = return int(a) == int(b)
 
 template ones(n: expr): expr = ((1 shl n)-1)
 
diff --git a/lib/system/hti.nim b/lib/system/hti.nim
index 1d62b910a..d79679107 100755
--- a/lib/system/hti.nim
+++ b/lib/system/hti.nim
@@ -37,7 +37,9 @@ type # This should be he same as ast.TTypeKind
     tyPointer, tyOpenArray,
     tyString, tyCString, tyForward,
     tyInt, tyInt8, tyInt16, tyInt32, tyInt64,
-    tyFloat, tyFloat32, tyFloat64, tyFloat128
+    tyFloat, tyFloat32, tyFloat64, tyFloat128,
+    tyUInt, tyUInt8, tyUInt16, tyUInt32, tyUInt64,
+    tyBigNum,
 
   TNimNodeKind = enum nkNone, nkSlot, nkList, nkCase
   TNimNode {.codegenType, final.} = object
diff --git a/lib/windows/windows.nim b/lib/windows/windows.nim
index d96c2bbed..9f7fd2d85 100755
--- a/lib/windows/windows.nim
+++ b/lib/windows/windows.nim
@@ -41,10 +41,6 @@ type  # WinNT.h -- Defines the 32-Bit Windows types and constants
 

 type  # BaseTsd.h -- Type definitions for the basic sized types

       # Give here only the bare minimum, to be expanded as needs arise

-  UINT8* = int8

-  UINT16* = int16

-  UINT32* = int32

-  UINT64* = int64

   LONG32* = int32

   ULONG32* = int32

   DWORD32* = int32

@@ -95,7 +91,6 @@ type  # WinDef.h -- Basic Windows Type Definitions
   LPCVOID* = pointer

 

   # INT* = int  # Cannot work and not necessary anyway

-  UINT* = int

   PUINT* = ptr int

 

   WPARAM* = LONG_PTR

@@ -18518,9 +18513,9 @@ proc DisableThreadLibraryCalls*(hLibModule: HMODULE): WINBOOL{.stdcall,
 proc GetProcAddress*(hModule: HINST, lpProcName: LPCSTR): FARPROC{.stdcall,

     dynlib: "kernel32", importc: "GetProcAddress".}

 proc GetVersion*(): DWORD{.stdcall, dynlib: "kernel32", importc: "GetVersion".}

-proc GlobalAlloc*(uFlags: UINT, dwBytes: DWORD): HGLOBAL{.stdcall,

+proc GlobalAlloc*(uFlags: INT, dwBytes: DWORD): HGLOBAL{.stdcall,

     dynlib: "kernel32", importc: "GlobalAlloc".}

-proc GlobalReAlloc*(hMem: HGLOBAL, dwBytes: DWORD, uFlags: UINT): HGLOBAL{.

+proc GlobalReAlloc*(hMem: HGLOBAL, dwBytes: DWORD, uFlags: INT): HGLOBAL{.

     stdcall, dynlib: "kernel32", importc: "GlobalReAlloc".}

 proc GlobalSize*(hMem: HGLOBAL): DWORD{.stdcall, dynlib: "kernel32",

                                         importc: "GlobalSize".}

@@ -23620,8 +23615,8 @@ proc ListView_SetItemPosition32(hwndLV: HWND, i, x, y: int32): LRESULT =
 

 proc ListView_SetItemState(hwndLV: HWND, i, data, mask: int32): LRESULT =

   var gnu_lvi: LV_ITEM

-  gnu_lvi.stateMask = mask

-  gnu_lvi.state = data

+  gnu_lvi.stateMask = uint(mask)

+  gnu_lvi.state = uint(data)

   result = SendMessage(hwndLV, LVM_SETITEMSTATE, WPARAM(i),

                        cast[LPARAM](addr(gnu_lvi)))

 

diff --git a/lib/wrappers/sdl/sdl.nim b/lib/wrappers/sdl/sdl.nim
index cf4eb452d..a48cb59ef 100755
--- a/lib/wrappers/sdl/sdl.nim
+++ b/lib/wrappers/sdl/sdl.nim
@@ -756,9 +756,7 @@ type
   PUInt8Array* = ptr TUInt8Array
   TUInt8Array* = array[0..high(int) shr 1, byte]
   PUInt16* = ptr UInt16
-  UInt16* = int16
-  PUInt32* = ptr int32
-  UInt32* = int32
+  PUInt32* = ptr UInt32
   PUInt64* = ptr UInt64
   UInt64*{.final.} = object 
     hi*: int32
diff --git a/tests/reject/tenummix.nim b/tests/reject/tenummix.nim
index f32eb82a7..8965ab3c3 100644
--- a/tests/reject/tenummix.nim
+++ b/tests/reject/tenummix.nim
@@ -1,6 +1,6 @@
 discard """
   file: "system.nim"
-  line: 640
+  line: 678
   errormsg: "type mismatch"
 """