mirror of
https://github.com/nim-lang/Nim.git
synced 2026-08-31 02:43:41 +00:00
Merge branch 'devel' of github.com:nim-lang/Nim into devel
This commit is contained in:
@@ -152,11 +152,13 @@ proc add*[T](q: var Queue[T], item: T) =
|
||||
q.data[q.wr] = item
|
||||
q.wr = (q.wr + 1) and q.mask
|
||||
|
||||
proc default[T](t: typedesc[T]): T {.inline.} = discard
|
||||
proc pop*[T](q: var Queue[T]): T {.inline, discardable.} =
|
||||
## Remove and returns the first (oldest) element of the queue `q`.
|
||||
emptyCheck(q)
|
||||
dec q.count
|
||||
result = q.data[q.rd]
|
||||
q.data[q.rd] = default(type(result))
|
||||
q.rd = (q.rd + 1) and q.mask
|
||||
|
||||
proc enqueue*[T](q: var Queue[T], item: T) =
|
||||
|
||||
@@ -16,6 +16,39 @@
|
||||
## semantics, this means that ``=`` performs a copy of the hash table.
|
||||
## For **reference** semantics use the ``Ref`` variant: ``TableRef``,
|
||||
## ``OrderedTableRef``, ``CountTableRef``.
|
||||
## To give an example, when `a` is a Table, then `var b = a` gives `b`
|
||||
## as a new independent table. b is initialised with the contents of `a`.
|
||||
## Changing `b` does not affect `a` and vice versa:
|
||||
##
|
||||
## .. code-block::
|
||||
## import tables
|
||||
##
|
||||
## var
|
||||
## a = {1: "one", 2: "two"}.toTable # creates a Table
|
||||
## b = a
|
||||
##
|
||||
## echo a, b # output: {1: one, 2: two}{1: one, 2: two}
|
||||
##
|
||||
## b[3] = "three"
|
||||
## echo a, b # output: {1: one, 2: two}{1: one, 2: two, 3: three}
|
||||
## echo a == b # output: false
|
||||
##
|
||||
## On the other hand, when `a` is a TableRef instead, then changes to `b` also affect `a`.
|
||||
## Both `a` and `b` reference the same data structure:
|
||||
##
|
||||
## .. code-block::
|
||||
## import tables
|
||||
##
|
||||
## var
|
||||
## a = {1: "one", 2: "two"}.newTable # creates a TableRef
|
||||
## b = a
|
||||
##
|
||||
## echo a, b # output: {1: one, 2: two}{1: one, 2: two}
|
||||
##
|
||||
## b[3] = "three"
|
||||
## echo a, b # output: {1: one, 2: two, 3: three}{1: one, 2: two, 3: three}
|
||||
## echo a == b # output: true
|
||||
##
|
||||
##
|
||||
## If you are using simple standard types like ``int`` or ``string`` for the
|
||||
## keys of the table you won't have any problems, but as soon as you try to use
|
||||
|
||||
@@ -1127,7 +1127,7 @@ proc parseJson(p: var JsonParser): JsonNode =
|
||||
discard getTok(p)
|
||||
while p.tok != tkCurlyRi:
|
||||
if p.tok != tkString:
|
||||
raiseParseErr(p, "string literal as key expected")
|
||||
raiseParseErr(p, "string literal as key")
|
||||
var key = p.a
|
||||
discard getTok(p)
|
||||
eat(p, tkColon)
|
||||
|
||||
@@ -452,10 +452,13 @@ proc rawNewObj(typ: PNimType, size: int, gch: var GcHeap): pointer =
|
||||
gcAssert((cast[ByteAddress](res) and (MemAlign-1)) == 0, "newObj: 2")
|
||||
# now it is buffered in the ZCT
|
||||
res.typ = typ
|
||||
when leakDetector and not hasThreadSupport:
|
||||
if framePtr != nil and framePtr.prev != nil:
|
||||
res.filename = framePtr.prev.filename
|
||||
res.line = framePtr.prev.line
|
||||
when leakDetector:
|
||||
res.filename = nil
|
||||
res.line = 0
|
||||
when not hasThreadSupport:
|
||||
if framePtr != nil and framePtr.prev != nil:
|
||||
res.filename = framePtr.prev.filename
|
||||
res.line = framePtr.prev.line
|
||||
# refcount is zero, color is black, but mark it to be in the ZCT
|
||||
res.refcount = ZctFlag
|
||||
sysAssert(isAllocatedPtr(gch.region, res), "newObj: 3")
|
||||
@@ -503,10 +506,13 @@ proc newObjRC1(typ: PNimType, size: int): pointer {.compilerRtl.} =
|
||||
sysAssert((cast[ByteAddress](res) and (MemAlign-1)) == 0, "newObj: 2")
|
||||
# now it is buffered in the ZCT
|
||||
res.typ = typ
|
||||
when leakDetector and not hasThreadSupport:
|
||||
if framePtr != nil and framePtr.prev != nil:
|
||||
res.filename = framePtr.prev.filename
|
||||
res.line = framePtr.prev.line
|
||||
when leakDetector:
|
||||
res.filename = nil
|
||||
res.line = 0
|
||||
when not hasThreadSupport:
|
||||
if framePtr != nil and framePtr.prev != nil:
|
||||
res.filename = framePtr.prev.filename
|
||||
res.line = framePtr.prev.line
|
||||
res.refcount = rcIncrement # refcount is 1
|
||||
sysAssert(isAllocatedPtr(gch.region, res), "newObj: 3")
|
||||
when logGC: writeCell("new cell", res)
|
||||
|
||||
@@ -65,6 +65,21 @@ proc hint*(name: string; val: bool) =
|
||||
let v = if val: "on" else: "off"
|
||||
hintImpl(name & "]:" & v, "hint[" & name & "]:" & v)
|
||||
|
||||
proc patchFile*(package, filename, replacement: string) =
|
||||
## Overrides the location of a given file belonging to the
|
||||
## passed package.
|
||||
## If the ``replacement`` is not an absolute path, the path
|
||||
## is interpreted to be local to the Nimscript file that contains
|
||||
## the call to ``patchFile``, Nim's ``--path`` is not used at all
|
||||
## to resolve the filename!
|
||||
##
|
||||
## Example:
|
||||
##
|
||||
## .. code-block:: nim
|
||||
##
|
||||
## patchFile("stdlib", "asyncdispatch", "patches/replacement")
|
||||
discard
|
||||
|
||||
proc getCommand*(): string =
|
||||
## Gets the Nim command that the compiler has been invoked with, for example
|
||||
## "c", "js", "build", "help".
|
||||
|
||||
Reference in New Issue
Block a user