Merge branch 'devel' of github.com:nim-lang/Nim into devel
This commit is contained in:
commit
30df922409
8 changed files with 28 additions and 12 deletions
|
|
@ -160,7 +160,10 @@ proc peekLast*[T](deq: Deque[T]): T {.inline.} =
|
||||||
emptyCheck(deq)
|
emptyCheck(deq)
|
||||||
result = deq.data[(deq.tail - 1) and deq.mask]
|
result = deq.data[(deq.tail - 1) and deq.mask]
|
||||||
|
|
||||||
proc default[T](t: typedesc[T]): T {.inline.} = discard
|
template default[T](t: typedesc[T]): T =
|
||||||
|
var v: T
|
||||||
|
v
|
||||||
|
|
||||||
proc popFirst*[T](deq: var Deque[T]): T {.inline, discardable.} =
|
proc popFirst*[T](deq: var Deque[T]): T {.inline, discardable.} =
|
||||||
## Remove and returns the first element of the `deq`.
|
## Remove and returns the first element of the `deq`.
|
||||||
emptyCheck(deq)
|
emptyCheck(deq)
|
||||||
|
|
|
||||||
|
|
@ -154,7 +154,10 @@ proc add*[T](q: var Queue[T], item: T) =
|
||||||
q.data[q.wr] = item
|
q.data[q.wr] = item
|
||||||
q.wr = (q.wr + 1) and q.mask
|
q.wr = (q.wr + 1) and q.mask
|
||||||
|
|
||||||
proc default[T](t: typedesc[T]): T {.inline.} = discard
|
template default[T](t: typedesc[T]): T =
|
||||||
|
var v: T
|
||||||
|
v
|
||||||
|
|
||||||
proc pop*[T](q: var Queue[T]): T {.inline, discardable.} =
|
proc pop*[T](q: var Queue[T]): T {.inline, discardable.} =
|
||||||
## Remove and returns the first (oldest) element of the queue `q`.
|
## Remove and returns the first (oldest) element of the queue `q`.
|
||||||
emptyCheck(q)
|
emptyCheck(q)
|
||||||
|
|
|
||||||
|
|
@ -261,7 +261,9 @@ template doWhile(a, b) =
|
||||||
b
|
b
|
||||||
if not a: break
|
if not a: break
|
||||||
|
|
||||||
proc default[T](t: typedesc[T]): T {.inline.} = discard
|
template default[T](t: typedesc[T]): T =
|
||||||
|
var v: T
|
||||||
|
v
|
||||||
|
|
||||||
proc excl*[A](s: var HashSet[A], key: A) =
|
proc excl*[A](s: var HashSet[A], key: A) =
|
||||||
## Excludes `key` from the set `s`.
|
## Excludes `key` from the set `s`.
|
||||||
|
|
|
||||||
|
|
@ -954,7 +954,7 @@ proc inc*[A](t: var CountTable[A], key: A, val = 1) =
|
||||||
inc(t.counter)
|
inc(t.counter)
|
||||||
|
|
||||||
proc smallest*[A](t: CountTable[A]): tuple[key: A, val: int] =
|
proc smallest*[A](t: CountTable[A]): tuple[key: A, val: int] =
|
||||||
## returns the largest (key,val)-pair. Efficiency: O(n)
|
## returns the (key,val)-pair with the smallest `val`. Efficiency: O(n)
|
||||||
assert t.len > 0
|
assert t.len > 0
|
||||||
var minIdx = 0
|
var minIdx = 0
|
||||||
for h in 1..high(t.data):
|
for h in 1..high(t.data):
|
||||||
|
|
@ -1080,7 +1080,7 @@ proc inc*[A](t: CountTableRef[A], key: A, val = 1) =
|
||||||
t[].inc(key, val)
|
t[].inc(key, val)
|
||||||
|
|
||||||
proc smallest*[A](t: CountTableRef[A]): (A, int) =
|
proc smallest*[A](t: CountTableRef[A]): (A, int) =
|
||||||
## returns the largest (key,val)-pair. Efficiency: O(n)
|
## returns the (key,val)-pair with the smallest `val`. Efficiency: O(n)
|
||||||
t[].smallest
|
t[].smallest
|
||||||
|
|
||||||
proc largest*[A](t: CountTableRef[A]): (A, int) =
|
proc largest*[A](t: CountTableRef[A]): (A, int) =
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ to a variable (that was passed to the ``scanf`` macro) while ``$[]`` merely
|
||||||
optional tokens.
|
optional tokens.
|
||||||
|
|
||||||
|
|
||||||
In this example, we define a helper proc ``skipSep`` that skips some separators
|
In this example, we define a helper proc ``someSep`` that skips some separators
|
||||||
which we then use in our scanf pattern to help us in the matching process:
|
which we then use in our scanf pattern to help us in the matching process:
|
||||||
|
|
||||||
.. code-block:: nim
|
.. code-block:: nim
|
||||||
|
|
@ -86,14 +86,14 @@ which we then use in our scanf pattern to help us in the matching process:
|
||||||
result = 0
|
result = 0
|
||||||
while input[start+result] in seps: inc result
|
while input[start+result] in seps: inc result
|
||||||
|
|
||||||
if scanf(input, "$w${someSep}$w", key, value):
|
if scanf(input, "$w$[someSep]$w", key, value):
|
||||||
...
|
...
|
||||||
|
|
||||||
It also possible to pass arguments to a user definable matcher:
|
It also possible to pass arguments to a user definable matcher:
|
||||||
|
|
||||||
.. code-block:: nim
|
.. code-block:: nim
|
||||||
|
|
||||||
proc ndigits(input: string; start: int; intVal: var int; n: int): int =
|
proc ndigits(input: string; intVal: var int; start: int; n: int): int =
|
||||||
# matches exactly ``n`` digits. Matchers need to return 0 if nothing
|
# matches exactly ``n`` digits. Matchers need to return 0 if nothing
|
||||||
# matched or otherwise the number of processed chars.
|
# matched or otherwise the number of processed chars.
|
||||||
var x = 0
|
var x = 0
|
||||||
|
|
|
||||||
|
|
@ -2595,6 +2595,14 @@ else:
|
||||||
if x < 0: -x else: x
|
if x < 0: -x else: x
|
||||||
{.pop.}
|
{.pop.}
|
||||||
|
|
||||||
|
type
|
||||||
|
FileSeekPos* = enum ## Position relative to which seek should happen
|
||||||
|
# The values are ordered so that they match with stdio
|
||||||
|
# SEEK_SET, SEEK_CUR and SEEK_END respectively.
|
||||||
|
fspSet ## Seek to absolute value
|
||||||
|
fspCur ## Seek relative to current position
|
||||||
|
fspEnd ## Seek relative to end
|
||||||
|
|
||||||
when not defined(JS): #and not defined(nimscript):
|
when not defined(JS): #and not defined(nimscript):
|
||||||
{.push stack_trace: off, profiler:off.}
|
{.push stack_trace: off, profiler:off.}
|
||||||
|
|
||||||
|
|
@ -2858,7 +2866,7 @@ when not defined(JS): #and not defined(nimscript):
|
||||||
## file `f`. Returns the number of actual written bytes, which may be less
|
## file `f`. Returns the number of actual written bytes, which may be less
|
||||||
## than `len` in case of an error.
|
## than `len` in case of an error.
|
||||||
|
|
||||||
proc setFilePos*(f: File, pos: int64) {.benign.}
|
proc setFilePos*(f: File, pos: int64, relativeTo: FileSeekPos = fspSet) {.benign.}
|
||||||
## sets the position of the file pointer that is used for read/write
|
## sets the position of the file pointer that is used for read/write
|
||||||
## operations. The file's first byte has the index zero.
|
## operations. The file's first byte has the index zero.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ const
|
||||||
alwaysCycleGC = defined(smokeCycles)
|
alwaysCycleGC = defined(smokeCycles)
|
||||||
alwaysGC = defined(fulldebug) # collect after every memory
|
alwaysGC = defined(fulldebug) # collect after every memory
|
||||||
# allocation (for debugging)
|
# allocation (for debugging)
|
||||||
leakDetector = false
|
leakDetector = defined(leakDetector)
|
||||||
overwriteFree = defined(nimBurnFree) # overwrite memory with 0xFF before free
|
overwriteFree = defined(nimBurnFree) # overwrite memory with 0xFF before free
|
||||||
trackAllocationSource = leakDetector
|
trackAllocationSource = leakDetector
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -336,8 +336,8 @@ proc open(f: var File, filehandle: FileHandle, mode: FileMode): bool =
|
||||||
f = c_fdopen(filehandle, FormatOpen[mode])
|
f = c_fdopen(filehandle, FormatOpen[mode])
|
||||||
result = f != nil
|
result = f != nil
|
||||||
|
|
||||||
proc setFilePos(f: File, pos: int64) =
|
proc setFilePos(f: File, pos: int64, relativeTo: FileSeekPos = fspSet) =
|
||||||
if c_fseek(f, clong(pos), 0) != 0:
|
if c_fseek(f, clong(pos), cint(relativeTo)) != 0:
|
||||||
raiseEIO("cannot set file position")
|
raiseEIO("cannot set file position")
|
||||||
|
|
||||||
proc getFilePos(f: File): int64 =
|
proc getFilePos(f: File): int64 =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue