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,22 +40,26 @@ 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:
## .. code-block:: Nim import sugar
## for i in countup(3, 7): let x = collect(newSeq):
## echo i # => 3; 4; 5; 6; 7 for i in countup(3, 7):
## i
## for i in countup(2, 9, 3):
## echo i # => 2; 5; 8 assert x == @[3, 4, 5, 6, 7]
let y = collect(newseq):
for i in countup(2, 9, 3):
i
assert y == @[2, 5, 8]
mixin inc mixin inc
when T is IntLikeForCount and T is Ordinal: when T is IntLikeForCount and T is Ordinal:
var res = int(a) var res = int(a)
@ -68,10 +77,14 @@ when defined(nimNewRoof):
## ##
## See also: ## See also:
## * [..<](#..<.i,T,T) ## * [..<](#..<.i,T,T)
## runnableExamples:
## .. code-block:: Nim import sugar
## for i in 3 .. 7:
## echo i # => 3; 4; 5; 6; 7 let x = collect(newSeq):
for i in 3 .. 7:
i
assert x == @[3, 4, 5, 6, 7]
mixin inc mixin inc
when T is IntLikeForCount and T is Ordinal: when T is IntLikeForCount and T is Ordinal:
var res = int(a) var res = int(a)
@ -86,7 +99,7 @@ when defined(nimNewRoof):
template dotdotImpl(t) {.dirty.} = template dotdotImpl(t) {.dirty.} =
iterator `..`*(a, b: t): t {.inline.} = iterator `..`*(a, b: t): t {.inline.} =
## A type specialized version of ``..`` for convenience so that ## A type specialized version of `..` for convenience so that
## mixing integer types works better. ## mixing integer types works better.
## ##
## See also: ## See also:
@ -110,7 +123,7 @@ when defined(nimNewRoof):
template dotdotLessImpl(t) {.dirty.} = template dotdotLessImpl(t) {.dirty.} =
iterator `..<`*(a, b: t): t {.inline.} = iterator `..<`*(a, b: t): t {.inline.} =
## A type specialized version of ``..<`` for convenience so that ## A type specialized version of `..<` for convenience so that
## mixing integer types works better. ## mixing integer types works better.
var res = a var res = a
while res < b: while res < b:
@ -122,62 +135,6 @@ when defined(nimNewRoof):
dotdotLessImpl(uint64) dotdotLessImpl(uint64)
dotdotLessImpl(uint32) 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
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.} =
## OpenMP parallel loop iterator. Same as `..` but the loop may run in parallel. ## OpenMP parallel loop iterator. Same as `..` but the loop may run in parallel.
@ -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