mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 01:14:41 +00:00
Merge branch 'devel' into sighashes
This commit is contained in:
@@ -73,6 +73,10 @@ proc atomicTypeX(name: string; m: TMagic; t: PType; info: TLineInfo): PNode =
|
||||
result = newSymNode(sym)
|
||||
result.typ = t
|
||||
|
||||
proc atomicTypeX(s: PSym; info: TLineInfo): PNode =
|
||||
result = newSymNode(s)
|
||||
result.info = info
|
||||
|
||||
proc mapTypeToAstX(t: PType; info: TLineInfo;
|
||||
inst=false; allowRecursionX=false): PNode
|
||||
|
||||
@@ -103,6 +107,7 @@ proc mapTypeToAstX(t: PType; info: TLineInfo;
|
||||
inst=false; allowRecursionX=false): PNode =
|
||||
var allowRecursion = allowRecursionX
|
||||
template atomicType(name, m): untyped = atomicTypeX(name, m, t, info)
|
||||
template atomicType(s): untyped = atomicTypeX(s, info)
|
||||
template mapTypeToAst(t,info): untyped = mapTypeToAstX(t, info, inst)
|
||||
template mapTypeToAstR(t,info): untyped = mapTypeToAstX(t, info, inst, true)
|
||||
template mapTypeToAst(t,i,info): untyped =
|
||||
@@ -125,7 +130,7 @@ proc mapTypeToAstX(t: PType; info: TLineInfo;
|
||||
if allowRecursion: # getTypeImpl behavior: turn off recursion
|
||||
allowRecursion = false
|
||||
else: # getTypeInst behavior: return symbol
|
||||
return atomicType(t.sym.name.s, t.sym.magic)
|
||||
return atomicType(t.sym)
|
||||
|
||||
case t.kind
|
||||
of tyNone: result = atomicType("none", mNone)
|
||||
@@ -180,9 +185,9 @@ proc mapTypeToAstX(t: PType; info: TLineInfo;
|
||||
if allowRecursion or t.sym == nil:
|
||||
result = mapTypeToBracket("distinct", mDistinct, t, info)
|
||||
else:
|
||||
result = atomicType(t.sym.name.s, t.sym.magic)
|
||||
result = atomicType(t.sym)
|
||||
of tyGenericParam, tyForward:
|
||||
result = atomicType(t.sym.name.s, t.sym.magic)
|
||||
result = atomicType(t.sym)
|
||||
of tyObject:
|
||||
if inst:
|
||||
result = newNodeX(nkObjectTy)
|
||||
@@ -206,7 +211,7 @@ proc mapTypeToAstX(t: PType; info: TLineInfo;
|
||||
result.add mapTypeToAst(t.sons[0], info)
|
||||
result.add copyTree(t.n)
|
||||
else:
|
||||
result = atomicType(t.sym.name.s, t.sym.magic)
|
||||
result = atomicType(t.sym)
|
||||
of tyEnum:
|
||||
result = newNodeIT(nkEnumTy, if t.n.isNil: info else: t.n.info, t)
|
||||
result.add copyTree(t.n)
|
||||
|
||||
@@ -160,7 +160,10 @@ proc peekLast*[T](deq: Deque[T]): T {.inline.} =
|
||||
emptyCheck(deq)
|
||||
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.} =
|
||||
## Remove and returns the first element of the `deq`.
|
||||
emptyCheck(deq)
|
||||
|
||||
@@ -154,7 +154,10 @@ 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
|
||||
template default[T](t: typedesc[T]): T =
|
||||
var v: T
|
||||
v
|
||||
|
||||
proc pop*[T](q: var Queue[T]): T {.inline, discardable.} =
|
||||
## Remove and returns the first (oldest) element of the queue `q`.
|
||||
emptyCheck(q)
|
||||
|
||||
@@ -261,7 +261,9 @@ template doWhile(a, b) =
|
||||
b
|
||||
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) =
|
||||
## Excludes `key` from the set `s`.
|
||||
|
||||
@@ -954,7 +954,7 @@ proc inc*[A](t: var CountTable[A], key: A, val = 1) =
|
||||
inc(t.counter)
|
||||
|
||||
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
|
||||
var minIdx = 0
|
||||
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)
|
||||
|
||||
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
|
||||
|
||||
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.
|
||||
|
||||
|
||||
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:
|
||||
|
||||
.. code-block:: nim
|
||||
@@ -86,14 +86,14 @@ which we then use in our scanf pattern to help us in the matching process:
|
||||
result = 0
|
||||
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:
|
||||
|
||||
.. 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
|
||||
# matched or otherwise the number of processed chars.
|
||||
var x = 0
|
||||
|
||||
@@ -2595,6 +2595,14 @@ else:
|
||||
if x < 0: -x else: x
|
||||
{.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):
|
||||
{.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
|
||||
## 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
|
||||
## operations. The file's first byte has the index zero.
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ const
|
||||
alwaysCycleGC = defined(smokeCycles)
|
||||
alwaysGC = defined(fulldebug) # collect after every memory
|
||||
# allocation (for debugging)
|
||||
leakDetector = false
|
||||
leakDetector = defined(leakDetector)
|
||||
overwriteFree = defined(nimBurnFree) # overwrite memory with 0xFF before free
|
||||
trackAllocationSource = leakDetector
|
||||
|
||||
|
||||
@@ -336,8 +336,8 @@ proc open(f: var File, filehandle: FileHandle, mode: FileMode): bool =
|
||||
f = c_fdopen(filehandle, FormatOpen[mode])
|
||||
result = f != nil
|
||||
|
||||
proc setFilePos(f: File, pos: int64) =
|
||||
if c_fseek(f, clong(pos), 0) != 0:
|
||||
proc setFilePos(f: File, pos: int64, relativeTo: FileSeekPos = fspSet) =
|
||||
if c_fseek(f, clong(pos), cint(relativeTo)) != 0:
|
||||
raiseEIO("cannot set file position")
|
||||
|
||||
proc getFilePos(f: File): int64 =
|
||||
|
||||
Reference in New Issue
Block a user