more uint related fixes
This commit is contained in:
parent
308cfc49b8
commit
b11fe5d0b4
12 changed files with 151 additions and 139 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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!
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue