more uint related fixes

This commit is contained in:
Zahary Karadjov 2012-06-14 17:33:00 +03:00
commit b11fe5d0b4
12 changed files with 151 additions and 139 deletions

View file

@ -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

View file

@ -19,8 +19,9 @@ 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

View file

@ -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!

View file

@ -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:

View file

@ -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

View file

@ -43,7 +43,12 @@ 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

View file

@ -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]) =
@ -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)

View file

@ -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)

View file

@ -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

View file

@ -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)))

View file

@ -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

View file

@ -1,6 +1,6 @@
discard """
file: "system.nim"
line: 640
line: 678
errormsg: "type mismatch"
"""