mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-23 15:55:23 +00:00
make countup et al take only a single type parameter in order to prevent type guesses
This commit is contained in:
@@ -17,7 +17,7 @@ type
|
||||
proc newMersenneTwister*(seed: uint32): MersenneTwister =
|
||||
result.index = 0
|
||||
result.mt[0] = seed
|
||||
for i in 1..623'u32:
|
||||
for i in 1'u32 .. 623'u32:
|
||||
result.mt[i] = (0x6c078965'u32 * (result.mt[i-1] xor (result.mt[i-1] shr 30'u32)) + i)
|
||||
|
||||
proc generateNumbers(m: var MersenneTwister) =
|
||||
|
||||
@@ -563,12 +563,12 @@ macro scanp*(input, idx: typed; pattern: varargs[untyped]): bool =
|
||||
of nnkCurlyExpr:
|
||||
if it.len == 3 and it[1].kind == nnkIntLit and it[2].kind == nnkIntLit:
|
||||
var h = newTree(nnkPar, it[0])
|
||||
for count in 2..it[1].intVal: h.add(it[0])
|
||||
for count in 2i64 .. it[1].intVal: h.add(it[0])
|
||||
for count in it[1].intVal .. it[2].intVal-1: h.add(newTree(nnkPrefix, ident"?", it[0]))
|
||||
result = atm(h, input, idx, attached)
|
||||
elif it.len == 2 and it[1].kind == nnkIntLit:
|
||||
var h = newTree(nnkPar, it[0])
|
||||
for count in 2..it[1].intVal: h.add(it[0])
|
||||
for count in 2i64 .. it[1].intVal: h.add(it[0])
|
||||
result = atm(h, input, idx, attached)
|
||||
else:
|
||||
error("invalid pattern")
|
||||
|
||||
102
lib/system.nim
102
lib/system.nim
@@ -1985,34 +1985,65 @@ iterator countdown*[T](a, b: T, step = 1): T {.inline.} =
|
||||
yield res
|
||||
dec(res, step)
|
||||
|
||||
iterator countup*[T](a, b: T, step = 1): T {.inline.} =
|
||||
## Counts from ordinal value `a` up to `b` (inclusive) with the given
|
||||
## step count. `S`, `T` may be any ordinal type, `step` may only
|
||||
## be positive. **Note**: This fails to count to ``high(int)`` if T = int for
|
||||
## efficiency reasons.
|
||||
when T is IntLikeForCount:
|
||||
var res = int(a)
|
||||
while res <= int(b):
|
||||
yield T(res)
|
||||
inc(res, step)
|
||||
else:
|
||||
var res: T = T(a)
|
||||
while res <= b:
|
||||
yield res
|
||||
inc(res, step)
|
||||
when defined(nimNewRoof):
|
||||
iterator countup*[T](a, b: T, step = 1): T {.inline.} =
|
||||
## Counts from ordinal value `a` up to `b` (inclusive) with the given
|
||||
## step count. `S`, `T` may be any ordinal type, `step` may only
|
||||
## be positive. **Note**: This fails to count to ``high(int)`` if T = int for
|
||||
## efficiency reasons.
|
||||
when T is IntLikeForCount:
|
||||
var res = int(a)
|
||||
while res <= int(b):
|
||||
yield T(res)
|
||||
inc(res, step)
|
||||
else:
|
||||
var res: T = T(a)
|
||||
while res <= b:
|
||||
yield res
|
||||
inc(res, step)
|
||||
|
||||
iterator `..`*[T](a, b: T): T {.inline.} =
|
||||
## An alias for `countup`.
|
||||
when T is IntLikeForCount:
|
||||
var res = int(a)
|
||||
while res <= int(b):
|
||||
yield T(res)
|
||||
inc(res)
|
||||
else:
|
||||
var res: T = T(a)
|
||||
while res <= b:
|
||||
yield res
|
||||
inc(res)
|
||||
else:
|
||||
iterator countup*[S, T](a: S, b: T, step = 1): T {.inline.} =
|
||||
## Counts from ordinal value `a` up to `b` (inclusive) with the given
|
||||
## step count. `S`, `T` may be any ordinal type, `step` may only
|
||||
## be positive. **Note**: This fails to count to ``high(int)`` if T = int for
|
||||
## efficiency reasons.
|
||||
when T is IntLikeForCount:
|
||||
var res = int(a)
|
||||
while res <= int(b):
|
||||
yield T(res)
|
||||
inc(res, step)
|
||||
else:
|
||||
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`.
|
||||
when T is IntLikeForCount:
|
||||
var res = int(a)
|
||||
while res <= int(b):
|
||||
yield T(res)
|
||||
inc(res)
|
||||
else:
|
||||
var res: T = T(a)
|
||||
while res <= b:
|
||||
yield res
|
||||
inc(res)
|
||||
|
||||
iterator `..`*[T](a, b: T): T {.inline.} =
|
||||
## An alias for `countup`.
|
||||
when T is IntLikeForCount:
|
||||
var res = int(a)
|
||||
while res <= int(b):
|
||||
yield T(res)
|
||||
inc(res)
|
||||
else:
|
||||
var res: T = T(a)
|
||||
while res <= b:
|
||||
yield res
|
||||
inc(res)
|
||||
|
||||
iterator `||`*[S, T](a: S, b: T, annotation=""): T {.
|
||||
inline, magic: "OmpParFor", sideEffect.} =
|
||||
@@ -3433,11 +3464,18 @@ template `..<`*(a, b: untyped): untyped =
|
||||
## a shortcut for 'a..pred(b)'.
|
||||
a .. pred(b)
|
||||
|
||||
iterator `..<`*[T](a, b: T): T =
|
||||
var i = T(a)
|
||||
while i < b:
|
||||
yield i
|
||||
inc i
|
||||
when defined(nimNewRoof):
|
||||
iterator `..<`*[T](a, b: T): T =
|
||||
var i = T(a)
|
||||
while i < b:
|
||||
yield i
|
||||
inc i
|
||||
else:
|
||||
iterator `..<`*[S, T](a: S, b: T): T =
|
||||
var i = T(a)
|
||||
while i < b:
|
||||
yield i
|
||||
inc i
|
||||
|
||||
template spliceImpl(s, a, L, b: untyped): untyped =
|
||||
# make room for additional elements or cut:
|
||||
|
||||
Reference in New Issue
Block a user