clean up old codes (#16284)

* clean up old codes

* fix docs and links

* clean
This commit is contained in:
flywind 2020-12-09 19:18:32 +08:00 • committed by GitHub
commit 9ce2f87a0a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 103 additions and 147 deletions

View file

@ -58,7 +58,6 @@ proc initDefines*(symbols: StringTableRef) =
defineSymbol("nimGenericInOutFlags") defineSymbol("nimGenericInOutFlags")
when false: defineSymbol("nimHasOpt") when false: defineSymbol("nimHasOpt")
defineSymbol("nimNoArrayToCstringConversion") defineSymbol("nimNoArrayToCstringConversion")
defineSymbol("nimNewRoof")
defineSymbol("nimHasRunnableExamples") defineSymbol("nimHasRunnableExamples")
defineSymbol("nimNewDot") defineSymbol("nimNewDot")
defineSymbol("nimHasNilChecks") defineSymbol("nimHasNilChecks")

View file

@ -9,15 +9,20 @@ iterator countdown*[T](a, b: T, step: Positive = 1): T {.inline.} =
## ##
## `T` may be any ordinal type, `step` may only be positive. ## `T` may be any ordinal type, `step` may only be positive.
## ##
## **Note**: This fails to count to ``low(int)`` if T = int for ## **Note**: This fails to count to `low(int)` if T = int for
## efficiency reasons. ## efficiency reasons.
## runnableExamples:
## .. code-block:: Nim import sugar
## for i in countdown(7, 3): let x = collect(newSeq):
## echo i # => 7; 6; 5; 4; 3 for i in countdown(7, 3):
## i
## for i in countdown(9, 2, 3):
## echo i # => 9; 6; 3 assert x == @[7, 6, 5, 4, 3]
let y = collect(newseq):
for i in countdown(9, 2, 3):
i
assert y == @[9, 6, 3]
when T is (uint|uint64): when T is (uint|uint64):
var res = a var res = a
while res >= b: while res >= b:
@ -35,148 +40,100 @@ iterator countdown*[T](a, b: T, step: Positive = 1): T {.inline.} =
yield res yield res
dec(res, step) dec(res, step)
when defined(nimNewRoof): iterator countup*[T](a, b: T, step: Positive = 1): T {.inline.} =
iterator countup*[T](a, b: T, step: Positive = 1): T {.inline.} = ## Counts from ordinal value `a` to `b` (inclusive) with the given
## Counts from ordinal value `a` to `b` (inclusive) with the given ## step count.
## step count. ##
## ## `T` may be any ordinal type, `step` may only be positive.
## `T` may be any ordinal type, `step` may only be positive. ##
## ## **Note**: This fails to count to `high(int)` if T = int for
## **Note**: This fails to count to ``high(int)`` if T = int for ## efficiency reasons.
## efficiency reasons. runnableExamples:
## import sugar
## .. code-block:: Nim let x = collect(newSeq):
## for i in countup(3, 7): for i in countup(3, 7):
## echo i # => 3; 4; 5; 6; 7 i
##
## for i in countup(2, 9, 3):
## echo i # => 2; 5; 8
mixin inc
when T is IntLikeForCount and T is Ordinal:
var res = int(a)
while res <= int(b):
yield T(res)
inc(res, step)
else:
var res = a
while res <= b:
yield res
inc(res, step)
iterator `..`*[T](a, b: T): T {.inline.} = assert x == @[3, 4, 5, 6, 7]
## An alias for `countup(a, b, 1)`.
let y = collect(newseq):
for i in countup(2, 9, 3):
i
assert y == @[2, 5, 8]
mixin inc
when T is IntLikeForCount and T is Ordinal:
var res = int(a)
while res <= int(b):
yield T(res)
inc(res, step)
else:
var res = a
while res <= b:
yield res
inc(res, step)
iterator `..`*[T](a, b: T): T {.inline.} =
## An alias for `countup(a, b, 1)`.
##
## See also:
## * [..<](#..<.i,T,T)
runnableExamples:
import sugar
let x = collect(newSeq):
for i in 3 .. 7:
i
assert x == @[3, 4, 5, 6, 7]
mixin inc
when T is IntLikeForCount and T is Ordinal:
var res = int(a)
while res <= int(b):
yield T(res)
inc(res)
else:
var res = a
while res <= b:
yield res
inc(res)
template dotdotImpl(t) {.dirty.} =
iterator `..`*(a, b: t): t {.inline.} =
## A type specialized version of `..` for convenience so that
## mixing integer types works better.
## ##
## See also: ## See also:
## * [..<](#..<.i,T,T) ## * [..<](#..<.i,T,T)
## var res = a
## .. code-block:: Nim while res <= b:
## for i in 3 .. 7: yield res
## echo i # => 3; 4; 5; 6; 7 inc(res)
mixin inc
when T is IntLikeForCount and T is Ordinal:
var res = int(a)
while res <= int(b):
yield T(res)
inc(res)
else:
var res = a
while res <= b:
yield res
inc(res)
template dotdotImpl(t) {.dirty.} = dotdotImpl(int64)
iterator `..`*(a, b: t): t {.inline.} = dotdotImpl(int32)
## A type specialized version of ``..`` for convenience so that dotdotImpl(uint64)
## mixing integer types works better. dotdotImpl(uint32)
##
## See also:
## * [..<](#..<.i,T,T)
var res = a
while res <= b:
yield res
inc(res)
dotdotImpl(int64) iterator `..<`*[T](a, b: T): T {.inline.} =
dotdotImpl(int32) mixin inc
dotdotImpl(uint64) var i = a
dotdotImpl(uint32) while i < b:
yield i
inc i
iterator `..<`*[T](a, b: T): T {.inline.} = template dotdotLessImpl(t) {.dirty.} =
mixin inc iterator `..<`*(a, b: t): t {.inline.} =
var i = a ## A type specialized version of `..<` for convenience so that
while i < b: ## mixing integer types works better.
yield i var res = a
inc i while res < b:
yield res
template dotdotLessImpl(t) {.dirty.} = inc(res)
iterator `..<`*(a, b: t): t {.inline.} =
## A type specialized version of ``..<`` for convenience so that
## mixing integer types works better.
var res = a
while res < b:
yield res
inc(res)
dotdotLessImpl(int64)
dotdotLessImpl(int32)
dotdotLessImpl(uint64)
dotdotLessImpl(uint32)
else: # not defined(nimNewRoof)
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.
##
## .. code-block:: Nim
## for i in countup(3, 7):
## echo i # => 3; 4; 5; 6; 7
##
## for i in countup(2, 9, 3):
## echo i # => 2; 5; 8
when T is IntLikeForCount and T is Ordinal:
var res = int(a)
while res <= int(b):
yield T(res)
inc(res, step)
else:
var res = T(a)
while res <= b:
yield res
inc(res, step)
iterator `..`*[S, T](a: S, b: T): T {.inline.} =
## An alias for `countup(a, b, 1)`.
##
## See also:
## * [..<](#..<.i,T,T)
##
## .. code-block:: Nim
## for i in 3 .. 7:
## echo i # => 3; 4; 5; 6; 7
mixin inc
when T is IntLikeForCount and T is Ordinal:
var res = int(a)
while res <= int(b):
yield T(res)
inc(res)
else:
var res = T(a)
while res <= b:
yield res
inc(res)
iterator `..<`*[S, T](a: S, b: T): T {.inline.} =
mixin inc
var i = T(a)
while i < b:
yield i
inc i
dotdotLessImpl(int64)
dotdotLessImpl(int32)
dotdotLessImpl(uint64)
dotdotLessImpl(uint32)
iterator `||`*[S, T](a: S, b: T, annotation: static string = "parallel for"): T {. iterator `||`*[S, T](a: S, b: T, annotation: static string = "parallel for"): T {.
inline, magic: "OmpParFor", sideEffect.} = inline, magic: "OmpParFor", sideEffect.} =
@ -189,9 +146,9 @@ iterator `||`*[S, T](a: S, b: T, annotation: static string = "parallel for"): T
## for further information. ## for further information.
## ##
## Note that the compiler maps that to ## Note that the compiler maps that to
## the ``#pragma omp parallel for`` construct of `OpenMP`:idx: and as ## the `#pragma omp parallel for` construct of `OpenMP`:idx: and as
## such isn't aware of the parallelism in your code! Be careful! Later ## such isn't aware of the parallelism in your code! Be careful! Later
## versions of ``||`` will get proper support by Nim's code generator ## versions of `||` will get proper support by Nim's code generator
## and GC. ## and GC.
discard discard
@ -207,8 +164,8 @@ iterator `||`*[S, T](a: S, b: T, step: Positive, annotation: static string = "pa
## for further information. ## for further information.
## ##
## Note that the compiler maps that to ## Note that the compiler maps that to
## the ``#pragma omp parallel for`` construct of `OpenMP`:idx: and as ## the `#pragma omp parallel for` construct of `OpenMP`:idx: and as
## such isn't aware of the parallelism in your code! Be careful! Later ## such isn't aware of the parallelism in your code! Be careful! Later
## versions of ``||`` will get proper support by Nim's code generator ## versions of `||` will get proper support by Nim's code generator
## and GC. ## and GC.
discard discard