diff options
-rwxr-xr-x | compiler/semexprs.nim | 2 | ||||
-rwxr-xr-x | compiler/semstmts.nim | 4 | ||||
-rwxr-xr-x | compiler/semtypes.nim | 59 | ||||
-rwxr-xr-x | lib/impure/graphics.nim | 2 | ||||
-rwxr-xr-x | lib/impure/re.nim | 18 | ||||
-rwxr-xr-x | lib/impure/zipfiles.nim | 4 | ||||
-rwxr-xr-x | lib/system.nim | 22 |
7 files changed, 55 insertions, 56 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 0e764425a..dfd637209 100755 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -138,7 +138,7 @@ const proc checkConvertible(info: TLineInfo, castDest, src: PType) = if sameType(castDest, src) and castDest.sym == src.sym: # don't annoy conversions that may be needed on another processor: - if castDest.kind notin {tyInt..tyUInt64, tyNil}: + if castDest.kind notin IntegralTypes+{tyRange}: Message(info, hintConvFromXtoItselfNotNeeded, typeToString(castDest)) return var d = skipTypes(castDest, abstractVar) diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 99b68c121..7e265d95c 100755 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -251,8 +251,8 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode = # BUGFIX: ``fitNode`` is needed here! # check type compability between def.typ and typ: if typ != nil: def = fitNode(c, typ, def) - else: typ = def.typ - else: + else: typ = skipIntLit(def.typ) + else: def = ast.emptyNode if symkind == skLet: GlobalError(a.info, errLetNeedsInit) diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 10722d853..d082f8bb9 100755 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -19,7 +19,7 @@ proc newOrPrevType(kind: TTypeKind, prev: PType, c: PContext): PType = proc newConstraint(c: PContext, k: TTypeKind): PType = result = newTypeS(tyTypeClass, c) - result.addSon(newTypeS(k, c)) + result.addSonSkipIntLit(newTypeS(k, c)) proc semEnum(c: PContext, n: PNode, prev: PType): PType = if n.sonsLen == 0: return newConstraint(c, tyEnum) @@ -37,7 +37,7 @@ proc semEnum(c: PContext, n: PNode, prev: PType): PType = if base.kind != tyEnum: localError(n.sons[0].info, errInheritanceOnlyWithEnums) counter = lastOrd(base) + 1 - addSon(result, base) + rawAddSon(result, base) for i in countup(1, sonsLen(n) - 1): case n.sons[i].kind of nkEnumFieldDef: @@ -81,7 +81,7 @@ proc semSet(c: PContext, n: PNode, prev: PType): PType = result = newOrPrevType(tySet, prev, c) if sonsLen(n) == 2: var base = semTypeNode(c, n.sons[1], nil) - addSon(result, base) + addSonSkipIntLit(result, base) if base.kind == tyGenericInst: base = lastSon(base) if base.kind != tyGenericParam: if not isOrdinalType(base): GlobalError(n.info, errOrdinalTypeExpected) @@ -94,7 +94,7 @@ proc semContainer(c: PContext, n: PNode, kind: TTypeKind, kindStr: string, result = newOrPrevType(kind, prev, c) if sonsLen(n) == 2: var base = semTypeNode(c, n.sons[1], nil) - addSon(result, base) + addSonSkipIntLit(result, base) else: GlobalError(n.info, errXExpectsOneTypeParam, kindStr) @@ -102,7 +102,7 @@ proc semAnyRef(c: PContext, n: PNode, kind: TTypeKind, prev: PType): PType = if sonsLen(n) == 1: result = newOrPrevType(kind, prev, c) var base = semTypeNode(c, n.sons[0], nil) - addSon(result, base) + addSonSkipIntLit(result, base) else: result = newConstraint(c, kind) @@ -111,14 +111,14 @@ proc semVarType(c: PContext, n: PNode, prev: PType): PType = result = newOrPrevType(tyVar, prev, c) var base = semTypeNode(c, n.sons[0], nil) if base.kind == tyVar: GlobalError(n.info, errVarVarTypeNotAllowed) - addSon(result, base) + addSonSkipIntLit(result, base) else: result = newConstraint(c, tyVar) proc semDistinct(c: PContext, n: PNode, prev: PType): PType = if sonsLen(n) == 1: result = newOrPrevType(tyDistinct, prev, c) - addSon(result, semTypeNode(c, n.sons[0], nil)) + addSonSkipIntLit(result, semTypeNode(c, n.sons[0], nil)) else: result = newConstraint(c, tyDistinct) @@ -140,7 +140,7 @@ proc semRangeAux(c: PContext, n: PNode, prev: PType): PType = if not leValue(a, b): GlobalError(n.Info, errRangeIsEmpty) addSon(result.n, a) addSon(result.n, b) - addSon(result, b.typ) + addSonSkipIntLit(result, b.typ) proc semRange(c: PContext, n: PNode, prev: PType): PType = result = nil @@ -157,7 +157,7 @@ proc semArray(c: PContext, n: PNode, prev: PType): PType = # 3 = length(array indx base) if isRange(n[1]): indx = semRangeAux(c, n[1], nil) else: indx = semTypeNode(c, n.sons[1], nil) - addSon(result, indx) + addSonSkipIntLit(result, indx) if indx.kind == tyGenericInst: indx = lastSon(indx) if indx.kind != tyGenericParam: if not isOrdinalType(indx): @@ -165,7 +165,7 @@ proc semArray(c: PContext, n: PNode, prev: PType): PType = if enumHasHoles(indx): GlobalError(n.sons[1].info, errEnumXHasHoles, indx.sym.name.s) base = semTypeNode(c, n.sons[2], nil) - addSon(result, base) + addSonSkipIntLit(result, base) else: GlobalError(n.info, errArrayExpectsTwoTypeParams) @@ -176,7 +176,7 @@ proc semOrdinal(c: PContext, n: PNode, prev: PType): PType = if base.kind != tyGenericParam: if not isOrdinalType(base): GlobalError(n.sons[1].info, errOrdinalTypeExpected) - addSon(result, base) + addSonSkipIntLit(result, base) else: GlobalError(n.info, errXExpectsOneTypeParam, "ordinal") @@ -232,7 +232,7 @@ proc semTuple(c: PContext, n: PNode, prev: PType): PType = if ContainsOrIncl(check, field.name.id): GlobalError(a.sons[j].info, errAttemptToRedefine, field.name.s) addSon(result.n, newSymNode(field)) - addSon(result, typ) + addSonSkipIntLit(result, typ) proc semIdentVis(c: PContext, kind: TSymKind, n: PNode, allowed: TSymFlags): PSym = @@ -487,7 +487,7 @@ proc semObjectNode(c: PContext, n: PNode, prev: PType): PType = localError(n.sons[1].info, errInheritanceOnlyWithNonFinalObjects) if n.kind != nkObjectTy: InternalError(n.info, "semObjectNode") result = newOrPrevType(tyObject, prev, c) - addSon(result, base) + rawAddSon(result, base) result.n = newNodeI(nkRecList, n.info) semRecordNodeAux(c, n.sons[2], check, pos, result.n, result.sym) if n.sons[0].kind != nkEmpty: @@ -537,7 +537,7 @@ proc paramTypeClass(c: PContext, paramType: PType, procKind: TSymKind): # type Foo[T] = object # proc x(a: Foo, b: Foo) result.typ = newTypeS(tyTypeClass, c) - result.typ.addSon(paramType) + result.typ.addSonSkipIntLit(paramType) result.id = paramType.sym.name # bindOnce by default of tyTypeClass: result.typ = copyType(paramType, getCurrOwner(), false) @@ -588,7 +588,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode, result.n = newNodeI(nkFormalParams, n.info) if genericParams != nil and sonsLen(genericParams) == 0: cl = initIntSet() - addSon(result, nil) # return type + rawAddSon(result, nil) # return type res = newNodeI(nkType, n.info) addSon(result.n, res) var check = initIntSet() @@ -625,7 +625,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode, for j in countup(0, length-3): var arg = newSymS(skParam, a.sons[j], c) var finalType = liftParamType(c, kind, genericParams, typ, arg.name.s, - arg.info) + arg.info).skipIntLit arg.typ = finalType arg.position = counter inc(counter) @@ -633,7 +633,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode, if ContainsOrIncl(check, arg.name.id): LocalError(a.sons[j].info, errAttemptToRedefine, arg.name.s) addSon(result.n, newSymNode(arg)) - addSon(result, finalType) + rawAddSon(result, finalType) addParamOrResult(c, arg, kind) if n.sons[0].kind != nkEmpty: @@ -643,7 +643,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode, if skipTypes(r, {tyGenericInst}).kind != tyEmpty: if r.sym == nil or sfAnon notin r.sym.flags: r = liftParamType(c, kind, genericParams, r, "result", n.sons[0].info) - result.sons[0] = r + result.sons[0] = skipIntLit(r) res.typ = result.sons[0] proc semStmtListType(c: PContext, n: PNode, prev: PType): PType = @@ -700,13 +700,14 @@ proc semGeneric(c: PContext, n: PNode, s: PSym, prev: PType): PType = InternalError(n.info, "semtypes.semGeneric") elif sonsLen(n) != sonsLen(s.typ): GlobalError(n.info, errWrongNumberOfArguments) - addSon(result, s.typ) + addSonSkipIntLit(result, s.typ) # iterate over arguments: for i in countup(1, sonsLen(n)-1): var elem = semGenericParamInInvokation(c, n.sons[i]) if containsGenericType(elem): isConcrete = false #if elem.kind in {tyGenericParam, tyGenericInvokation}: isConcrete = false - addSon(result, elem) + if elem.isNil: rawAddSon(result, elem) + else: addSonSkipIntLit(result, elem) if isConcrete: if s.ast == nil: GlobalError(n.info, errCannotInstantiateX, s.name.s) result = instGenericContainer(c, n, result) @@ -747,8 +748,8 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType = elif t2 == nil: GlobalError(n.sons[2].info, errTypeExpected) else: result = newTypeS(tyTypeClass, c) - result.addSon(t1) - result.addSon(t2) + result.addSonSkipIntLit(t1) + result.addSonSkipIntLit(t2) result.flags.incl(if op.id == ord(wAnd): tfAll else: tfAny) else: result = semTypeFromMacro(c, n) @@ -757,7 +758,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType = if result != nil: result = copyType(result, getCurrOwner(), false) for i in countup(1, n.len - 1): - result.addSon(semTypeNode(c, n.sons[i], nil)) + result.rawAddSon(semTypeNode(c, n.sons[i], nil)) of nkWhenStmt: var whenResult = semWhen(c, n, false) if whenResult.kind == nkStmtList: whenResult.kind = nkStmtListType @@ -841,14 +842,14 @@ proc processMagicType(c: PContext, m: PSym) = of mChar: setMagicType(m, tyChar, 1) of mString: setMagicType(m, tyString, ptrSize) - addSon(m.typ, getSysType(tyChar)) + rawAddSon(m.typ, getSysType(tyChar)) of mCstring: setMagicType(m, tyCString, ptrSize) - addSon(m.typ, getSysType(tyChar)) + rawAddSon(m.typ, getSysType(tyChar)) of mPointer: setMagicType(m, tyPointer, ptrSize) of mEmptySet: setMagicType(m, tySet, 1) - addSon(m.typ, newTypeS(tyEmpty, c)) + rawAddSon(m.typ, newTypeS(tyEmpty, c)) of mIntSetBaseType: setMagicType(m, tyRange, intSize) of mNil: setMagicType(m, tyNil, ptrSize) of mExpr: setMagicType(m, tyExpr, 0) @@ -869,7 +870,7 @@ proc semGenericConstraints(c: PContext, n: PNode, result: PType) = if x.kind in StructuralEquivTypes and ( sonsLen(x) == 0 or x.sons[0].kind in {tyGenericParam, tyEmpty}): x = newConstraint(c, x.kind) - result.addSon(x) + result.addSonSkipIntLit(x) proc semGenericParamList(c: PContext, n: PNode, father: PType = nil): PNode = result = copyNode(n) @@ -910,9 +911,7 @@ proc semGenericParamList(c: PContext, n: PNode, father: PType = nil): PNode = s.typ = typ if def.kind != nkEmpty: s.ast = def s.typ.sym = s - if father != nil: addSon(father, s.typ) + if father != nil: addSonSkipIntLit(father, s.typ) s.position = i addSon(result, newSymNode(s)) addDecl(c, s) - - diff --git a/lib/impure/graphics.nim b/lib/impure/graphics.nim index 1392fd903..c955d96ca 100755 --- a/lib/impure/graphics.nim +++ b/lib/impure/graphics.nim @@ -74,7 +74,7 @@ proc fontFinalizer(f: PFont) = closeFont(f.f) proc newFont*(name = "VeraMono.ttf", size = 9, color = colBlack): PFont = ## Creates a new font object. Raises ``EIO`` if the font cannot be loaded. new(result, fontFinalizer) - result.f = OpenFont(name, size) + result.f = OpenFont(name, size.cint) if result.f == nil: raise newException(EIO, "Could not open font file: " & name) result.color = toSdlColor(color) diff --git a/lib/impure/re.nim b/lib/impure/re.nim index f3a6e5a44..ebc4c549a 100755 --- a/lib/impure/re.nim +++ b/lib/impure/re.nim @@ -100,7 +100,7 @@ proc findBounds*(s: string, pattern: TRegEx, matches: var openarray[string], ## is written into `matches` and ``(-1,0)`` is returned. var rawMatches: array[0..maxSubpatterns * 3 - 1, cint] - res = pcre.Exec(pattern.h, pattern.e, s, len(s).cint, start, 0'i32, + res = pcre.Exec(pattern.h, pattern.e, s, len(s).cint, start.cint, 0'i32, cast[ptr cint](addr(rawMatches)), maxSubpatterns * 3) if res < 0'i32: return (-1, 0) for i in 1..int(res)-1: @@ -119,7 +119,7 @@ proc findBounds*(s: string, pattern: TRegEx, ## ``(-1,0)`` is returned. var rawMatches: array[0..maxSubpatterns * 3 - 1, cint] - res = pcre.Exec(pattern.h, pattern.e, s, len(s).cint, start, 0'i32, + res = pcre.Exec(pattern.h, pattern.e, s, len(s).cint, start.cint, 0'i32, cast[ptr cint](addr(rawMatches)), maxSubpatterns * 3) if res < 0'i32: return (-1, 0) for i in 1..int(res)-1: @@ -135,7 +135,7 @@ proc findBounds*(s: string, pattern: TRegEx, ## match, ``(-1,0)`` is returned. var rawMatches: array[0..3 - 1, cint] - res = pcre.Exec(pattern.h, nil, s, len(s).cint, start, 0'i32, + res = pcre.Exec(pattern.h, nil, s, len(s).cint, start.cint, 0'i32, cast[ptr cint](addr(rawMatches)), 3) if res < 0'i32: return (int(res), 0) return (int(rawMatches[0]), int(rawMatches[1]-1)) @@ -153,25 +153,25 @@ proc match*(s: string, pattern: TRegEx, matches: var openarray[string], ## the captured substrings in the array ``matches``. If it does not ## match, nothing is written into ``matches`` and ``false`` is ## returned. - return matchOrFind(s, pattern, matches, start, + return matchOrFind(s, pattern, matches, start.cint, pcre.ANCHORED) == cint(s.len - start) proc match*(s: string, pattern: TRegEx, start = 0): bool = ## returns ``true`` if ``s[start..]`` matches the ``pattern``. - return matchOrFind(s, pattern, start, pcre.ANCHORED) == cint(s.len - start) + return matchOrFind(s, pattern, start.cint, pcre.ANCHORED) == cint(s.len-start) proc matchLen*(s: string, pattern: TRegEx, matches: var openarray[string], start = 0): int = ## the same as ``match``, but it returns the length of the match, ## if there is no match, -1 is returned. Note that a match length ## of zero can happen. - return matchOrFind(s, pattern, matches, start, pcre.ANCHORED) + return matchOrFind(s, pattern, matches, start.cint, pcre.ANCHORED) proc matchLen*(s: string, pattern: TRegEx, start = 0): int = ## the same as ``match``, but it returns the length of the match, ## if there is no match, -1 is returned. Note that a match length ## of zero can happen. - return matchOrFind(s, pattern, start, pcre.ANCHORED) + return matchOrFind(s, pattern, start.cint, pcre.ANCHORED) proc find*(s: string, pattern: TRegEx, matches: var openarray[string], start = 0): int = @@ -180,7 +180,7 @@ proc find*(s: string, pattern: TRegEx, matches: var openarray[string], ## is written into ``matches`` and -1 is returned. var rawMatches: array[0..maxSubpatterns * 3 - 1, cint] - res = pcre.Exec(pattern.h, pattern.e, s, len(s).cint, start, 0'i32, + res = pcre.Exec(pattern.h, pattern.e, s, len(s).cint, start.cint, 0'i32, cast[ptr cint](addr(rawMatches)), maxSubpatterns * 3) if res < 0'i32: return res for i in 1..int(res)-1: @@ -195,7 +195,7 @@ proc find*(s: string, pattern: TRegEx, start = 0): int = ## match, -1 is returned. var rawMatches: array[0..3 - 1, cint] - res = pcre.Exec(pattern.h, nil, s, len(s).cint, start, 0'i32, + res = pcre.Exec(pattern.h, nil, s, len(s).cint, start.cint, 0'i32, cast[ptr cint](addr(rawMatches)), 3) if res < 0'i32: return res return rawMatches[0] diff --git a/lib/impure/zipfiles.nim b/lib/impure/zipfiles.nim index 36842a51b..029d8527d 100755 --- a/lib/impure/zipfiles.nim +++ b/lib/impure/zipfiles.nim @@ -137,8 +137,8 @@ proc getStream*(z: var TZipArchive, filename: string): PZipFileStream = iterator walkFiles*(z: var TZipArchive): string = ## walks over all files in the archive `z` and returns the filename ## (including the path). - var i = 0 - var num = int(zip_get_num_files(z.w)) + var i = 0'i32 + var num = zip_get_num_files(z.w) while i < num: yield $zip_get_name(z.w, i, 0'i32) inc(i) diff --git a/lib/system.nim b/lib/system.nim index 994127ea2..71dc063ca 100755 --- a/lib/system.nim +++ b/lib/system.nim @@ -55,23 +55,23 @@ type ## a type description (for templates) void* {.magic: "VoidType".} ## meta type to denote the absense of any type - TSignedInt* = distinct int|int8|int16|int32|int64 + TSignedInt* = int|int8|int16|int32|int64 ## type class matching all signed integer types - TUnsignedInt* = distinct uint|uint8|uint16|uint32|uint64 + TUnsignedInt* = uint|uint8|uint16|uint32|uint64 ## type class matching all unsigned integer types - TInteger* = distinct TSignedInt|TUnsignedInt + TInteger* = TSignedInt|TUnsignedInt ## type class matching all integer types - TOrdinal* = distinct TInteger|bool|enum + TOrdinal* = TInteger|bool|enum ## type class matching all ordinal types; however this includes enums with ## holes. - TReal* = distinct float|float32|float64 + TReal* = float|float32|float64 ## type class matching all floating point number types - TNumber* = distinct TInteger|TReal + TNumber* = TInteger|TReal ## type class matching all number types proc defined*(x: expr): bool {.magic: "Defined", noSideEffect.} @@ -1234,14 +1234,14 @@ iterator countup*[S, T](a: S, b: T, step = 1): T {.inline.} = ## Counts from ordinal value `a` up to `b` with the given ## step count. `S`, `T` may be any ordinal type, `step` may only ## be positive. - var res: T = a + var res: T = T(a) while res <= b: yield res inc(res, step) iterator `..`*[S, T](a: S, b: T): T {.inline.} = ## An alias for `countup`. - var res: T = a + var res: T = T(a) while res <= b: yield res inc res @@ -2242,13 +2242,13 @@ proc staticExec*(command: string, input = ""): string {. ## ## ``gorge`` is an alias for ``staticExec``. -proc `+=`*[T](x, y: ordinal[T]) {.magic: "Inc", noSideEffect.} +proc `+=`*[T: TOrdinal](x: var T, y: T) {.magic: "Inc", noSideEffect.} ## Increments an ordinal -proc `-=`*[T](x, y: ordinal[T]) {.magic: "Dec", noSideEffect.} +proc `-=`*[T: TOrdinal](x: var T, y: T) {.magic: "Dec", noSideEffect.} ## Decrements an ordinal -proc `*=`*[T](x: var ordinal[T], y: ordinal[T]) {.inline, noSideEffect.} = +proc `*=`*[T: TOrdinal](x: var T, y: T) {.inline, noSideEffect.} = ## Binary `*=` operator for ordinals x = x * y |