stdlib and compiler don't use .immediate anymore
This commit is contained in:
parent
9ee5b5eabc
commit
60b187513e
36 changed files with 169 additions and 172 deletions
|
|
@ -355,7 +355,7 @@ proc insert*[T](dest: var seq[T], src: openArray[T], pos=0) =
|
|||
inc(j)
|
||||
|
||||
|
||||
template filterIt*(seq1, pred: expr): expr =
|
||||
template filterIt*(seq1, pred: untyped): untyped =
|
||||
## Returns a new sequence with all the items that fulfilled the predicate.
|
||||
##
|
||||
## Unlike the `proc` version, the predicate needs to be an expression using
|
||||
|
|
@ -374,7 +374,7 @@ template filterIt*(seq1, pred: expr): expr =
|
|||
if pred: result.add(it)
|
||||
result
|
||||
|
||||
template keepItIf*(varSeq: seq, pred: expr) =
|
||||
template keepItIf*(varSeq: seq, pred: untyped) =
|
||||
## Convenience template around the ``keepIf`` proc to reduce typing.
|
||||
##
|
||||
## Unlike the `proc` version, the predicate needs to be an expression using
|
||||
|
|
@ -409,7 +409,7 @@ proc all*[T](seq1: seq[T], pred: proc(item: T): bool {.closure.}): bool =
|
|||
return false
|
||||
return true
|
||||
|
||||
template allIt*(seq1, pred: expr): bool {.immediate.} =
|
||||
template allIt*(seq1, pred: untyped): bool =
|
||||
## Checks if every item fulfills the predicate.
|
||||
##
|
||||
## Example:
|
||||
|
|
@ -440,7 +440,7 @@ proc any*[T](seq1: seq[T], pred: proc(item: T): bool {.closure.}): bool =
|
|||
return true
|
||||
return false
|
||||
|
||||
template anyIt*(seq1, pred: expr): bool {.immediate.} =
|
||||
template anyIt*(seq1, pred: untyped): bool =
|
||||
## Checks if some item fulfills the predicate.
|
||||
##
|
||||
## Example:
|
||||
|
|
@ -456,7 +456,7 @@ template anyIt*(seq1, pred: expr): bool {.immediate.} =
|
|||
break
|
||||
result
|
||||
|
||||
template toSeq*(iter: expr): expr {.immediate.} =
|
||||
template toSeq*(iter: untyped): untyped =
|
||||
## Transforms any iterator into a sequence.
|
||||
##
|
||||
## Example:
|
||||
|
|
@ -482,7 +482,7 @@ template toSeq*(iter: expr): expr {.immediate.} =
|
|||
result.add(x)
|
||||
result
|
||||
|
||||
template foldl*(sequence, operation: expr): expr =
|
||||
template foldl*(sequence, operation: untyped): untyped =
|
||||
## Template to fold a sequence from left to right, returning the accumulation.
|
||||
##
|
||||
## The sequence is required to have at least a single element. Debug versions
|
||||
|
|
@ -519,7 +519,7 @@ template foldl*(sequence, operation: expr): expr =
|
|||
result = operation
|
||||
result
|
||||
|
||||
template foldl*(sequence, operation: expr, first): expr =
|
||||
template foldl*(sequence, operation, first): untyped =
|
||||
## Template to fold a sequence from left to right, returning the accumulation.
|
||||
##
|
||||
## This version of ``foldl`` gets a starting parameter. This makes it possible
|
||||
|
|
@ -544,7 +544,7 @@ template foldl*(sequence, operation: expr, first): expr =
|
|||
result = operation
|
||||
result
|
||||
|
||||
template foldr*(sequence, operation: expr): expr =
|
||||
template foldr*(sequence, operation: untyped): untyped =
|
||||
## Template to fold a sequence from right to left, returning the accumulation.
|
||||
##
|
||||
## The sequence is required to have at least a single element. Debug versions
|
||||
|
|
@ -581,7 +581,7 @@ template foldr*(sequence, operation: expr): expr =
|
|||
result = operation
|
||||
result
|
||||
|
||||
template mapIt*(seq1, typ, op: expr): expr {.deprecated.}=
|
||||
template mapIt*(seq1, typ, op: untyped): untyped =
|
||||
## Convenience template around the ``map`` proc to reduce typing.
|
||||
##
|
||||
## The template injects the ``it`` variable which you can use directly in an
|
||||
|
|
@ -602,7 +602,7 @@ template mapIt*(seq1, typ, op: expr): expr {.deprecated.}=
|
|||
result
|
||||
|
||||
|
||||
template mapIt*(seq1, op: expr): expr =
|
||||
template mapIt*(seq1, op: untyped): untyped =
|
||||
## Convenience template around the ``map`` proc to reduce typing.
|
||||
##
|
||||
## The template injects the ``it`` variable which you can use directly in an
|
||||
|
|
@ -631,7 +631,7 @@ template mapIt*(seq1, op: expr): expr =
|
|||
result.add(op)
|
||||
result
|
||||
|
||||
template applyIt*(varSeq, op: expr) =
|
||||
template applyIt*(varSeq, op: untyped) =
|
||||
## Convenience template around the mutable ``apply`` proc to reduce typing.
|
||||
##
|
||||
## The template injects the ``it`` variable which you can use directly in an
|
||||
|
|
@ -648,7 +648,7 @@ template applyIt*(varSeq, op: expr) =
|
|||
|
||||
|
||||
|
||||
template newSeqWith*(len: int, init: expr): expr =
|
||||
template newSeqWith*(len: int, init: untyped): untyped =
|
||||
## creates a new sequence, calling `init` to initialize each value. Example:
|
||||
##
|
||||
## .. code-block::
|
||||
|
|
|
|||
|
|
@ -286,7 +286,7 @@ proc excl*[A](s: var HashSet[A], key: A) =
|
|||
var r = j # though may be adaptable to other simple sequences.
|
||||
s.data[i].hcode = 0 # mark current EMPTY
|
||||
s.data[i].key = default(type(s.data[i].key))
|
||||
doWhile ((i >= r and r > j) or (r > j and j > i) or (j > i and i >= r)):
|
||||
doWhile((i >= r and r > j) or (r > j and j > i) or (j > i and i >= r)):
|
||||
i = (i + 1) and msk # increment mod table size
|
||||
if isEmpty(s.data[i].hcode): # end of collision cluster; So all done
|
||||
return
|
||||
|
|
@ -615,7 +615,7 @@ proc card*[A](s: OrderedSet[A]): int {.inline.} =
|
|||
## <http://en.wikipedia.org/wiki/Cardinality>`_ of a set.
|
||||
result = s.counter
|
||||
|
||||
template forAllOrderedPairs(yieldStmt: stmt) {.dirty, immediate.} =
|
||||
template forAllOrderedPairs(yieldStmt: untyped) {.dirty.} =
|
||||
var h = s.first
|
||||
while h >= 0:
|
||||
var nxt = s.data[h].next
|
||||
|
|
|
|||
|
|
@ -72,14 +72,14 @@ proc rawInsert[X, A, B](t: var X, data: var KeyValuePairSeq[A, B],
|
|||
key: A, val: B, hc: Hash, h: Hash) =
|
||||
rawInsertImpl()
|
||||
|
||||
template addImpl(enlarge) {.dirty, immediate.} =
|
||||
template addImpl(enlarge) {.dirty.} =
|
||||
if mustRehash(t.dataLen, t.counter): enlarge(t)
|
||||
var hc: Hash
|
||||
var j = rawGetDeep(t, key, hc)
|
||||
rawInsert(t, t.data, key, val, hc, j)
|
||||
inc(t.counter)
|
||||
|
||||
template maybeRehashPutImpl(enlarge) {.dirty, immediate.} =
|
||||
template maybeRehashPutImpl(enlarge) {.dirty.} =
|
||||
if mustRehash(t.dataLen, t.counter):
|
||||
enlarge(t)
|
||||
index = rawGetKnownHC(t, key, hc)
|
||||
|
|
@ -87,13 +87,13 @@ template maybeRehashPutImpl(enlarge) {.dirty, immediate.} =
|
|||
rawInsert(t, t.data, key, val, hc, index)
|
||||
inc(t.counter)
|
||||
|
||||
template putImpl(enlarge) {.dirty, immediate.} =
|
||||
template putImpl(enlarge) {.dirty.} =
|
||||
var hc: Hash
|
||||
var index = rawGet(t, key, hc)
|
||||
if index >= 0: t.data[index].val = val
|
||||
else: maybeRehashPutImpl(enlarge)
|
||||
|
||||
template mgetOrPutImpl(enlarge) {.dirty, immediate.} =
|
||||
template mgetOrPutImpl(enlarge) {.dirty.} =
|
||||
var hc: Hash
|
||||
var index = rawGet(t, key, hc)
|
||||
if index < 0:
|
||||
|
|
@ -102,7 +102,7 @@ template mgetOrPutImpl(enlarge) {.dirty, immediate.} =
|
|||
# either way return modifiable val
|
||||
result = t.data[index].val
|
||||
|
||||
template hasKeyOrPutImpl(enlarge) {.dirty, immediate.} =
|
||||
template hasKeyOrPutImpl(enlarge) {.dirty.} =
|
||||
var hc: Hash
|
||||
var index = rawGet(t, key, hc)
|
||||
if index < 0:
|
||||
|
|
@ -112,7 +112,7 @@ template hasKeyOrPutImpl(enlarge) {.dirty, immediate.} =
|
|||
|
||||
proc default[T](t: typedesc[T]): T {.inline.} = discard
|
||||
|
||||
template delImpl() {.dirty, immediate.} =
|
||||
template delImpl() {.dirty.} =
|
||||
var hc: Hash
|
||||
var i = rawGet(t, key, hc)
|
||||
let msk = maxHash(t)
|
||||
|
|
@ -140,7 +140,7 @@ template delImpl() {.dirty, immediate.} =
|
|||
else:
|
||||
shallowCopy(t.data[j], t.data[i]) # data[j] will be marked EMPTY next loop
|
||||
|
||||
template clearImpl() {.dirty, immediate.} =
|
||||
template clearImpl() {.dirty.} =
|
||||
for i in 0 .. <t.data.len:
|
||||
t.data[i].hcode = 0
|
||||
t.data[i].key = default(type(t.data[i].key))
|
||||
|
|
|
|||
|
|
@ -113,8 +113,8 @@ type
|
|||
|
||||
{.deprecated: [TTable: Table, PTable: TableRef].}
|
||||
|
||||
template maxHash(t): expr {.immediate.} = high(t.data)
|
||||
template dataLen(t): expr = len(t.data)
|
||||
template maxHash(t): untyped = high(t.data)
|
||||
template dataLen(t): untyped = len(t.data)
|
||||
|
||||
include tableimpl
|
||||
|
||||
|
|
@ -135,7 +135,7 @@ proc len*[A, B](t: Table[A, B]): int =
|
|||
## returns the number of keys in `t`.
|
||||
result = t.counter
|
||||
|
||||
template get(t, key): untyped {.immediate.} =
|
||||
template get(t, key): untyped =
|
||||
## retrieves the value at ``t[key]``. The value can be modified.
|
||||
## If `key` is not in `t`, the ``KeyError`` exception is raised.
|
||||
mixin rawGet
|
||||
|
|
@ -148,7 +148,7 @@ template get(t, key): untyped {.immediate.} =
|
|||
else:
|
||||
raise newException(KeyError, "key not found")
|
||||
|
||||
template getOrDefaultImpl(t, key): untyped {.immediate.} =
|
||||
template getOrDefaultImpl(t, key): untyped =
|
||||
mixin rawGet
|
||||
var hc: Hash
|
||||
var index = rawGet(t, key, hc)
|
||||
|
|
@ -311,7 +311,7 @@ proc toTable*[A, B](pairs: openArray[(A,
|
|||
result = initTable[A, B](rightSize(pairs.len))
|
||||
for key, val in items(pairs): result[key] = val
|
||||
|
||||
template dollarImpl(): stmt {.dirty.} =
|
||||
template dollarImpl(): untyped {.dirty.} =
|
||||
if t.len == 0:
|
||||
result = "{:}"
|
||||
else:
|
||||
|
|
@ -463,7 +463,7 @@ proc clear*[A, B](t: OrderedTable[A, B] | OrderedTableRef[A, B]) =
|
|||
t.first = -1
|
||||
t.last = -1
|
||||
|
||||
template forAllOrderedPairs(yieldStmt: stmt) {.dirty, immediate.} =
|
||||
template forAllOrderedPairs(yieldStmt: untyped) {.dirty.} =
|
||||
var h = t.first
|
||||
while h >= 0:
|
||||
var nxt = t.data[h].next
|
||||
|
|
@ -649,7 +649,7 @@ proc len*[A, B](t: OrderedTableRef[A, B]): int {.inline.} =
|
|||
## returns the number of keys in `t`.
|
||||
result = t.counter
|
||||
|
||||
template forAllOrderedPairs(yieldStmt: stmt) {.dirty, immediate.} =
|
||||
template forAllOrderedPairs(yieldStmt: untyped) {.dirty.} =
|
||||
var h = t.first
|
||||
while h >= 0:
|
||||
var nxt = t.data[h].next
|
||||
|
|
@ -824,7 +824,7 @@ proc rawGet[A](t: CountTable[A], key: A): int =
|
|||
h = nextTry(h, high(t.data))
|
||||
result = -1 - h # < 0 => MISSING; insert idx = -1 - result
|
||||
|
||||
template ctget(t, key: untyped): untyped {.immediate.} =
|
||||
template ctget(t, key: untyped): untyped =
|
||||
var index = rawGet(t, key)
|
||||
if index >= 0: result = t.data[index].val
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue