use typeof instead type (#16962)

This commit is contained in:
flywind 2021-02-08 02:46:07 -06:00 • committed by GitHub
commit d447c0fe3f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 253 additions and 253 deletions

View file

@ -147,7 +147,7 @@ proc commonType*(c: PContext; x, y: PType): PType =
# range[0..4]. But then why is (range[0..4], 6) not range[0..6]? # range[0..4]. But then why is (range[0..4], 6) not range[0..6]?
# But then why is (2,4) not range[2..4]? But I think this would break # But then why is (2,4) not range[2..4]? But I think this would break
# too much code. So ... it's the same range or the base type. This means # too much code. So ... it's the same range or the base type. This means
# type(if b: 0 else 1) == int and not range[0..1]. For now. In the long # typeof(if b: 0 else 1) == int and not range[0..1]. For now. In the long
# run people expect ranges to work properly within a tuple. # run people expect ranges to work properly within a tuple.
if not sameType(a, b): if not sameType(a, b):
result = skipTypes(a, {tyRange}).skipIntLit(c.idgen) result = skipTypes(a, {tyRange}).skipIntLit(c.idgen)

View file

@ -842,7 +842,7 @@ proc semOverloadedCallAnalyseEffects(c: PContext, n: PNode, nOrig: PNode,
# consider: 'for x in pReturningArray()' --> we don't want the restriction # consider: 'for x in pReturningArray()' --> we don't want the restriction
# to 'skIterator' anymore; skIterator is preferred in sigmatch already # to 'skIterator' anymore; skIterator is preferred in sigmatch already
# for typeof support. # for typeof support.
# for ``type(countup(1,3))``, see ``tests/ttoseq``. # for ``typeof(countup(1,3))``, see ``tests/ttoseq``.
result = semOverloadedCall(c, n, nOrig, result = semOverloadedCall(c, n, nOrig,
{skProc, skFunc, skMethod, skConverter, skMacro, skTemplate, skIterator}, flags) {skProc, skFunc, skMethod, skConverter, skMacro, skTemplate, skIterator}, flags)
else: else:

View file

@ -232,11 +232,11 @@ proc instantiateProcType(c: PContext, pt: TIdTable,
# time adding the instantiated proc params into the current scope. # time adding the instantiated proc params into the current scope.
# This is necessary, because the instantiation process may refer to # This is necessary, because the instantiation process may refer to
# these params in situations like this: # these params in situations like this:
# proc foo[Container](a: Container, b: a.type.Item): type(b.x) # proc foo[Container](a: Container, b: a.type.Item): typeof(b.x)
# #
# Alas, doing this here is probably not enough, because another # Alas, doing this here is probably not enough, because another
# proc signature could appear in the params: # proc signature could appear in the params:
# proc foo[T](a: proc (x: T, b: type(x.y)) # proc foo[T](a: proc (x: T, b: typeof(x.y))
# #
# The solution would be to move this logic into semtypinst, but # The solution would be to move this logic into semtypinst, but
# at this point semtypinst have to become part of sem, because it # at this point semtypinst have to become part of sem, because it

View file

@ -1346,7 +1346,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
r = skipIntLit(r, c.idgen) r = skipIntLit(r, c.idgen)
if kind == skIterator: if kind == skIterator:
# see tchainediterators # see tchainediterators
# in cases like iterator foo(it: iterator): type(it) # in cases like iterator foo(it: iterator): typeof(it)
# we don't need to change the return type to iter[T] # we don't need to change the return type to iter[T]
result.flags.incl tfIterator result.flags.incl tfIterator
# XXX Would be nice if we could get rid of this # XXX Would be nice if we could get rid of this
@ -1704,7 +1704,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
case n.kind case n.kind
of nkEmpty: result = n.typ of nkEmpty: result = n.typ
of nkTypeOfExpr: of nkTypeOfExpr:
# for ``type(countup(1,3))``, see ``tests/ttoseq``. # for ``typeof(countup(1,3))``, see ``tests/ttoseq``.
checkSonsLen(n, 1, c.config) checkSonsLen(n, 1, c.config)
result = semTypeof(c, n[0], prev) result = semTypeof(c, n[0], prev)
if result.kind == tyTypeDesc: result.flags.incl tfExplicit if result.kind == tyTypeDesc: result.flags.incl tfExplicit

View file

@ -791,7 +791,7 @@ when declared(float128):
proc newLit*(arg: enum): NimNode {.compileTime.} = proc newLit*(arg: enum): NimNode {.compileTime.} =
result = newCall( result = newCall(
arg.type.getTypeInst[1], arg.typeof.getTypeInst[1],
newLit(int(arg)) newLit(int(arg))
) )
@ -801,13 +801,13 @@ proc newLit*[T](s: set[T]): NimNode {.compileTime.}
proc newLit*[T: tuple](arg: T): NimNode {.compileTime.} proc newLit*[T: tuple](arg: T): NimNode {.compileTime.}
proc newLit*(arg: object): NimNode {.compileTime.} = proc newLit*(arg: object): NimNode {.compileTime.} =
result = nnkObjConstr.newTree(arg.type.getTypeInst[1]) result = nnkObjConstr.newTree(arg.typeof.getTypeInst[1])
for a, b in arg.fieldPairs: for a, b in arg.fieldPairs:
result.add nnkExprColonExpr.newTree( newIdentNode(a), newLit(b) ) result.add nnkExprColonExpr.newTree( newIdentNode(a), newLit(b) )
proc newLit*(arg: ref object): NimNode {.compileTime.} = proc newLit*(arg: ref object): NimNode {.compileTime.} =
## produces a new ref type literal node. ## produces a new ref type literal node.
result = nnkObjConstr.newTree(arg.type.getTypeInst[1]) result = nnkObjConstr.newTree(arg.typeof.getTypeInst[1])
for a, b in fieldPairs(arg[]): for a, b in fieldPairs(arg[]):
result.add nnkExprColonExpr.newTree(newIdentNode(a), newLit(b)) result.add nnkExprColonExpr.newTree(newIdentNode(a), newLit(b))

View file

@ -86,7 +86,7 @@ proc exclImpl[A](s: var HashSet[A], key: A): bool {.inline.} =
var j = i # The correctness of this depends on (h+1) in nextTry, var j = i # The correctness of this depends on (h+1) in nextTry,
var r = j # though may be adaptable to other simple sequences. var r = j # though may be adaptable to other simple sequences.
s.data[i].hcode = 0 # mark current EMPTY s.data[i].hcode = 0 # mark current EMPTY
s.data[i].key = default(type(s.data[i].key)) s.data[i].key = default(typeof(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 i = (i + 1) and msk # increment mod table size
if isEmpty(s.data[i].hcode): # end of collision cluster; So all done if isEmpty(s.data[i].hcode): # end of collision cluster; So all done

View file

@ -355,7 +355,7 @@ proc clear*[A](s: var HashSet[A]) =
s.counter = 0 s.counter = 0
for i in 0 ..< s.data.len: for i in 0 ..< s.data.len:
s.data[i].hcode = 0 s.data[i].hcode = 0
s.data[i].key = default(type(s.data[i].key)) s.data[i].key = default(typeof(s.data[i].key))
proc len*[A](s: HashSet[A]): int = proc len*[A](s: HashSet[A]): int =
## Returns the number of elements in `s`. ## Returns the number of elements in `s`.
@ -812,7 +812,7 @@ proc clear*[A](s: var OrderedSet[A]) =
for i in 0 ..< s.data.len: for i in 0 ..< s.data.len:
s.data[i].hcode = 0 s.data[i].hcode = 0
s.data[i].next = 0 s.data[i].next = 0
s.data[i].key = default(type(s.data[i].key)) s.data[i].key = default(typeof(s.data[i].key))
proc len*[A](s: OrderedSet[A]): int {.inline.} = proc len*[A](s: OrderedSet[A]): int {.inline.} =
## Returns the number of elements in `s`. ## Returns the number of elements in `s`.

View file

@ -117,8 +117,8 @@ template delImplIdx(t, i, makeEmpty, cellEmpty, cellHash) =
var j = i # The correctness of this depends on (h+1) in nextTry var j = i # The correctness of this depends on (h+1) in nextTry
var r = j # though may be adaptable to other simple sequences. var r = j # though may be adaptable to other simple sequences.
makeEmpty(i) # mark current EMPTY makeEmpty(i) # mark current EMPTY
t.data[i].key = default(type(t.data[i].key)) t.data[i].key = default(typeof(t.data[i].key))
t.data[i].val = default(type(t.data[i].val)) t.data[i].val = default(typeof(t.data[i].val))
while true: while true:
i = (i + 1) and msk # increment mod table size i = (i + 1) and msk # increment mod table size
if cellEmpty(i): # end of collision cluster; So all done if cellEmpty(i): # end of collision cluster; So all done
@ -149,8 +149,8 @@ template clearImpl() {.dirty.} =
for i in 0 ..< t.dataLen: for i in 0 ..< t.dataLen:
when compiles(t.data[i].hcode): # CountTable records don't contain a hcode when compiles(t.data[i].hcode): # CountTable records don't contain a hcode
t.data[i].hcode = 0 t.data[i].hcode = 0
t.data[i].key = default(type(t.data[i].key)) t.data[i].key = default(typeof(t.data[i].key))
t.data[i].val = default(type(t.data[i].val)) t.data[i].val = default(typeof(t.data[i].val))
t.counter = 0 t.counter = 0
template ctAnd(a, b): bool = template ctAnd(a, b): bool =
@ -161,7 +161,7 @@ template ctAnd(a, b): bool =
template initImpl(result: typed, size: int) = template initImpl(result: typed, size: int) =
let correctSize = slotsNeeded(size) let correctSize = slotsNeeded(size)
when ctAnd(declared(SharedTable), type(result) is SharedTable): when ctAnd(declared(SharedTable), typeof(result) is SharedTable):
init(result, correctSize) init(result, correctSize)
else: else:
result.counter = 0 result.counter = 0

View file

@ -338,7 +338,7 @@ else:
{.pop.} {.pop.}
proc load*[T: Trivial](location: var Atomic[T]; order: MemoryOrder = moSequentiallyConsistent): T {.inline.} = proc load*[T: Trivial](location: var Atomic[T]; order: MemoryOrder = moSequentiallyConsistent): T {.inline.} =
cast[T](atomic_load_explicit[nonAtomicType(T), type(location.value)](addr(location.value), order)) cast[T](atomic_load_explicit[nonAtomicType(T), typeof(location.value)](addr(location.value), order))
proc store*[T: Trivial](location: var Atomic[T]; desired: T; order: MemoryOrder = moSequentiallyConsistent) {.inline.} = proc store*[T: Trivial](location: var Atomic[T]; desired: T; order: MemoryOrder = moSequentiallyConsistent) {.inline.} =
atomic_store_explicit(addr(location.value), cast[nonAtomicType(T)](desired), order) atomic_store_explicit(addr(location.value), cast[nonAtomicType(T)](desired), order)
proc exchange*[T: Trivial](location: var Atomic[T]; desired: T; order: MemoryOrder = moSequentiallyConsistent): T {.inline.} = proc exchange*[T: Trivial](location: var Atomic[T]; desired: T; order: MemoryOrder = moSequentiallyConsistent): T {.inline.} =

View file

@ -446,14 +446,14 @@ proc toSockAddr*(address: IpAddress, port: Port, sa: var Sockaddr_storage,
of IpAddressFamily.IPv4: of IpAddressFamily.IPv4:
sl = sizeof(Sockaddr_in).SockLen sl = sizeof(Sockaddr_in).SockLen
let s = cast[ptr Sockaddr_in](addr sa) let s = cast[ptr Sockaddr_in](addr sa)
s.sin_family = type(s.sin_family)(toInt(AF_INET)) s.sin_family = typeof(s.sin_family)(toInt(AF_INET))
s.sin_port = port s.sin_port = port
copyMem(addr s.sin_addr, unsafeAddr address.address_v4[0], copyMem(addr s.sin_addr, unsafeAddr address.address_v4[0],
sizeof(s.sin_addr)) sizeof(s.sin_addr))
of IpAddressFamily.IPv6: of IpAddressFamily.IPv6:
sl = sizeof(Sockaddr_in6).SockLen sl = sizeof(Sockaddr_in6).SockLen
let s = cast[ptr Sockaddr_in6](addr sa) let s = cast[ptr Sockaddr_in6](addr sa)
s.sin6_family = type(s.sin6_family)(toInt(AF_INET6)) s.sin6_family = typeof(s.sin6_family)(toInt(AF_INET6))
s.sin6_port = port s.sin6_port = port
copyMem(addr s.sin6_addr, unsafeAddr address.address_v6[0], copyMem(addr s.sin6_addr, unsafeAddr address.address_v6[0],
sizeof(s.sin6_addr)) sizeof(s.sin6_addr))

View file

@ -100,7 +100,7 @@ proc some*[T](val: T): Option[T] {.inline.} =
var var
a = some("abc") a = some("abc")
b = some(42) b = some(42)
assert $type(a) == "Option[system.string]" assert $typeof(a) == "Option[system.string]"
assert b.isSome assert b.isSome
assert a.get == "abc" assert a.get == "abc"
assert $b == "Some(42)" assert $b == "Some(42)"
@ -122,7 +122,7 @@ proc none*(T: typedesc): Option[T] {.inline.} =
runnableExamples: runnableExamples:
var a = none(int) var a = none(int)
assert a.isNone assert a.isNone
assert $type(a) == "Option[system.int]" assert $typeof(a) == "Option[system.int]"
# the default is the none type # the default is the none type
discard discard

View file

@ -76,7 +76,7 @@ when defined(windows):
template check(expr) = template check(expr) =
let r = expr let r = expr
if r == cast[type(r)](0): if r == cast[typeof(r)](0):
raiseOSError(osLastError()) raiseOSError(osLastError())
else: else:

View file

@ -379,9 +379,9 @@ proc formatInt(n: SomeNumber; radix: int;
result = "0" result = "0"
else: else:
result = "" result = ""
while v > type(v)(0): while v > typeof(v)(0):
let d = v mod type(v)(radix) let d = v mod typeof(v)(radix)
v = v div type(v)(radix) v = v div typeof(v)(radix)
result.add(mkDigit(d.int, spec.typ)) result.add(mkDigit(d.int, spec.typ))
for idx in 0..<(result.len div 2): for idx in 0..<(result.len div 2):
swap result[idx], result[result.len - idx - 1] swap result[idx], result[result.len - idx - 1]

View file

@ -103,7 +103,7 @@ since (1, 1):
doAssert 12.MyInt.distinctBase == 12 doAssert 12.MyInt.distinctBase == 12
doAssert 12.distinctBase == 12 doAssert 12.distinctBase == 12
when T is distinct: when T is distinct:
distinctBase(type(a))(a) distinctBase(typeof(a))(a)
else: # avoids hint ConvFromXtoItselfNotNeeded else: # avoids hint ConvFromXtoItselfNotNeeded
a a
@ -124,7 +124,7 @@ since (1, 1):
runnableExamples: runnableExamples:
doAssert tupleLen((1, 2)) == 2 doAssert tupleLen((1, 2)) == 2
tupleLen(type(t)) tupleLen(typeof(t))
template get*(T: typedesc[tuple], i: static int): untyped = template get*(T: typedesc[tuple], i: static int): untyped =
## Returns the `i`-th element of `T`. ## Returns the `i`-th element of `T`.
@ -132,7 +132,7 @@ since (1, 1):
runnableExamples: runnableExamples:
doAssert get((int, int, float, string), 2) is float doAssert get((int, int, float, string), 2) is float
type(default(T)[i]) typeof(default(T)[i])
type StaticParam*[value: static type] = object type StaticParam*[value: static type] = object
## Used to wrap a static value in `genericParams <#genericParams.t,typedesc>`_. ## Used to wrap a static value in `genericParams <#genericParams.t,typedesc>`_.

View file

@ -20,7 +20,7 @@ template volatileLoad*[T](src: ptr T): T =
src[] src[]
else: else:
var res: T var res: T
{.emit: [res, " = (*(", type(src[]), " volatile*)", src, ");"].} {.emit: [res, " = (*(", typeof(src[]), " volatile*)", src, ");"].}
res res
template volatileStore*[T](dest: ptr T, val: T) = template volatileStore*[T](dest: ptr T, val: T) =
@ -33,4 +33,4 @@ template volatileStore*[T](dest: ptr T, val: T) =
when defined(js): when defined(js):
dest[] = val dest[] = val
else: else:
{.emit: ["*((", type(dest[]), " volatile*)(", dest, ")) = ", val, ";"].} {.emit: ["*((", typeof(dest[]), " volatile*)(", dest, ")) = ", val, ";"].}

View file

@ -11,7 +11,7 @@ runnableExamples:
z1: int8 z1: int8
let a = (1.5'f32, (b: "b2", a: "a2"), 'x', @[Foo(t: true, z1: -3), nil], [{"name": "John"}.newStringTable]) let a = (1.5'f32, (b: "b2", a: "a2"), 'x', @[Foo(t: true, z1: -3), nil], [{"name": "John"}.newStringTable])
let j = a.toJson let j = a.toJson
doAssert j.jsonTo(type(a)).toJson == j doAssert j.jsonTo(typeof(a)).toJson == j
import std/[json,strutils,tables,sets,strtabs,options] import std/[json,strutils,tables,sets,strtabs,options]
@ -42,7 +42,7 @@ type
proc isNamedTuple(T: typedesc): bool {.magic: "TypeTrait".} proc isNamedTuple(T: typedesc): bool {.magic: "TypeTrait".}
proc distinctBase(T: typedesc): typedesc {.magic: "TypeTrait".} proc distinctBase(T: typedesc): typedesc {.magic: "TypeTrait".}
template distinctBase[T](a: T): untyped = distinctBase(type(a))(a) template distinctBase[T](a: T): untyped = distinctBase(typeof(a))(a)
macro getDiscriminants(a: typedesc): seq[string] = macro getDiscriminants(a: typedesc): seq[string] =
## return the discriminant keys ## return the discriminant keys

View file

@ -45,9 +45,9 @@ template `.`*(a: Wrapnil, b): untyped =
## See top-level example. ## See top-level example.
let a1 = a # to avoid double evaluations let a1 = a # to avoid double evaluations
let a2 = a1.valueImpl let a2 = a1.valueImpl
type T = Wrapnil[type(a2.b)] type T = Wrapnil[typeof(a2.b)]
if a1.validImpl: if a1.validImpl:
when type(a2) is ref|ptr: when typeof(a2) is ref|ptr:
if a2 == nil: if a2 == nil:
default(T) default(T)
else: else:
@ -72,13 +72,13 @@ template `[]`*[I](a: Wrapnil, i: I): untyped =
# correctly will raise IndexDefect if a is valid but wraps an empty container # correctly will raise IndexDefect if a is valid but wraps an empty container
wrapnil(a1.valueImpl[i]) wrapnil(a1.valueImpl[i])
else: else:
default(Wrapnil[type(a1.valueImpl[i])]) default(Wrapnil[typeof(a1.valueImpl[i])])
template `[]`*(a: Wrapnil): untyped = template `[]`*(a: Wrapnil): untyped =
## See top-level example. ## See top-level example.
let a1 = a # to avoid double evaluations let a1 = a # to avoid double evaluations
let a2 = a1.valueImpl let a2 = a1.valueImpl
type T = Wrapnil[type(a2[])] type T = Wrapnil[typeof(a2[])]
if a1.validImpl: if a1.validImpl:
if a2 == nil: if a2 == nil:
default(T) default(T)

View file

@ -14,7 +14,7 @@
## ##
## Each module implicitly imports the System module; it must not be listed ## Each module implicitly imports the System module; it must not be listed
## explicitly. Because of this there cannot be a user-defined module named ## explicitly. Because of this there cannot be a user-defined module named
## ``system``. ## `system`.
## ##
## System module ## System module
## ============= ## =============
@ -33,7 +33,7 @@ type
char* {.magic: Char.} ## Built-in 8 bit character type (unsigned). char* {.magic: Char.} ## Built-in 8 bit character type (unsigned).
string* {.magic: String.} ## Built-in string type. string* {.magic: String.} ## Built-in string type.
cstring* {.magic: Cstring.} ## Built-in cstring (*compatible string*) type. cstring* {.magic: Cstring.} ## Built-in cstring (*compatible string*) type.
pointer* {.magic: Pointer.} ## Built-in pointer type, use the ``addr`` pointer* {.magic: Pointer.} ## Built-in pointer type, use the `addr`
## operator to get a pointer to a variable. ## operator to get a pointer to a variable.
typedesc* {.magic: TypeDesc.} ## Meta type to denote a type description. typedesc* {.magic: TypeDesc.} ## Meta type to denote a type description.
@ -140,10 +140,10 @@ when defined(nimHasRunnableExamples):
## A section you should use to mark `runnable example`:idx: code with. ## A section you should use to mark `runnable example`:idx: code with.
## ##
## - In normal debug and release builds code within ## - In normal debug and release builds code within
## a ``runnableExamples`` section is ignored. ## a `runnableExamples` section is ignored.
## - The documentation generator is aware of these examples and considers them ## - The documentation generator is aware of these examples and considers them
## part of the ``##`` doc comment. As the last step of documentation ## part of the `##` doc comment. As the last step of documentation
## generation each runnableExample is put in its own file ``$file_examples$i.nim``, ## generation each runnableExample is put in its own file `$file_examples$i.nim`,
## compiled and tested. The collected examples are ## compiled and tested. The collected examples are
## put into their own module to ensure the examples do not refer to ## put into their own module to ensure the examples do not refer to
## non-exported symbols. ## non-exported symbols.
@ -211,7 +211,7 @@ proc `addr`*[T](x: var T): ptr T {.magic: "Addr", noSideEffect.} =
proc unsafeAddr*[T](x: T): ptr T {.magic: "Addr", noSideEffect.} = proc unsafeAddr*[T](x: T): ptr T {.magic: "Addr", noSideEffect.} =
## Builtin `addr` operator for taking the address of a memory ## Builtin `addr` operator for taking the address of a memory
## location. This works even for ``let`` variables or parameters ## location. This works even for `let` variables or parameters
## for better interop with C and so it is considered even more ## for better interop with C and so it is considered even more
## unsafe than the ordinary `addr <#addr,T>`_. ## unsafe than the ordinary `addr <#addr,T>`_.
## ##
@ -227,14 +227,14 @@ when defined(nimNewTypedesc):
`static`*[T] {.magic: "Static".} `static`*[T] {.magic: "Static".}
## Meta type representing all values that can be evaluated at compile-time. ## Meta type representing all values that can be evaluated at compile-time.
## ##
## The type coercion ``static(x)`` can be used to force the compile-time ## The type coercion `static(x)` can be used to force the compile-time
## evaluation of the given expression ``x``. ## evaluation of the given expression `x`.
`type`*[T] {.magic: "Type".} `type`*[T] {.magic: "Type".}
## Meta type representing the type of all type values. ## Meta type representing the type of all type values.
## ##
## The coercion ``type(x)`` can be used to obtain the type of the given ## The coercion `type(x)` can be used to obtain the type of the given
## expression ``x``. ## expression `x`.
else: else:
proc `type`*(x: untyped): typedesc {.magic: "TypeOf", noSideEffect, compileTime.} = proc `type`*(x: untyped): typedesc {.magic: "TypeOf", noSideEffect, compileTime.} =
## Builtin `type` operator for accessing the type of an expression. ## Builtin `type` operator for accessing the type of an expression.
@ -262,8 +262,8 @@ proc internalNew*[T](a: var ref T) {.magic: "New", noSideEffect.}
when true: when true:
proc new*[T](a: var ref T, finalizer: proc (x: ref T) {.nimcall.}) {. proc new*[T](a: var ref T, finalizer: proc (x: ref T) {.nimcall.}) {.
magic: "NewFinalize", noSideEffect.} magic: "NewFinalize", noSideEffect.}
## Creates a new object of type ``T`` and returns a safe (traced) ## Creates a new object of type `T` and returns a safe (traced)
## reference to it in ``a``. ## reference to it in `a`.
## ##
## When the garbage collector frees the object, `finalizer` is called. ## When the garbage collector frees the object, `finalizer` is called.
## The `finalizer` may not keep a reference to the ## The `finalizer` may not keep a reference to the
@ -322,7 +322,7 @@ proc high*[T: Ordinal|enum|range](x: T): T {.magic: "High", noSideEffect,
proc high*[T: Ordinal|enum|range](x: typedesc[T]): T {.magic: "High", noSideEffect.} proc high*[T: Ordinal|enum|range](x: typedesc[T]): T {.magic: "High", noSideEffect.}
## Returns the highest possible value of an ordinal or enum type. ## Returns the highest possible value of an ordinal or enum type.
## ##
## ``high(int)`` is Nim's way of writing `INT_MAX`:idx: or `MAX_INT`:idx:. ## `high(int)` is Nim's way of writing `INT_MAX`:idx: or `MAX_INT`:idx:.
## ##
## See also: ## See also:
## * `low(typedesc) <#low,typedesc[T]>`_ ## * `low(typedesc) <#low,typedesc[T]>`_
@ -394,7 +394,7 @@ proc low*[T: Ordinal|enum|range](x: T): T {.magic: "Low", noSideEffect,
proc low*[T: Ordinal|enum|range](x: typedesc[T]): T {.magic: "Low", noSideEffect.} proc low*[T: Ordinal|enum|range](x: typedesc[T]): T {.magic: "Low", noSideEffect.}
## Returns the lowest possible value of an ordinal or enum type. ## Returns the lowest possible value of an ordinal or enum type.
## ##
## ``low(int)`` is Nim's way of writing `INT_MIN`:idx: or `MIN_INT`:idx:. ## `low(int)` is Nim's way of writing `INT_MIN`:idx: or `MIN_INT`:idx:.
## ##
## See also: ## See also:
## * `high(typedesc) <#high,typedesc[T]>`_ ## * `high(typedesc) <#high,typedesc[T]>`_
@ -485,10 +485,10 @@ type
HSlice*[T, U] = object ## "Heterogeneous" slice type. HSlice*[T, U] = object ## "Heterogeneous" slice type.
a*: T ## The lower bound (inclusive). a*: T ## The lower bound (inclusive).
b*: U ## The upper bound (inclusive). b*: U ## The upper bound (inclusive).
Slice*[T] = HSlice[T, T] ## An alias for ``HSlice[T, T]``. Slice*[T] = HSlice[T, T] ## An alias for `HSlice[T, T]`.
proc `..`*[T, U](a: sink T, b: sink U): HSlice[T, U] {.noSideEffect, inline, magic: "DotDot".} = proc `..`*[T, U](a: sink T, b: sink U): HSlice[T, U] {.noSideEffect, inline, magic: "DotDot".} =
## Binary `slice`:idx: operator that constructs an interval ``[a, b]``, both `a` ## Binary `slice`:idx: operator that constructs an interval `[a, b]`, both `a`
## and `b` are inclusive. ## and `b` are inclusive.
## ##
## Slices can also be used in the set constructor and in ordinal case ## Slices can also be used in the set constructor and in ordinal case
@ -500,7 +500,7 @@ proc `..`*[T, U](a: sink T, b: sink U): HSlice[T, U] {.noSideEffect, inline, mag
result = HSlice[T, U](a: a, b: b) result = HSlice[T, U](a: a, b: b)
proc `..`*[T](b: sink T): HSlice[int, T] {.noSideEffect, inline, magic: "DotDot".} = proc `..`*[T](b: sink T): HSlice[int, T] {.noSideEffect, inline, magic: "DotDot".} =
## Unary `slice`:idx: operator that constructs an interval ``[default(int), b]``. ## Unary `slice`:idx: operator that constructs an interval `[default(int), b]`.
## ##
## .. code-block:: Nim ## .. code-block:: Nim
## let a = [10, 20, 30, 40, 50] ## let a = [10, 20, 30, 40, 50]
@ -560,7 +560,7 @@ when notJSnotNims:
include "system/hti" include "system/hti"
type type
byte* = uint8 ## This is an alias for ``uint8``, that is an unsigned byte* = uint8 ## This is an alias for `uint8`, that is an unsigned
## integer, 8 bits wide. ## integer, 8 bits wide.
Natural* = range[0..high(int)] Natural* = range[0..high(int)]
@ -587,10 +587,10 @@ when defined(js) or defined(nimdoc):
## Root type of the JavaScript object hierarchy ## Root type of the JavaScript object hierarchy
proc unsafeNew*[T](a: var ref T, size: Natural) {.magic: "New", noSideEffect.} proc unsafeNew*[T](a: var ref T, size: Natural) {.magic: "New", noSideEffect.}
## Creates a new object of type ``T`` and returns a safe (traced) ## Creates a new object of type `T` and returns a safe (traced)
## reference to it in ``a``. ## reference to it in `a`.
## ##
## This is **unsafe** as it allocates an object of the passed ``size``. ## This is **unsafe** as it allocates an object of the passed `size`.
## This should only be used for optimization purposes when you know ## This should only be used for optimization purposes when you know
## what you're doing! ## what you're doing!
## ##
@ -598,17 +598,17 @@ proc unsafeNew*[T](a: var ref T, size: Natural) {.magic: "New", noSideEffect.}
## * `new <#new,ref.T,proc(ref.T)>`_ ## * `new <#new,ref.T,proc(ref.T)>`_
proc sizeof*[T](x: T): int {.magic: "SizeOf", noSideEffect.} proc sizeof*[T](x: T): int {.magic: "SizeOf", noSideEffect.}
## Returns the size of ``x`` in bytes. ## Returns the size of `x` in bytes.
## ##
## Since this is a low-level proc, ## Since this is a low-level proc,
## its usage is discouraged - using `new <#new,ref.T,proc(ref.T)>`_ for ## its usage is discouraged - using `new <#new,ref.T,proc(ref.T)>`_ for
## the most cases suffices that one never needs to know ``x``'s size. ## the most cases suffices that one never needs to know `x`'s size.
## ##
## As a special semantic rule, ``x`` may also be a type identifier ## As a special semantic rule, `x` may also be a type identifier
## (``sizeof(int)`` is valid). ## (`sizeof(int)` is valid).
## ##
## Limitations: If used for types that are imported from C or C++, ## Limitations: If used for types that are imported from C or C++,
## sizeof should fallback to the ``sizeof`` in the C compiler. The ## sizeof should fallback to the `sizeof` in the C compiler. The
## result isn't available for the Nim compiler and therefore can't ## result isn't available for the Nim compiler and therefore can't
## be used inside of macros. ## be used inside of macros.
## ##
@ -636,9 +636,9 @@ when defined(nimtypedescfixed):
proc newSeq*[T](s: var seq[T], len: Natural) {.magic: "NewSeq", noSideEffect.} proc newSeq*[T](s: var seq[T], len: Natural) {.magic: "NewSeq", noSideEffect.}
## Creates a new sequence of type ``seq[T]`` with length ``len``. ## Creates a new sequence of type `seq[T]` with length `len`.
## ##
## This is equivalent to ``s = @[]; setlen(s, len)``, but more ## This is equivalent to `s = @[]; setlen(s, len)`, but more
## efficient since no reallocation is needed. ## efficient since no reallocation is needed.
## ##
## Note that the sequence will be filled with zeroed entries. ## Note that the sequence will be filled with zeroed entries.
@ -655,7 +655,7 @@ proc newSeq*[T](s: var seq[T], len: Natural) {.magic: "NewSeq", noSideEffect.}
## #inputStrings[3] = "out of bounds" ## #inputStrings[3] = "out of bounds"
proc newSeq*[T](len = 0.Natural): seq[T] = proc newSeq*[T](len = 0.Natural): seq[T] =
## Creates a new sequence of type ``seq[T]`` with length ``len``. ## Creates a new sequence of type `seq[T]` with length `len`.
## ##
## Note that the sequence will be filled with zeroed entries. ## Note that the sequence will be filled with zeroed entries.
## After the creation of the sequence you should assign entries to ## After the creation of the sequence you should assign entries to
@ -676,8 +676,8 @@ proc newSeq*[T](len = 0.Natural): seq[T] =
proc newSeqOfCap*[T](cap: Natural): seq[T] {. proc newSeqOfCap*[T](cap: Natural): seq[T] {.
magic: "NewSeqOfCap", noSideEffect.} = magic: "NewSeqOfCap", noSideEffect.} =
## Creates a new sequence of type ``seq[T]`` with length zero and capacity ## Creates a new sequence of type `seq[T]` with length zero and capacity
## ``cap``. ## `cap`.
## ##
## .. code-block:: Nim ## .. code-block:: Nim
## var x = newSeqOfCap[int](5) ## var x = newSeqOfCap[int](5)
@ -688,7 +688,7 @@ proc newSeqOfCap*[T](cap: Natural): seq[T] {.
when not defined(js): when not defined(js):
proc newSeqUninitialized*[T: SomeNumber](len: Natural): seq[T] = proc newSeqUninitialized*[T: SomeNumber](len: Natural): seq[T] =
## Creates a new sequence of type ``seq[T]`` with length ``len``. ## Creates a new sequence of type `seq[T]` with length `len`.
## ##
## Only available for numbers types. Note that the sequence will be ## Only available for numbers types. Note that the sequence will be
## uninitialized. After the creation of the sequence you should assign ## uninitialized. After the creation of the sequence you should assign
@ -741,7 +741,7 @@ proc len*(x: cstring): int {.magic: "LengthStr", noSideEffect.} =
proc len*(x: (type array)|array): int {.magic: "LengthArray", noSideEffect.} proc len*(x: (type array)|array): int {.magic: "LengthArray", noSideEffect.}
## Returns the length of an array or an array type. ## Returns the length of an array or an array type.
## This is roughly the same as ``high(T)-low(T)+1``. ## This is roughly the same as `high(T)-low(T)+1`.
## ##
## .. code-block:: Nim ## .. code-block:: Nim
## var arr = [1, 1, 1, 1, 1] ## var arr = [1, 1, 1, 1, 1]
@ -757,7 +757,7 @@ proc len*[T](x: seq[T]): int {.magic: "LengthSeq", noSideEffect.}
proc ord*[T: Ordinal|enum](x: T): int {.magic: "Ord", noSideEffect.} proc ord*[T: Ordinal|enum](x: T): int {.magic: "Ord", noSideEffect.}
## Returns the internal `int` value of an ordinal value ``x``. ## Returns the internal `int` value of an ordinal value `x`.
## ##
## .. code-block:: Nim ## .. code-block:: Nim
## echo ord('A') # => 65 ## echo ord('A') # => 65
@ -839,7 +839,7 @@ proc `is`*[T, S](x: T, y: S): bool {.magic: "Is", noSideEffect.}
## assert(test[int](3) == 3) ## assert(test[int](3) == 3)
## assert(test[string]("xyz") == 0) ## assert(test[string]("xyz") == 0)
template `isnot`*(x, y: untyped): untyped = not (x is y) template `isnot`*(x, y: untyped): untyped = not (x is y)
## Negated version of `is <#is,T,S>`_. Equivalent to ``not(x is y)``. ## Negated version of `is <#is,T,S>`_. Equivalent to `not(x is y)`.
## ##
## .. code-block:: Nim ## .. code-block:: Nim
## assert 42 isnot float ## assert 42 isnot float
@ -852,15 +852,15 @@ else:
when defined(nimOwnedEnabled) and not defined(nimscript): when defined(nimOwnedEnabled) and not defined(nimscript):
proc new*[T](a: var owned(ref T)) {.magic: "New", noSideEffect.} proc new*[T](a: var owned(ref T)) {.magic: "New", noSideEffect.}
## Creates a new object of type ``T`` and returns a safe (traced) ## Creates a new object of type `T` and returns a safe (traced)
## reference to it in ``a``. ## reference to it in `a`.
proc new*(t: typedesc): auto = proc new*(t: typedesc): auto =
## Creates a new object of type ``T`` and returns a safe (traced) ## Creates a new object of type `T` and returns a safe (traced)
## reference to it as result value. ## reference to it as result value.
## ##
## When ``T`` is a ref type then the resulting type will be ``T``, ## When `T` is a ref type then the resulting type will be `T`,
## otherwise it will be ``ref T``. ## otherwise it will be `ref T`.
when (t is ref): when (t is ref):
var r: owned t var r: owned t
else: else:
@ -869,7 +869,7 @@ when defined(nimOwnedEnabled) and not defined(nimscript):
return r return r
proc unown*[T](x: T): T {.magic: "Unown", noSideEffect.} proc unown*[T](x: T): T {.magic: "Unown", noSideEffect.}
## Use the expression ``x`` ignoring its ownership attribute. ## Use the expression `x` ignoring its ownership attribute.
# This is only required to make 0.20 compile with the 0.19 line. # This is only required to make 0.20 compile with the 0.19 line.
template `<//>`*(t: untyped): untyped = owned(t) template `<//>`*(t: untyped): untyped = owned(t)
@ -878,15 +878,15 @@ else:
template unown*(x: typed): untyped = x template unown*(x: typed): untyped = x
proc new*[T](a: var ref T) {.magic: "New", noSideEffect.} proc new*[T](a: var ref T) {.magic: "New", noSideEffect.}
## Creates a new object of type ``T`` and returns a safe (traced) ## Creates a new object of type `T` and returns a safe (traced)
## reference to it in ``a``. ## reference to it in `a`.
proc new*(t: typedesc): auto = proc new*(t: typedesc): auto =
## Creates a new object of type ``T`` and returns a safe (traced) ## Creates a new object of type `T` and returns a safe (traced)
## reference to it as result value. ## reference to it as result value.
## ##
## When ``T`` is a ref type then the resulting type will be ``T``, ## When `T` is a ref type then the resulting type will be `T`,
## otherwise it will be ``ref T``. ## otherwise it will be `ref T`.
when (t is ref): when (t is ref):
var r: t var r: t
else: else:
@ -960,8 +960,8 @@ when defined(nimHasDefault):
## Turns an array into a sequence. ## Turns an array into a sequence.
## ##
## This most often useful for constructing ## This most often useful for constructing
## sequences with the array constructor: ``@[1, 2, 3]`` has the type ## sequences with the array constructor: `@[1, 2, 3]` has the type
## ``seq[int]``, while ``[1, 2, 3]`` has the type ``array[0..2, int]``. ## `seq[int]`, while `[1, 2, 3]` has the type `array[0..2, int]`.
## ##
## .. code-block:: Nim ## .. code-block:: Nim
## let ## let
@ -1003,10 +1003,10 @@ else:
proc setLen*[T](s: var seq[T], newlen: Natural) {. proc setLen*[T](s: var seq[T], newlen: Natural) {.
magic: "SetLengthSeq", noSideEffect.} magic: "SetLengthSeq", noSideEffect.}
## Sets the length of seq `s` to `newlen`. ``T`` may be any sequence type. ## Sets the length of seq `s` to `newlen`. `T` may be any sequence type.
## ##
## If the current length is greater than the new length, ## If the current length is greater than the new length,
## ``s`` will be truncated. ## `s` will be truncated.
## ##
## .. code-block:: Nim ## .. code-block:: Nim
## var x = @[10, 20] ## var x = @[10, 20]
@ -1021,7 +1021,7 @@ proc setLen*(s: var string, newlen: Natural) {.
## Sets the length of string `s` to `newlen`. ## Sets the length of string `s` to `newlen`.
## ##
## If the current length is greater than the new length, ## If the current length is greater than the new length,
## ``s`` will be truncated. ## `s` will be truncated.
## ##
## .. code-block:: Nim ## .. code-block:: Nim
## var myS = "Nim is great!!" ## var myS = "Nim is great!!"
@ -1030,19 +1030,19 @@ proc setLen*(s: var string, newlen: Natural) {.
proc newString*(len: Natural): string {. proc newString*(len: Natural): string {.
magic: "NewString", importc: "mnewString", noSideEffect.} magic: "NewString", importc: "mnewString", noSideEffect.}
## Returns a new string of length ``len`` but with uninitialized ## Returns a new string of length `len` but with uninitialized
## content. One needs to fill the string character after character ## content. One needs to fill the string character after character
## with the index operator ``s[i]``. ## with the index operator `s[i]`.
## ##
## This procedure exists only for optimization purposes; ## This procedure exists only for optimization purposes;
## the same effect can be achieved with the ``&`` operator or with ``add``. ## the same effect can be achieved with the `&` operator or with `add`.
proc newStringOfCap*(cap: Natural): string {. proc newStringOfCap*(cap: Natural): string {.
magic: "NewStringOfCap", importc: "rawNewString", noSideEffect.} magic: "NewStringOfCap", importc: "rawNewString", noSideEffect.}
## Returns a new string of length ``0`` but with capacity `cap`. ## Returns a new string of length `0` but with capacity `cap`.
## ##
## This procedure exists only for optimization purposes; the same effect can ## This procedure exists only for optimization purposes; the same effect can
## be achieved with the ``&`` operator or with ``add``. ## be achieved with the `&` operator or with `add`.
proc `&`*(x: string, y: char): string {. proc `&`*(x: string, y: char): string {.
magic: "ConStrStr", noSideEffect, merge.} magic: "ConStrStr", noSideEffect, merge.}
@ -1101,11 +1101,11 @@ const
CompileDate* {.magic: "CompileDate"}: string = "0000-00-00" CompileDate* {.magic: "CompileDate"}: string = "0000-00-00"
## The date (in UTC) of compilation as a string of the form ## The date (in UTC) of compilation as a string of the form
## ``YYYY-MM-DD``. This works thanks to compiler magic. ## `YYYY-MM-DD`. This works thanks to compiler magic.
CompileTime* {.magic: "CompileTime"}: string = "00:00:00" CompileTime* {.magic: "CompileTime"}: string = "00:00:00"
## The time (in UTC) of compilation as a string of the form ## The time (in UTC) of compilation as a string of the form
## ``HH:MM:SS``. This works thanks to compiler magic. ## `HH:MM:SS`. This works thanks to compiler magic.
cpuEndian* {.magic: "CpuEndian"}: Endianness = littleEndian cpuEndian* {.magic: "CpuEndian"}: Endianness = littleEndian
## The endianness of the target CPU. This is a valuable piece of ## The endianness of the target CPU. This is a valuable piece of
@ -1139,7 +1139,7 @@ const
when hasThreadSupport and defined(tcc) and not compileOption("tlsEmulation"): when hasThreadSupport and defined(tcc) and not compileOption("tlsEmulation"):
# tcc doesn't support TLS # tcc doesn't support TLS
{.error: "``--tlsEmulation:on`` must be used when using threads with tcc backend".} {.error: "`--tlsEmulation:on` must be used when using threads with tcc backend".}
when defined(boehmgc): when defined(boehmgc):
when defined(windows): when defined(windows):
@ -1195,17 +1195,17 @@ when defined(nimdoc):
## ##
## Before stopping the program the "exit procedures" are called in the ## Before stopping the program the "exit procedures" are called in the
## opposite order they were added with `addExitProc <exitprocs.html#addExitProc,proc)>`_. ## opposite order they were added with `addExitProc <exitprocs.html#addExitProc,proc)>`_.
## ``quit`` never returns and ignores any exception that may have been raised ## `quit` never returns and ignores any exception that may have been raised
## by the quit procedures. It does *not* call the garbage collector to free ## by the quit procedures. It does *not* call the garbage collector to free
## all the memory, unless a quit procedure calls `GC_fullCollect ## all the memory, unless a quit procedure calls `GC_fullCollect
## <#GC_fullCollect>`_. ## <#GC_fullCollect>`_.
## ##
## The proc ``quit(QuitSuccess)`` is called implicitly when your nim ## The proc `quit(QuitSuccess)` is called implicitly when your nim
## program finishes without incident for platforms where this is the ## program finishes without incident for platforms where this is the
## expected behavior. A raised unhandled exception is ## expected behavior. A raised unhandled exception is
## equivalent to calling ``quit(QuitFailure)``. ## equivalent to calling `quit(QuitFailure)`.
## ##
## Note that this is a *runtime* call and using ``quit`` inside a macro won't ## Note that this is a *runtime* call and using `quit` inside a macro won't
## have any compile time effect. If you need to stop the compiler inside a ## have any compile time effect. If you need to stop the compiler inside a
## macro, use the `error <manual.html#pragmas-error-pragma>`_ or `fatal ## macro, use the `error <manual.html#pragmas-error-pragma>`_ or `fatal
## <manual.html#pragmas-fatal-pragma>`_ pragmas. ## <manual.html#pragmas-fatal-pragma>`_ pragmas.
@ -1311,7 +1311,7 @@ else:
shallowCopy(a, b) shallowCopy(a, b)
proc del*[T](x: var seq[T], i: Natural) {.noSideEffect.} = proc del*[T](x: var seq[T], i: Natural) {.noSideEffect.} =
## Deletes the item at index `i` by putting ``x[high(x)]`` into position `i`. ## Deletes the item at index `i` by putting `x[high(x)]` into position `i`.
## ##
## This is an `O(1)` operation. ## This is an `O(1)` operation.
## ##
@ -1326,7 +1326,7 @@ proc del*[T](x: var seq[T], i: Natural) {.noSideEffect.} =
setLen(x, xl) setLen(x, xl)
proc delete*[T](x: var seq[T], i: Natural) {.noSideEffect.} = proc delete*[T](x: var seq[T], i: Natural) {.noSideEffect.} =
## Deletes the item at index `i` by moving all ``x[i+1..]`` items by one position. ## Deletes the item at index `i` by moving all `x[i+1..]` items by one position.
## ##
## This is an `O(n)` operation. ## This is an `O(n)` operation.
## ##
@ -1396,78 +1396,78 @@ type
BiggestFloat* = float64 BiggestFloat* = float64
## is an alias for the biggest floating point type the Nim ## is an alias for the biggest floating point type the Nim
## compiler supports. Currently this is ``float64``, but it is ## compiler supports. Currently this is `float64`, but it is
## platform-dependent in general. ## platform-dependent in general.
when defined(js): when defined(js):
type BiggestUInt* = uint32 type BiggestUInt* = uint32
## is an alias for the biggest unsigned integer type the Nim compiler ## is an alias for the biggest unsigned integer type the Nim compiler
## supports. Currently this is ``uint32`` for JS and ``uint64`` for other ## supports. Currently this is `uint32` for JS and `uint64` for other
## targets. ## targets.
else: else:
type BiggestUInt* = uint64 type BiggestUInt* = uint64
## is an alias for the biggest unsigned integer type the Nim compiler ## is an alias for the biggest unsigned integer type the Nim compiler
## supports. Currently this is ``uint32`` for JS and ``uint64`` for other ## supports. Currently this is `uint32` for JS and `uint64` for other
## targets. ## targets.
when defined(windows): when defined(windows):
type type
clong* {.importc: "long", nodecl.} = int32 clong* {.importc: "long", nodecl.} = int32
## This is the same as the type ``long`` in *C*. ## This is the same as the type `long` in *C*.
culong* {.importc: "unsigned long", nodecl.} = uint32 culong* {.importc: "unsigned long", nodecl.} = uint32
## This is the same as the type ``unsigned long`` in *C*. ## This is the same as the type `unsigned long` in *C*.
else: else:
type type
clong* {.importc: "long", nodecl.} = int clong* {.importc: "long", nodecl.} = int
## This is the same as the type ``long`` in *C*. ## This is the same as the type `long` in *C*.
culong* {.importc: "unsigned long", nodecl.} = uint culong* {.importc: "unsigned long", nodecl.} = uint
## This is the same as the type ``unsigned long`` in *C*. ## This is the same as the type `unsigned long` in *C*.
type # these work for most platforms: type # these work for most platforms:
cchar* {.importc: "char", nodecl.} = char cchar* {.importc: "char", nodecl.} = char
## This is the same as the type ``char`` in *C*. ## This is the same as the type `char` in *C*.
cschar* {.importc: "signed char", nodecl.} = int8 cschar* {.importc: "signed char", nodecl.} = int8
## This is the same as the type ``signed char`` in *C*. ## This is the same as the type `signed char` in *C*.
cshort* {.importc: "short", nodecl.} = int16 cshort* {.importc: "short", nodecl.} = int16
## This is the same as the type ``short`` in *C*. ## This is the same as the type `short` in *C*.
cint* {.importc: "int", nodecl.} = int32 cint* {.importc: "int", nodecl.} = int32
## This is the same as the type ``int`` in *C*. ## This is the same as the type `int` in *C*.
csize* {.importc: "size_t", nodecl, deprecated: "use `csize_t` instead".} = int csize* {.importc: "size_t", nodecl, deprecated: "use `csize_t` instead".} = int
## This isn't the same as ``size_t`` in *C*. Don't use it. ## This isn't the same as `size_t` in *C*. Don't use it.
csize_t* {.importc: "size_t", nodecl.} = uint csize_t* {.importc: "size_t", nodecl.} = uint
## This is the same as the type ``size_t`` in *C*. ## This is the same as the type `size_t` in *C*.
clonglong* {.importc: "long long", nodecl.} = int64 clonglong* {.importc: "long long", nodecl.} = int64
## This is the same as the type ``long long`` in *C*. ## This is the same as the type `long long` in *C*.
cfloat* {.importc: "float", nodecl.} = float32 cfloat* {.importc: "float", nodecl.} = float32
## This is the same as the type ``float`` in *C*. ## This is the same as the type `float` in *C*.
cdouble* {.importc: "double", nodecl.} = float64 cdouble* {.importc: "double", nodecl.} = float64
## This is the same as the type ``double`` in *C*. ## This is the same as the type `double` in *C*.
clongdouble* {.importc: "long double", nodecl.} = BiggestFloat clongdouble* {.importc: "long double", nodecl.} = BiggestFloat
## This is the same as the type ``long double`` in *C*. ## This is the same as the type `long double` in *C*.
## This C type is not supported by Nim's code generator. ## This C type is not supported by Nim's code generator.
cuchar* {.importc: "unsigned char", nodecl.} = char cuchar* {.importc: "unsigned char", nodecl.} = char
## This is the same as the type ``unsigned char`` in *C*. ## This is the same as the type `unsigned char` in *C*.
cushort* {.importc: "unsigned short", nodecl.} = uint16 cushort* {.importc: "unsigned short", nodecl.} = uint16
## This is the same as the type ``unsigned short`` in *C*. ## This is the same as the type `unsigned short` in *C*.
cuint* {.importc: "unsigned int", nodecl.} = uint32 cuint* {.importc: "unsigned int", nodecl.} = uint32
## This is the same as the type ``unsigned int`` in *C*. ## This is the same as the type `unsigned int` in *C*.
culonglong* {.importc: "unsigned long long", nodecl.} = uint64 culonglong* {.importc: "unsigned long long", nodecl.} = uint64
## This is the same as the type ``unsigned long long`` in *C*. ## This is the same as the type `unsigned long long` in *C*.
cstringArray* {.importc: "char**", nodecl.} = ptr UncheckedArray[cstring] cstringArray* {.importc: "char**", nodecl.} = ptr UncheckedArray[cstring]
## This is binary compatible to the type ``char**`` in *C*. The array's ## This is binary compatible to the type `char**` in *C*. The array's
## high value is large enough to disable bounds checking in practice. ## high value is large enough to disable bounds checking in practice.
## Use `cstringArrayToSeq proc <#cstringArrayToSeq,cstringArray,Natural>`_ ## Use `cstringArrayToSeq proc <#cstringArrayToSeq,cstringArray,Natural>`_
## to convert it into a ``seq[string]``. ## to convert it into a `seq[string]`.
PFloat32* = ptr float32 ## An alias for ``ptr float32``. PFloat32* = ptr float32 ## An alias for `ptr float32`.
PFloat64* = ptr float64 ## An alias for ``ptr float64``. PFloat64* = ptr float64 ## An alias for `ptr float64`.
PInt64* = ptr int64 ## An alias for ``ptr int64``. PInt64* = ptr int64 ## An alias for `ptr int64`.
PInt32* = ptr int32 ## An alias for ``ptr int32``. PInt32* = ptr int32 ## An alias for `ptr int32`.
proc toFloat*(i: int): float {.noSideEffect, inline.} = proc toFloat*(i: int): float {.noSideEffect, inline.} =
## Converts an integer `i` into a ``float``. ## Converts an integer `i` into a `float`.
## ##
## If the conversion fails, `ValueError` is raised. ## If the conversion fails, `ValueError` is raised.
## However, on most platforms the conversion cannot fail. ## However, on most platforms the conversion cannot fail.
@ -1481,11 +1481,11 @@ proc toFloat*(i: int): float {.noSideEffect, inline.} =
float(i) float(i)
proc toBiggestFloat*(i: BiggestInt): BiggestFloat {.noSideEffect, inline.} = proc toBiggestFloat*(i: BiggestInt): BiggestFloat {.noSideEffect, inline.} =
## Same as `toFloat <#toFloat,int>`_ but for ``BiggestInt`` to ``BiggestFloat``. ## Same as `toFloat <#toFloat,int>`_ but for `BiggestInt` to `BiggestFloat`.
BiggestFloat(i) BiggestFloat(i)
proc toInt*(f: float): int {.noSideEffect.} = proc toInt*(f: float): int {.noSideEffect.} =
## Converts a floating point number `f` into an ``int``. ## Converts a floating point number `f` into an `int`.
## ##
## Conversion rounds `f` half away from 0, see ## Conversion rounds `f` half away from 0, see
## `Round half away from zero ## `Round half away from zero
@ -1501,17 +1501,17 @@ proc toInt*(f: float): int {.noSideEffect.} =
if f >= 0: int(f+0.5) else: int(f-0.5) if f >= 0: int(f+0.5) else: int(f-0.5)
proc toBiggestInt*(f: BiggestFloat): BiggestInt {.noSideEffect.} = proc toBiggestInt*(f: BiggestFloat): BiggestInt {.noSideEffect.} =
## Same as `toInt <#toInt,float>`_ but for ``BiggestFloat`` to ``BiggestInt``. ## Same as `toInt <#toInt,float>`_ but for `BiggestFloat` to `BiggestInt`.
if f >= 0: BiggestInt(f+0.5) else: BiggestInt(f-0.5) if f >= 0: BiggestInt(f+0.5) else: BiggestInt(f-0.5)
proc addQuitProc*(quitProc: proc() {.noconv.}) {. proc addQuitProc*(quitProc: proc() {.noconv.}) {.
importc: "atexit", header: "<stdlib.h>", deprecated: "use exitprocs.addExitProc".} importc: "atexit", header: "<stdlib.h>", deprecated: "use exitprocs.addExitProc".}
## Adds/registers a quit procedure. ## Adds/registers a quit procedure.
## ##
## Each call to ``addQuitProc`` registers another quit procedure. Up to 30 ## Each call to `addQuitProc` registers another quit procedure. Up to 30
## procedures can be registered. They are executed on a last-in, first-out ## procedures can be registered. They are executed on a last-in, first-out
## basis (that is, the last function registered is the first to be executed). ## basis (that is, the last function registered is the first to be executed).
## ``addQuitProc`` raises an EOutOfIndex exception if ``quitProc`` cannot be ## `addQuitProc` raises an EOutOfIndex exception if `quitProc` cannot be
## registered. ## registered.
# Support for addQuitProc() is done by Ansi C's facilities here. # Support for addQuitProc() is done by Ansi C's facilities here.
# In case of an unhandled exception the exit handlers should # In case of an unhandled exception the exit handlers should
@ -1520,7 +1520,7 @@ proc addQuitProc*(quitProc: proc() {.noconv.}) {.
proc swap*[T](a, b: var T) {.magic: "Swap", noSideEffect.} proc swap*[T](a, b: var T) {.magic: "Swap", noSideEffect.}
## Swaps the values `a` and `b`. ## Swaps the values `a` and `b`.
## ##
## This is often more efficient than ``tmp = a; a = b; b = tmp``. ## This is often more efficient than `tmp = a; a = b; b = tmp`.
## Particularly useful for sorting algorithms. ## Particularly useful for sorting algorithms.
## ##
## .. code-block:: Nim ## .. code-block:: Nim
@ -1636,7 +1636,7 @@ proc isNil*(x: pointer): bool {.noSideEffect, magic: "IsNil".}
proc isNil*(x: cstring): bool {.noSideEffect, magic: "IsNil".} proc isNil*(x: cstring): bool {.noSideEffect, magic: "IsNil".}
proc isNil*[T: proc](x: T): bool {.noSideEffect, magic: "IsNil".} proc isNil*[T: proc](x: T): bool {.noSideEffect, magic: "IsNil".}
## Fast check whether `x` is nil. This is sometimes more efficient than ## Fast check whether `x` is nil. This is sometimes more efficient than
## ``== nil``. ## `== nil`.
proc `@`*[T](a: openArray[T]): seq[T] = proc `@`*[T](a: openArray[T]): seq[T] =
@ -1751,7 +1751,7 @@ proc instantiationInfo*(index = -1, fullPaths = false): tuple[
## While similar to the `caller info`:idx: of other languages, it is determined ## While similar to the `caller info`:idx: of other languages, it is determined
## at compile time. ## at compile time.
## ##
## This proc is mostly useful for meta programming (eg. ``assert`` template) ## This proc is mostly useful for meta programming (eg. `assert` template)
## to retrieve information about the current filename and line number. ## to retrieve information about the current filename and line number.
## Example: ## Example:
## ##
@ -1821,7 +1821,7 @@ when notJSnotNims and defined(nimSeqsV2):
when not defined(nimscript): when not defined(nimscript):
proc writeStackTrace*() {.tags: [], gcsafe, raises: [].} proc writeStackTrace*() {.tags: [], gcsafe, raises: [].}
## Writes the current stack trace to ``stderr``. This is only works ## Writes the current stack trace to `stderr`. This is only works
## for debug builds. Since it's usually used for debugging, this ## for debug builds. Since it's usually used for debugging, this
## is proclaimed to have no IO effect! ## is proclaimed to have no IO effect!
@ -1865,7 +1865,7 @@ proc find*[T, S](a: T, item: S): int {.inline.}=
proc contains*[T](a: openArray[T], item: T): bool {.inline.}= proc contains*[T](a: openArray[T], item: T): bool {.inline.}=
## Returns true if `item` is in `a` or false if not found. This is a shortcut ## Returns true if `item` is in `a` or false if not found. This is a shortcut
## for ``find(a, item) >= 0``. ## for `find(a, item) >= 0`.
## ##
## This allows the `in` operator: `a.contains(item)` is the same as ## This allows the `in` operator: `a.contains(item)` is the same as
## `item in a`. ## `item in a`.
@ -1878,7 +1878,7 @@ proc contains*[T](a: openArray[T], item: T): bool {.inline.}=
return find(a, item) >= 0 return find(a, item) >= 0
proc pop*[T](s: var seq[T]): T {.inline, noSideEffect.} = proc pop*[T](s: var seq[T]): T {.inline, noSideEffect.} =
## Returns the last item of `s` and decreases ``s.len`` by one. This treats ## Returns the last item of `s` and decreases `s.len` by one. This treats
## `s` as a stack and implements the common *pop* operation. ## `s` as a stack and implements the common *pop* operation.
runnableExamples: runnableExamples:
var a = @[1, 3, 5, 7] var a = @[1, 3, 5, 7]
@ -1895,14 +1895,14 @@ proc pop*[T](s: var seq[T]): T {.inline, noSideEffect.} =
setLen(s, L) setLen(s, L)
proc `==`*[T: tuple|object](x, y: T): bool = proc `==`*[T: tuple|object](x, y: T): bool =
## Generic ``==`` operator for tuples that is lifted from the components. ## Generic `==` operator for tuples that is lifted from the components.
## of `x` and `y`. ## of `x` and `y`.
for a, b in fields(x, y): for a, b in fields(x, y):
if a != b: return false if a != b: return false
return true return true
proc `<=`*[T: tuple](x, y: T): bool = proc `<=`*[T: tuple](x, y: T): bool =
## Generic lexicographic ``<=`` operator for tuples that is lifted from the ## Generic lexicographic `<=` operator for tuples that is lifted from the
## components of `x` and `y`. This implementation uses `cmp`. ## components of `x` and `y`. This implementation uses `cmp`.
for a, b in fields(x, y): for a, b in fields(x, y):
var c = cmp(a, b) var c = cmp(a, b)
@ -1911,7 +1911,7 @@ proc `<=`*[T: tuple](x, y: T): bool =
return true return true
proc `<`*[T: tuple](x, y: T): bool = proc `<`*[T: tuple](x, y: T): bool =
## Generic lexicographic ``<`` operator for tuples that is lifted from the ## Generic lexicographic `<` operator for tuples that is lifted from the
## components of `x` and `y`. This implementation uses `cmp`. ## components of `x` and `y`. This implementation uses `cmp`.
for a, b in fields(x, y): for a, b in fields(x, y):
var c = cmp(a, b) var c = cmp(a, b)
@ -1960,7 +1960,7 @@ when notJSnotNims:
## **Warning**: Ordinary application code should never set this hook! ## **Warning**: Ordinary application code should never set this hook!
## You better know what you do when setting this. ## You better know what you do when setting this.
## ##
## If ``globalRaiseHook`` returns false, the exception is caught and does ## If `globalRaiseHook` returns false, the exception is caught and does
## not propagate further through the call stack. ## not propagate further through the call stack.
localRaiseHook* {.threadvar.}: proc (e: ref Exception): bool {.nimcall, benign.} localRaiseHook* {.threadvar.}: proc (e: ref Exception): bool {.nimcall, benign.}
@ -1971,7 +1971,7 @@ when notJSnotNims:
## **Warning**: Ordinary application code should never set this hook! ## **Warning**: Ordinary application code should never set this hook!
## You better know what you do when setting this. ## You better know what you do when setting this.
## ##
## If ``localRaiseHook`` returns false, the exception ## If `localRaiseHook` returns false, the exception
## is caught and does not propagate further through the call stack. ## is caught and does not propagate further through the call stack.
outOfMemHook*: proc () {.nimcall, tags: [], benign, raises: [].} outOfMemHook*: proc () {.nimcall, tags: [], benign, raises: [].}
@ -2042,21 +2042,21 @@ when defined(nimvarargstyped):
## Writes and flushes the parameters to the standard output. ## Writes and flushes the parameters to the standard output.
## ##
## Special built-in that takes a variable number of arguments. Each argument ## Special built-in that takes a variable number of arguments. Each argument
## is converted to a string via ``$``, so it works for user-defined ## is converted to a string via `$`, so it works for user-defined
## types that have an overloaded ``$`` operator. ## types that have an overloaded `$` operator.
## It is roughly equivalent to ``writeLine(stdout, x); flushFile(stdout)``, but ## It is roughly equivalent to `writeLine(stdout, x); flushFile(stdout)`, but
## available for the JavaScript target too. ## available for the JavaScript target too.
## ##
## Unlike other IO operations this is guaranteed to be thread-safe as ## Unlike other IO operations this is guaranteed to be thread-safe as
## ``echo`` is very often used for debugging convenience. If you want to use ## `echo` is very often used for debugging convenience. If you want to use
## ``echo`` inside a `proc without side effects ## `echo` inside a `proc without side effects
## <manual.html#pragmas-nosideeffect-pragma>`_ you can use `debugEcho ## <manual.html#pragmas-nosideeffect-pragma>`_ you can use `debugEcho
## <#debugEcho,varargs[typed,]>`_ instead. ## <#debugEcho,varargs[typed,]>`_ instead.
proc debugEcho*(x: varargs[typed, `$`]) {.magic: "Echo", noSideEffect, proc debugEcho*(x: varargs[typed, `$`]) {.magic: "Echo", noSideEffect,
tags: [], raises: [].} tags: [], raises: [].}
## Same as `echo <#echo,varargs[typed,]>`_, but as a special semantic rule, ## Same as `echo <#echo,varargs[typed,]>`_, but as a special semantic rule,
## ``debugEcho`` pretends to be free of side effects, so that it can be used ## `debugEcho` pretends to be free of side effects, so that it can be used
## for debugging routines marked as `noSideEffect ## for debugging routines marked as `noSideEffect
## <manual.html#pragmas-nosideeffect-pragma>`_. ## <manual.html#pragmas-nosideeffect-pragma>`_.
else: else:
@ -2067,7 +2067,7 @@ else:
template newException*(exceptn: typedesc, message: string; template newException*(exceptn: typedesc, message: string;
parentException: ref Exception = nil): untyped = parentException: ref Exception = nil): untyped =
## Creates an exception object of type ``exceptn`` and sets its ``msg`` field ## Creates an exception object of type `exceptn` and sets its `msg` field
## to `message`. Returns the new exception object. ## to `message`. Returns the new exception object.
(ref exceptn)(msg: message, parent: parentException) (ref exceptn)(msg: message, parent: parentException)
@ -2094,7 +2094,7 @@ func abs*(x: int32): int32 {.magic: "AbsI", inline.} =
func abs*(x: int64): int64 {.magic: "AbsI", inline.} = func abs*(x: int64): int64 {.magic: "AbsI", inline.} =
## Returns the absolute value of `x`. ## Returns the absolute value of `x`.
## ##
## If `x` is ``low(x)`` (that is -MININT for its type), ## If `x` is `low(x)` (that is -MININT for its type),
## an overflow exception is thrown (if overflow checking is turned on). ## an overflow exception is thrown (if overflow checking is turned on).
result = if x < 0: -x else: x result = if x < 0: -x else: x
{.pop.} {.pop.}
@ -2254,14 +2254,14 @@ when not defined(js):
when declared(newSeq): when declared(newSeq):
proc cstringArrayToSeq*(a: cstringArray, len: Natural): seq[string] = proc cstringArrayToSeq*(a: cstringArray, len: Natural): seq[string] =
## Converts a ``cstringArray`` to a ``seq[string]``. `a` is supposed to be ## Converts a `cstringArray` to a `seq[string]`. `a` is supposed to be
## of length ``len``. ## of length `len`.
newSeq(result, len) newSeq(result, len)
for i in 0..len-1: result[i] = $a[i] for i in 0..len-1: result[i] = $a[i]
proc cstringArrayToSeq*(a: cstringArray): seq[string] = proc cstringArrayToSeq*(a: cstringArray): seq[string] =
## Converts a ``cstringArray`` to a ``seq[string]``. `a` is supposed to be ## Converts a `cstringArray` to a `seq[string]`. `a` is supposed to be
## terminated by ``nil``. ## terminated by `nil`.
var L = 0 var L = 0
while a[L] != nil: inc(L) while a[L] != nil: inc(L)
result = cstringArrayToSeq(a, L) result = cstringArrayToSeq(a, L)
@ -2319,7 +2319,7 @@ when notJSnotNims:
proc getStackTrace*(e: ref Exception): string {.gcsafe.} proc getStackTrace*(e: ref Exception): string {.gcsafe.}
## Gets the stack trace associated with `e`, which is the stack that ## Gets the stack trace associated with `e`, which is the stack that
## lead to the ``raise`` statement. This only works for debug builds. ## lead to the `raise` statement. This only works for debug builds.
{.push stackTrace: off, profiler: off.} {.push stackTrace: off, profiler: off.}
when defined(memtracker): when defined(memtracker):
@ -2377,7 +2377,7 @@ when notJSnotNims:
if discr < cast[uint](n.len): if discr < cast[uint](n.len):
result = n.sons[discr] result = n.sons[discr]
if result == nil: result = n.sons[n.len] if result == nil: result = n.sons[n.len]
# n.sons[n.len] contains the ``else`` part (but may be nil) # n.sons[n.len] contains the `else` part (but may be nil)
else: else:
result = n.sons[n.len] result = n.sons[n.len]
@ -2470,7 +2470,7 @@ when defined(js) or defined(nimscript):
result.add $x result.add $x
proc quit*(errormsg: string, errorcode = QuitFailure) {.noreturn.} = proc quit*(errormsg: string, errorcode = QuitFailure) {.noreturn.} =
## A shorthand for ``echo(errormsg); quit(errorcode)``. ## A shorthand for `echo(errormsg); quit(errorcode)`.
when defined(nimscript) or defined(js) or (hostOS == "standalone"): when defined(nimscript) or defined(js) or (hostOS == "standalone"):
echo errormsg echo errormsg
else: else:
@ -2496,13 +2496,13 @@ proc `/`*(x, y: int): float {.inline, noSideEffect.} =
result = toFloat(x) / toFloat(y) result = toFloat(x) / toFloat(y)
type type
BackwardsIndex* = distinct int ## Type that is constructed by ``^`` for BackwardsIndex* = distinct int ## Type that is constructed by `^` for
## reversed array accesses. ## reversed array accesses.
## (See `^ template <#^.t,int>`_) ## (See `^ template <#^.t,int>`_)
template `^`*(x: int): BackwardsIndex = BackwardsIndex(x) template `^`*(x: int): BackwardsIndex = BackwardsIndex(x)
## Builtin `roof`:idx: operator that can be used for convenient array access. ## Builtin `roof`:idx: operator that can be used for convenient array access.
## ``a[^x]`` is a shortcut for ``a[a.len-x]``. ## `a[^x]` is a shortcut for `a[a.len-x]`.
## ##
## .. code-block:: Nim ## .. code-block:: Nim
## let ## let
@ -2561,7 +2561,7 @@ proc `[]`*[T, U: Ordinal](s: string, x: HSlice[T, U]): string {.inline.} =
proc `[]=`*[T, U: Ordinal](s: var string, x: HSlice[T, U], b: string) = proc `[]=`*[T, U: Ordinal](s: var string, x: HSlice[T, U], b: string) =
## Slice assignment for strings. ## Slice assignment for strings.
## ##
## If ``b.len`` is not exactly the number of elements that are referred to ## If `b.len` is not exactly the number of elements that are referred to
## by `x`, a `splice`:idx: is performed: ## by `x`, a `splice`:idx: is performed:
## ##
runnableExamples: runnableExamples:
@ -2617,7 +2617,7 @@ proc `[]`*[T; U, V: Ordinal](s: openArray[T], x: HSlice[U, V]): seq[T] =
proc `[]=`*[T; U, V: Ordinal](s: var seq[T], x: HSlice[U, V], b: openArray[T]) = proc `[]=`*[T; U, V: Ordinal](s: var seq[T], x: HSlice[U, V], b: openArray[T]) =
## Slice assignment for sequences. ## Slice assignment for sequences.
## ##
## If ``b.len`` is not exactly the number of elements that are referred to ## If `b.len` is not exactly the number of elements that are referred to
## by `x`, a `splice`:idx: is performed. ## by `x`, a `splice`:idx: is performed.
runnableExamples: runnableExamples:
var s = @"abcdefgh" var s = @"abcdefgh"
@ -2658,13 +2658,13 @@ proc staticRead*(filename: string): string {.magic: "Slurp".}
## Compile-time `readFile <io.html#readFile,string>`_ proc for easy ## Compile-time `readFile <io.html#readFile,string>`_ proc for easy
## `resource`:idx: embedding: ## `resource`:idx: embedding:
## ##
## The maximum file size limit that ``staticRead`` and ``slurp`` can read is ## The maximum file size limit that `staticRead` and `slurp` can read is
## near or equal to the *free* memory of the device you are using to compile. ## near or equal to the *free* memory of the device you are using to compile.
## ##
## .. code-block:: Nim ## .. code-block:: Nim
## const myResource = staticRead"mydatafile.bin" ## const myResource = staticRead"mydatafile.bin"
## ##
## `slurp <#slurp,string>`_ is an alias for ``staticRead``. ## `slurp <#slurp,string>`_ is an alias for `staticRead`.
proc gorge*(command: string, input = "", cache = ""): string {. proc gorge*(command: string, input = "", cache = ""): string {.
magic: "StaticExec".} = discard magic: "StaticExec".} = discard
@ -2682,17 +2682,17 @@ proc staticExec*(command: string, input = "", cache = ""): string {.
## const buildInfo = "Revision " & staticExec("git rev-parse HEAD") & ## const buildInfo = "Revision " & staticExec("git rev-parse HEAD") &
## "\nCompiled on " & staticExec("uname -v") ## "\nCompiled on " & staticExec("uname -v")
## ##
## `gorge <#gorge,string,string,string>`_ is an alias for ``staticExec``. ## `gorge <#gorge,string,string,string>`_ is an alias for `staticExec`.
## ##
## Note that you can use this proc inside a pragma like ## Note that you can use this proc inside a pragma like
## `passc <manual.html#implementation-specific-pragmas-passc-pragma>`_ or ## `passc <manual.html#implementation-specific-pragmas-passc-pragma>`_ or
## `passl <manual.html#implementation-specific-pragmas-passl-pragma>`_. ## `passl <manual.html#implementation-specific-pragmas-passl-pragma>`_.
## ##
## If ``cache`` is not empty, the results of ``staticExec`` are cached within ## If `cache` is not empty, the results of `staticExec` are cached within
## the ``nimcache`` directory. Use ``--forceBuild`` to get rid of this caching ## the `nimcache` directory. Use `--forceBuild` to get rid of this caching
## behaviour then. ``command & input & cache`` (the concatenated string) is ## behaviour then. `command & input & cache` (the concatenated string) is
## used to determine whether the entry in the cache is still valid. You can ## used to determine whether the entry in the cache is still valid. You can
## use versioning information for ``cache``: ## use versioning information for `cache`:
## ##
## .. code-block:: Nim ## .. code-block:: Nim
## const stateMachine = staticExec("dfaoptimizer", "input", "0.8.0") ## const stateMachine = staticExec("dfaoptimizer", "input", "0.8.0")
@ -2737,8 +2737,8 @@ proc `&=`*(x: var string, y: string) {.magic: "AppendStrStr", noSideEffect.}
template `&=`*(x, y: typed) = template `&=`*(x, y: typed) =
## Generic 'sink' operator for Nim. ## Generic 'sink' operator for Nim.
## ##
## For files an alias for ``write``. ## For files an alias for `write`.
## If not specialized further, an alias for ``add``. ## If not specialized further, an alias for `add`.
add(x, y) add(x, y)
when declared(File): when declared(File):
template `&=`*(f: File, x: typed) = write(f, x) template `&=`*(f: File, x: typed) = write(f, x)
@ -2747,13 +2747,13 @@ template currentSourcePath*: string = instantiationInfo(-1, true).filename
## Returns the full file-system path of the current source. ## Returns the full file-system path of the current source.
## ##
## To get the directory containing the current source, use it with ## To get the directory containing the current source, use it with
## `os.parentDir() <os.html#parentDir%2Cstring>`_ as ``currentSourcePath.parentDir()``. ## `os.parentDir() <os.html#parentDir%2Cstring>`_ as `currentSourcePath.parentDir()`.
## ##
## The path returned by this template is set at compile time. ## The path returned by this template is set at compile time.
## ##
## See the docstring of `macros.getProjectPath() <macros.html#getProjectPath>`_ ## See the docstring of `macros.getProjectPath() <macros.html#getProjectPath>`_
## for an example to see the distinction between the ``currentSourcePath`` ## for an example to see the distinction between the `currentSourcePath`
## and ``getProjectPath``. ## and `getProjectPath`.
## ##
## See also: ## See also:
## * `getCurrentDir proc <os.html#getCurrentDir>`_ ## * `getCurrentDir proc <os.html#getCurrentDir>`_
@ -2761,7 +2761,7 @@ template currentSourcePath*: string = instantiationInfo(-1, true).filename
when compileOption("rangechecks"): when compileOption("rangechecks"):
template rangeCheck*(cond) = template rangeCheck*(cond) =
## Helper for performing user-defined range checks. ## Helper for performing user-defined range checks.
## Such checks will be performed only when the ``rangechecks`` ## Such checks will be performed only when the `rangechecks`
## compile-time option is enabled. ## compile-time option is enabled.
if not cond: sysFatal(RangeDefect, "range check failed") if not cond: sysFatal(RangeDefect, "range check failed")
else: else:
@ -2841,19 +2841,19 @@ when declared(initDebugger):
proc addEscapedChar*(s: var string, c: char) {.noSideEffect, inline.} = proc addEscapedChar*(s: var string, c: char) {.noSideEffect, inline.} =
## Adds a char to string `s` and applies the following escaping: ## Adds a char to string `s` and applies the following escaping:
## ##
## * replaces any ``\`` by ``\\`` ## * replaces any `\` by `\\`
## * replaces any ``'`` by ``\'`` ## * replaces any `'` by `\'`
## * replaces any ``"`` by ``\"`` ## * replaces any `"` by `\"`
## * replaces any ``\a`` by ``\\a`` ## * replaces any `\a` by `\\a`
## * replaces any ``\b`` by ``\\b`` ## * replaces any `\b` by `\\b`
## * replaces any ``\t`` by ``\\t`` ## * replaces any `\t` by `\\t`
## * replaces any ``\n`` by ``\\n`` ## * replaces any `\n` by `\\n`
## * replaces any ``\v`` by ``\\v`` ## * replaces any `\v` by `\\v`
## * replaces any ``\f`` by ``\\f`` ## * replaces any `\f` by `\\f`
## * replaces any ``\c`` by ``\\c`` ## * replaces any `\c` by `\\c`
## * replaces any ``\e`` by ``\\e`` ## * replaces any `\e` by `\\e`
## * replaces any other character not in the set ``{'\21..'\126'} ## * replaces any other character not in the set `{'\21..'\126'}
## by ``\xHH`` where ``HH`` is its hexadecimal value. ## by `\xHH` where `HH` is its hexadecimal value.
## ##
## The procedure has been designed so that its output is usable for many ## The procedure has been designed so that its output is usable for many
## different common syntaxes. ## different common syntaxes.
@ -2885,9 +2885,9 @@ proc addQuoted*[T](s: var string, x: T) =
## ##
## See `addEscapedChar <#addEscapedChar,string,char>`_ ## See `addEscapedChar <#addEscapedChar,string,char>`_
## for the escaping scheme. When `x` is a string, characters in the ## for the escaping scheme. When `x` is a string, characters in the
## range ``{\128..\255}`` are never escaped so that multibyte UTF-8 ## range `{\128..\255}` are never escaped so that multibyte UTF-8
## characters are untouched (note that this behavior is different from ## characters are untouched (note that this behavior is different from
## ``addEscapedChar``). ## `addEscapedChar`).
## ##
## The Nim standard library uses this function on the elements of ## The Nim standard library uses this function on the elements of
## collections when producing a string representation of a collection. ## collections when producing a string representation of a collection.
@ -2933,7 +2933,7 @@ proc locals*(): RootObj {.magic: "Plugin", noSideEffect.} =
## ##
## This is quite fast as it does not rely ## This is quite fast as it does not rely
## on any debug or runtime information. Note that in contrast to what ## on any debug or runtime information. Note that in contrast to what
## the official signature says, the return type is *not* ``RootObj`` but a ## the official signature says, the return type is *not* `RootObj` but a
## tuple of a structure that depends on the current scope. Example: ## tuple of a structure that depends on the current scope. Example:
## ##
## .. code-block:: Nim ## .. code-block:: Nim
@ -2959,10 +2959,10 @@ when hasAlloc and notJSnotNims:
## Performs a deep copy of `y` and copies it into `x`. ## Performs a deep copy of `y` and copies it into `x`.
## ##
## This is also used by the code generator ## This is also used by the code generator
## for the implementation of ``spawn``. ## for the implementation of `spawn`.
## ##
## For ``--gc:arc`` or ``--gc:orc`` deepcopy support has to be enabled ## For `--gc:arc` or `--gc:orc` deepcopy support has to be enabled
## via ``--deepcopy:on``. ## via `--deepcopy:on`.
discard discard
proc deepCopy*[T](y: T): T = proc deepCopy*[T](y: T): T =
@ -2991,13 +2991,13 @@ proc `==`*(x, y: cstring): bool {.magic: "EqCString", noSideEffect,
else: result = strcmp(x, y) == 0 else: result = strcmp(x, y) == 0
when not compileOption("nilseqs"): when not compileOption("nilseqs"):
# bug #9149; ensure that 'type(nil)' does not match *too* well by using 'type(nil) | type(nil)', # bug #9149; ensure that 'typeof(nil)' does not match *too* well by using 'typeof(nil) | typeof(nil)',
# especially for converters, see tests/overload/tconverter_to_string.nim # especially for converters, see tests/overload/tconverter_to_string.nim
# Eventually we will be able to remove this hack completely. # Eventually we will be able to remove this hack completely.
proc `==`*(x: string; y: type(nil) | type(nil)): bool {. proc `==`*(x: string; y: typeof(nil) | typeof(nil)): bool {.
error: "'nil' is now invalid for 'string'; compile with --nilseqs:on for a migration period".} = error: "'nil' is now invalid for 'string'; compile with --nilseqs:on for a migration period".} =
discard discard
proc `==`*(x: type(nil) | type(nil); y: string): bool {. proc `==`*(x: typeof(nil) | typeof(nil); y: string): bool {.
error: "'nil' is now invalid for 'string'; compile with --nilseqs:on for a migration period".} = error: "'nil' is now invalid for 'string'; compile with --nilseqs:on for a migration period".} =
discard discard
@ -3051,9 +3051,9 @@ proc substr*(s: string, first, last: int): string =
## string. ## string.
## ##
## The bounds `first` and `last` denote the indices of ## The bounds `first` and `last` denote the indices of
## the first and last characters that shall be copied. If ``last`` ## the first and last characters that shall be copied. If `last`
## is omitted, it is treated as ``high(s)``. If ``last >= s.len``, ``s.len`` ## is omitted, it is treated as `high(s)`. If `last >= s.len`, `s.len`
## is used instead: This means ``substr`` can also be used to `cut`:idx: ## is used instead: This means `substr` can also be used to `cut`:idx:
## or `limit`:idx: a string's length. ## or `limit`:idx: a string's length.
runnableExamples: runnableExamples:
let a = "abcdefgh" let a = "abcdefgh"
@ -3109,11 +3109,11 @@ when defined(genode):
## ##
## This hook is called after all globals are initialized. ## This hook is called after all globals are initialized.
## When this hook is set the component will not automatically exit, ## When this hook is set the component will not automatically exit,
## call ``quit`` explicitly to do so. This is the only available method ## call `quit` explicitly to do so. This is the only available method
## of accessing the initial Genode environment. ## of accessing the initial Genode environment.
proc nim_component_construct(env: GenodeEnv) {.exportc.} = proc nim_component_construct(env: GenodeEnv) {.exportc.} =
## Procedure called during ``Component::construct`` by the loader. ## Procedure called during `Component::construct` by the loader.
if componentConstructHook.isNil: if componentConstructHook.isNil:
env.quit(programResult) env.quit(programResult)
# No native Genode application initialization, # No native Genode application initialization,

View file

@ -242,7 +242,7 @@ template addFrameEntry(s: var string, f: StackTraceEntry|PFrame) =
for k in 1..max(1, 25-(s.len-oldLen)): add(s, ' ') for k in 1..max(1, 25-(s.len-oldLen)): add(s, ' ')
add(s, f.procname) add(s, f.procname)
when NimStackTraceMsgs: when NimStackTraceMsgs:
when type(f) is StackTraceEntry: when typeof(f) is StackTraceEntry:
add(s, f.frameMsg) add(s, f.frameMsg)
else: else:
var first = if f.prev == nil: 0 else: f.prev.frameMsgLen var first = if f.prev == nil: 0 else: f.prev.frameMsgLen

View file

@ -240,7 +240,7 @@ iterator fields*[T: tuple|object](x: T): RootObj {.
## that affects symbol binding in the loop body. ## that affects symbol binding in the loop body.
runnableExamples: runnableExamples:
var t = (1, "foo") var t = (1, "foo")
for v in fields(t): v = default(type(v)) for v in fields(t): v = default(typeof(v))
doAssert t == (0, "") doAssert t == (0, "")
iterator fields*[S:tuple|object, T:tuple|object](x: S, y: T): tuple[key: string, val: RootObj] {. iterator fields*[S:tuple|object, T:tuple|object](x: S, y: T): tuple[key: string, val: RootObj] {.
@ -252,7 +252,7 @@ iterator fields*[S:tuple|object, T:tuple|object](x: S, y: T): tuple[key: string,
## in the loop body. ## in the loop body.
runnableExamples: runnableExamples:
var t1 = (1, "foo") var t1 = (1, "foo")
var t2 = default(type(t1)) var t2 = default(typeof(t1))
for v1, v2 in fields(t1, t2): v2 = v1 for v1, v2 in fields(t1, t2): v2 = v1
doAssert t1 == t2 doAssert t1 == t2

View file

@ -418,9 +418,9 @@ proc isValid1*[A](s: HashSet[A]): bool {.deprecated:
result = s.data.len > 0 result = s.data.len > 0
# bug #11468 # bug #11468
assert $type(a) == "Option[system.int]" assert $typeof(a) == "Option[system.int]"
foo(a, $type(b), c) foo(a, $typeof(b), c)
foo(type(b), c) # this is ok foo(typeof(b), c) # this is ok
proc `<`*[A](s, t: A): bool = discard proc `<`*[A](s, t: A): bool = discard
proc `==`*[A](s, t: HashSet[A]): bool = discard proc `==`*[A](s, t: HashSet[A]): bool = discard

View file

@ -423,9 +423,9 @@ proc isValid1*[A](s: HashSet[A]): bool {.deprecated:
result = s.data.len > 0 result = s.data.len > 0
# bug #11468 # bug #11468
assert $type(a) == "Option[system.int]" assert $typeof(a) == "Option[system.int]"
foo(a, $type(b), c) foo(a, $typeof(b), c)
foo(type(b), c) # this is ok foo(typeof(b), c) # this is ok
proc `<`*[A](s, t: A): bool = discard proc `<`*[A](s, t: A): bool = discard
proc `==`*[A](s, t: HashSet[A]): bool = discard proc `==`*[A](s, t: HashSet[A]): bool = discard

View file

@ -57,7 +57,7 @@ proc main(): Future[void] =
template await[T](f_gensym12: Future[T]): auto {.used.} = template await[T](f_gensym12: Future[T]): auto {.used.} =
var internalTmpFuture_gensym12: FutureBase = f_gensym12 var internalTmpFuture_gensym12: FutureBase = f_gensym12
yield internalTmpFuture_gensym12 yield internalTmpFuture_gensym12
(cast[type(f_gensym12)](internalTmpFuture_gensym12)).read() (cast[typeof(f_gensym12)](internalTmpFuture_gensym12)).read()
var retFuture = newFuture[void]("main") var retFuture = newFuture[void]("main")
iterator mainIter(): FutureBase {.closure.} = iterator mainIter(): FutureBase {.closure.} =

View file

@ -71,8 +71,8 @@ proc newRStarTree*[M, D: Dim; RT, LT](minFill: range[30 .. 50] = 40): RStarTree[
result.p = M * 30 div 100 result.p = M * 30 div 100
result.root = newLeaf[M, D, RT, LT]() result.root = newLeaf[M, D, RT, LT]()
proc center(r: Box): auto =#BoxCenter[r.len, type(r[0].a)] = proc center(r: Box): auto =#BoxCenter[r.len, typeof(r[0].a)] =
var res: BoxCenter[r.len, type(r[0].a)] var res: BoxCenter[r.len, typeof(r[0].a)]
for i in 0 .. r.high: for i in 0 .. r.high:
when r[0].a is SomeInteger: when r[0].a is SomeInteger:
res[i] = (r[i].a + r[i].b) div 2 res[i] = (r[i].a + r[i].b) div 2
@ -82,13 +82,13 @@ proc center(r: Box): auto =#BoxCenter[r.len, type(r[0].a)] =
return res return res
proc distance(c1, c2: BoxCenter): auto = proc distance(c1, c2: BoxCenter): auto =
var res: type(c1[0]) var res: typeof(c1[0])
for i in 0 .. c1.high: for i in 0 .. c1.high:
res += (c1[i] - c2[i]) * (c1[i] - c2[i]) res += (c1[i] - c2[i]) * (c1[i] - c2[i])
return res return res
proc overlap(r1, r2: Box): auto = proc overlap(r1, r2: Box): auto =
result = type(r1[0].a)(1) result = typeof(r1[0].a)(1)
for i in 0 .. r1.high: for i in 0 .. r1.high:
result *= (min(r1[i].b, r2[i].b) - max(r1[i].a, r2[i].a)) result *= (min(r1[i].b, r2[i].b) - max(r1[i].a, r2[i].a))
if result <= 0: return 0 if result <= 0: return 0
@ -104,13 +104,13 @@ proc intersect(r1, r2: Box): bool =
return false return false
return true return true
proc area(r: Box): auto = #type(r[0].a) = proc area(r: Box): auto = #typeof(r[0].a) =
result = type(r[0].a)(1) result = typeof(r[0].a)(1)
for i in 0 .. r.high: for i in 0 .. r.high:
result *= r[i].b - r[i].a result *= r[i].b - r[i].a
proc margin(r: Box): auto = #type(r[0].a) = proc margin(r: Box): auto = #typeof(r[0].a) =
result = type(r[0].a)(0) result = typeof(r[0].a)(0)
for i in 0 .. r.high: for i in 0 .. r.high:
result += r[i].b - r[i].a result += r[i].b - r[i].a
@ -142,7 +142,7 @@ proc chooseSubtree[M, D: Dim; RT, LT](t: RTree[M, D, RT, LT]; b: Box[D, RT]; lev
while it.level > level: while it.level > level:
let nn = Node[M, D, RT, LT](it) let nn = Node[M, D, RT, LT](it)
var i0 = 0 # selected index var i0 = 0 # selected index
var minLoss = type(b[0].a).high var minLoss = typeof(b[0].a).high
if it.level == 1: # childreen are leaves -- determine the minimum overlap costs if it.level == 1: # childreen are leaves -- determine the minimum overlap costs
for i in 0 ..< it.numEntries: for i in 0 ..< it.numEntries:
let nx = union(nn.a[i].b, b) let nx = union(nn.a[i].b, b)
@ -179,8 +179,8 @@ proc chooseSubtree[M, D: Dim; RT, LT](t: RTree[M, D, RT, LT]; b: Box[D, RT]; lev
proc pickSeeds[M, D: Dim; RT, LT](t: RTree[M, D, RT, LT]; n: Node[M, D, RT, LT] | Leaf[M, D, RT, LT]; bx: Box[D, RT]): (int, int) = proc pickSeeds[M, D: Dim; RT, LT](t: RTree[M, D, RT, LT]; n: Node[M, D, RT, LT] | Leaf[M, D, RT, LT]; bx: Box[D, RT]): (int, int) =
var i0, j0: int var i0, j0: int
var bi, bj: type(bx) var bi, bj: typeof(bx)
var largestWaste = type(bx[0].a).low var largestWaste = typeof(bx[0].a).low
for i in -1 .. n.a.high: for i in -1 .. n.a.high:
for j in 0 .. n.a.high: for j in 0 .. n.a.high:
if unlikely(i == j): continue if unlikely(i == j): continue
@ -200,7 +200,7 @@ proc pickSeeds[M, D: Dim; RT, LT](t: RTree[M, D, RT, LT]; n: Node[M, D, RT, LT]
proc pickNext[M, D: Dim; RT, LT](t: RTree[M, D, RT, LT]; n0, n1, n2: Node[M, D, RT, LT] | Leaf[M, D, RT, LT]; b1, b2: Box[D, RT]): int = proc pickNext[M, D: Dim; RT, LT](t: RTree[M, D, RT, LT]; n0, n1, n2: Node[M, D, RT, LT] | Leaf[M, D, RT, LT]; b1, b2: Box[D, RT]): int =
let a1 = area(b1) let a1 = area(b1)
let a2 = area(b2) let a2 = area(b2)
var d = type(a1).low var d = typeof(a1).low
for i in 0 ..< n0.numEntries: for i in 0 ..< n0.numEntries:
let d1 = area(union(b1, n0.a[i].b)) - a1 let d1 = area(union(b1, n0.a[i].b)) - a1
let d2 = area(union(b2, n0.a[i].b)) - a2 let d2 = area(union(b2, n0.a[i].b)) - a2
@ -220,15 +220,15 @@ proc sortPlus[T](a: var openArray[T], ax: var T, cmp: proc (x, y: T): int {.clos
a.sort(cmp, order) a.sort(cmp, order)
# R*TREE procs # R*TREE procs
proc rstarSplit[M, D: Dim; RT, LT](t: RStarTree[M, D, RT, LT]; n: var Node[M, D, RT, LT] | var Leaf[M, D, RT, LT]; lx: L[D, RT, LT] | N[M, D, RT, LT]): type(n) = proc rstarSplit[M, D: Dim; RT, LT](t: RStarTree[M, D, RT, LT]; n: var Node[M, D, RT, LT] | var Leaf[M, D, RT, LT]; lx: L[D, RT, LT] | N[M, D, RT, LT]): typeof(n) =
type NL = type(lx) type NL = typeof(lx)
var nBest: type(n) var nBest: typeof(n)
new nBest new nBest
var lx = lx var lx = lx
when n is Node[M, D, RT, LT]: when n is Node[M, D, RT, LT]:
lx.n.parent = n lx.n.parent = n
var lxbest: type(lx) var lxbest: typeof(lx)
var m0 = lx.b[0].a.high var m0 = lx.b[0].a.typeof.high
for d2 in 0 ..< 2 * D: for d2 in 0 ..< 2 * D:
let d = d2 div 2 let d = d2 div 2
if d2 mod 2 == 0: if d2 mod 2 == 0:
@ -251,8 +251,8 @@ proc rstarSplit[M, D: Dim; RT, LT](t: RStarTree[M, D, RT, LT]; n: var Node[M, D,
lxbest = lx lxbest = lx
m0 = m m0 = m
var i0 = -1 var i0 = -1
var o0 = lx.b[0].a.high var o0 = lx.b[0].a.typeof.high
for i in t.m - 1 .. n.a.high - t.m + 1: for i in t.m - 1 .. n.a.typeof.high - t.m + 1:
var b1 = lxbest.b var b1 = lxbest.b
for j in 0 ..< i: for j in 0 ..< i:
b1 = union(nbest.a[j].b, b1) b1 = union(nbest.a[j].b, b1)
@ -277,8 +277,8 @@ proc rstarSplit[M, D: Dim; RT, LT](t: RStarTree[M, D, RT, LT]; n: var Node[M, D,
for i in 0 ..< result.numEntries: for i in 0 ..< result.numEntries:
result.a[i].n.parent = result result.a[i].n.parent = result
proc quadraticSplit[M, D: Dim; RT, LT](t: RTree[M, D, RT, LT]; n: var Node[M, D, RT, LT] | var Leaf[M, D, RT, LT]; lx: L[D, RT, LT] | N[M, D, RT, LT]): type(n) = proc quadraticSplit[M, D: Dim; RT, LT](t: RTree[M, D, RT, LT]; n: var Node[M, D, RT, LT] | var Leaf[M, D, RT, LT]; lx: L[D, RT, LT] | N[M, D, RT, LT]): typeof(n) =
var n1, n2: type(n) var n1, n2: typeof(n)
var s1, s2: int var s1, s2: int
new n1 new n1
new n2 new n2
@ -341,7 +341,7 @@ proc quadraticSplit[M, D: Dim; RT, LT](t: RTree[M, D, RT, LT]; n: var Node[M, D,
n[] = n1[] n[] = n1[]
return n2 return n2
proc overflowTreatment[M, D: Dim; RT, LT](t: RStarTree[M, D, RT, LT]; n: var Node[M, D, RT, LT] | var Leaf[M, D, RT, LT]; lx: L[D, RT, LT] | N[M, D, RT, LT]): type(n) proc overflowTreatment[M, D: Dim; RT, LT](t: RStarTree[M, D, RT, LT]; n: var Node[M, D, RT, LT] | var Leaf[M, D, RT, LT]; lx: L[D, RT, LT] | N[M, D, RT, LT]): typeof(n)
proc adjustTree[M, D: Dim; RT, LT](t: RTree[M, D, RT, LT]; l, ll: H[M, D, RT, LT]; hb: Box[D, RT]) = proc adjustTree[M, D: Dim; RT, LT](t: RTree[M, D, RT, LT]; l, ll: H[M, D, RT, LT]; hb: Box[D, RT]) =
var n = l var n = l
@ -361,7 +361,7 @@ proc adjustTree[M, D: Dim; RT, LT](t: RTree[M, D, RT, LT]; l, ll: H[M, D, RT, LT
var i = 0 var i = 0
while p.a[i].n != n: while p.a[i].n != n:
inc(i) inc(i)
var b: type(p.a[0].b) var b: typeof(p.a[0].b)
if n of Leaf[M, D, RT, LT]: if n of Leaf[M, D, RT, LT]:
when false:#if likely(nn.isNil): # no performance gain when false:#if likely(nn.isNil): # no performance gain
b = union(p.a[i].b, Leaf[M, D, RT, LT](n).a[n.numEntries - 1].b) b = union(p.a[i].b, Leaf[M, D, RT, LT](n).a[n.numEntries - 1].b)
@ -427,9 +427,9 @@ proc insert*[M, D: Dim; RT, LT](t: RTree[M, D, RT, LT]; leaf: N[M, D, RT, LT] |
proc rsinsert[M, D: Dim; RT, LT](t: RStarTree[M, D, RT, LT]; leaf: N[M, D, RT, LT] | L[D, RT, LT]; level: int) proc rsinsert[M, D: Dim; RT, LT](t: RStarTree[M, D, RT, LT]; leaf: N[M, D, RT, LT] | L[D, RT, LT]; level: int)
proc reInsert[M, D: Dim; RT, LT](t: RStarTree[M, D, RT, LT]; n: var Node[M, D, RT, LT] | var Leaf[M, D, RT, LT]; lx: L[D, RT, LT] | N[M, D, RT, LT]) = proc reInsert[M, D: Dim; RT, LT](t: RStarTree[M, D, RT, LT]; n: var Node[M, D, RT, LT] | var Leaf[M, D, RT, LT]; lx: L[D, RT, LT] | N[M, D, RT, LT]) =
type NL = type(lx) type NL = typeof(lx)
var lx = lx var lx = lx
var buf: type(n.a) var buf: typeof(n.a)
let p = Node[M, D, RT, LT](n.parent) let p = Node[M, D, RT, LT](n.parent)
var i = 0 var i = 0
while p.a[i].n != n: while p.a[i].n != n:
@ -449,7 +449,7 @@ proc reInsert[M, D: Dim; RT, LT](t: RStarTree[M, D, RT, LT]; n: var Node[M, D, R
for i in M - t.p + 1 .. n.a.high: for i in M - t.p + 1 .. n.a.high:
rsinsert(t, buf[i], n.level) rsinsert(t, buf[i], n.level)
proc overflowTreatment[M, D: Dim; RT, LT](t: RStarTree[M, D, RT, LT]; n: var Node[M, D, RT, LT] | var Leaf[M, D, RT, LT]; lx: L[D, RT, LT] | N[M, D, RT, LT]): type(n) = proc overflowTreatment[M, D: Dim; RT, LT](t: RStarTree[M, D, RT, LT]; n: var Node[M, D, RT, LT] | var Leaf[M, D, RT, LT]; lx: L[D, RT, LT] | N[M, D, RT, LT]): typeof(n) =
if n.level != t.root.level and t.firstOverflow[n.level]: if n.level != t.root.level and t.firstOverflow[n.level]:
t.firstOverflow[n.level] = false t.firstOverflow[n.level] = false
reInsert(t, n, lx) reInsert(t, n, lx)

View file

@ -22,10 +22,10 @@ import typetraits
block tand: block tand:
# bug #5216 # bug #5216
echo(name type((0x0A'i8 and 0x7F'i32) shl 7'i32)) echo(name typeof((0x0A'i8 and 0x7F'i32) shl 7'i32))
let i8 = 0x0A'i8 let i8 = 0x0A'i8
echo(name type((i8 and 0x7F'i32) shl 7'i32)) echo(name typeof((i8 and 0x7F'i32) shl 7'i32))
echo((0x0A'i8 and 0x7F'i32) shl 7'i32) echo((0x0A'i8 and 0x7F'i32) shl 7'i32)

View file

@ -344,11 +344,11 @@ block troofregression:
if $a != b: if $a != b:
echo "Failure ", a, " != ", b echo "Failure ", a, " != ", b
check type(4 ...< 1), "HSlice[system.int, system.int]" check typeof(4 ...< 1), "HSlice[system.int, system.int]"
check type(4 ...< ^1), "HSlice[system.int, system.BackwardsIndex]" check typeof(4 ...< ^1), "HSlice[system.int, system.BackwardsIndex]"
check type(4 ... pred(^1)), "HSlice[system.int, system.BackwardsIndex]" check typeof(4 ... pred(^1)), "HSlice[system.int, system.BackwardsIndex]"
check type(4 ... mypred(8)), "HSlice[system.int, system.int]" check typeof(4 ... mypred(8)), "HSlice[system.int, system.int]"
check type(4 ... mypred(^1)), "HSlice[system.int, system.BackwardsIndex]" check typeof(4 ... mypred(^1)), "HSlice[system.int, system.BackwardsIndex]"
var rot = 8 var rot = 8

View file

@ -178,7 +178,7 @@ when false:
proc `=`[T](d: var GenericT[T]; src: GenericT[T]) = proc `=`[T](d: var GenericT[T]; src: GenericT[T]) =
shallowCopy(d.a, src.a) shallowCopy(d.a, src.a)
shallowCopy(d.b, src.b) shallowCopy(d.b, src.b)
echo "GenericT[T] '=' ", type(T).name echo "GenericT[T] '=' ", typeof(T).name
var ag: GenericT[int] var ag: GenericT[int]
var bg: GenericT[int] var bg: GenericT[int]

View file

@ -10,7 +10,7 @@ type
v: T v: T
template templ(o: A, op: untyped): untyped = template templ(o: A, op: untyped): untyped =
type T = type(o.v) type T = typeof(o.v)
var res: A[T] var res: A[T]

View file

@ -68,7 +68,7 @@ template odd*(i: int) : untyped =
proc vidx(hg: HexGrid; col, row: int; i: HexVtxIndex) : Index = proc vidx(hg: HexGrid; col, row: int; i: HexVtxIndex) : Index =
#NOTE: this variation compiles #NOTE: this variation compiles
#var offset : type(evenSharingOffsets[i]) #var offset : typeof(evenSharingOffsets[i])
# #
#if odd(col): #if odd(col):
# offset = oddSharingOffsets[i] # offset = oddSharingOffsets[i]

View file

@ -190,7 +190,7 @@ proc foo() =
let f = (proc() = let f = (proc() =
myDiscard (proc() = echo a) myDiscard (proc() = echo a)
) )
echo name(type(f)) echo name(typeof(f))
foo() foo()

View file

@ -201,7 +201,7 @@ block ttoseq:
stdout.write(x) stdout.write(x)
for x in items(toSeq(countup(2, 6))): for x in items(toSeq(countup(2, 6))):
stdout.write(x) stdout.write(x)
var y: type("a b c".split) var y: typeof("a b c".split)
y = "xzy" y = "xzy"
stdout.write("\n") stdout.write("\n")