Remove expr/stmt (#5857)
This commit is contained in:
parent
52ff244d5d
commit
000b8afd26
168 changed files with 497 additions and 529 deletions
|
|
@ -97,7 +97,7 @@ proc newObj(typ: PNimType, size: int): pointer {.importCompilerProc.}
|
|||
proc newSeq(typ: PNimType, len: int): pointer {.importCompilerProc.}
|
||||
proc objectInit(dest: pointer, typ: PNimType) {.importCompilerProc.}
|
||||
|
||||
template `+!!`(a, b: expr): expr = cast[pointer](cast[ByteAddress](a) + b)
|
||||
template `+!!`(a, b): untyped = cast[pointer](cast[ByteAddress](a) + b)
|
||||
|
||||
proc getDiscriminant(aa: pointer, n: ptr TNimNode): int =
|
||||
assert(n.kind == nkCase)
|
||||
|
|
|
|||
|
|
@ -206,16 +206,16 @@ proc htons*(x: int16): int16 =
|
|||
## order, this is a no-op; otherwise, it performs a 2-byte swap operation.
|
||||
result = sockets.ntohs(x)
|
||||
|
||||
template ntohl(x: uint32): expr =
|
||||
template ntohl(x: uint32): uint32 =
|
||||
cast[uint32](sockets.ntohl(cast[int32](x)))
|
||||
|
||||
template ntohs(x: uint16): expr =
|
||||
template ntohs(x: uint16): uint16 =
|
||||
cast[uint16](sockets.ntohs(cast[int16](x)))
|
||||
|
||||
template htonl(x: uint32): expr =
|
||||
template htonl(x: uint32): uint32 =
|
||||
sockets.ntohl(x)
|
||||
|
||||
template htons(x: uint16): expr =
|
||||
template htons(x: uint16): uint16 =
|
||||
sockets.ntohs(x)
|
||||
|
||||
when defined(Posix):
|
||||
|
|
@ -442,14 +442,13 @@ proc parseIp4*(s: string): BiggestInt =
|
|||
if s[i] != '\0': invalidIp4(s)
|
||||
result = BiggestInt(a shl 24 or b shl 16 or c shl 8 or d)
|
||||
|
||||
template gaiNim(a, p, h, list: expr): stmt =
|
||||
block:
|
||||
var gaiResult = getaddrinfo(a, $p, addr(h), list)
|
||||
if gaiResult != 0'i32:
|
||||
when defined(windows):
|
||||
raiseOSError(osLastError())
|
||||
else:
|
||||
raiseOSError(osLastError(), $gai_strerror(gaiResult))
|
||||
template gaiNim(a, p, h, list: untyped): untyped =
|
||||
var gaiResult = getaddrinfo(a, $p, addr(h), list)
|
||||
if gaiResult != 0'i32:
|
||||
when defined(windows):
|
||||
raiseOSError(osLastError())
|
||||
else:
|
||||
raiseOSError(osLastError(), $gai_strerror(gaiResult))
|
||||
|
||||
proc bindAddr*(socket: Socket, port = Port(0), address = "") {.
|
||||
tags: [ReadIOEffect].} =
|
||||
|
|
@ -493,8 +492,8 @@ proc getSockName*(socket: Socket): Port =
|
|||
raiseOSError(osLastError())
|
||||
result = Port(sockets.ntohs(name.sin_port))
|
||||
|
||||
template acceptAddrPlain(noClientRet, successRet: expr,
|
||||
sslImplementation: stmt): stmt {.immediate.} =
|
||||
template acceptAddrPlain(noClientRet, successRet: int,
|
||||
sslImplementation: untyped): untyped =
|
||||
assert(client != nil)
|
||||
var sockAddress: Sockaddr_in
|
||||
var addrLen = sizeof(sockAddress).SockLen
|
||||
|
|
@ -594,7 +593,7 @@ when defined(ssl):
|
|||
##
|
||||
## ``AcceptNoClient`` will be returned when no client is currently attempting
|
||||
## to connect.
|
||||
template doHandshake(): stmt =
|
||||
template doHandshake(): untyped =
|
||||
when defined(ssl):
|
||||
if server.isSSL:
|
||||
client.setBlocking(false)
|
||||
|
|
@ -1278,7 +1277,7 @@ proc recvLine*(socket: Socket, line: var TaintedString, timeout = -1): bool {.
|
|||
## **Deprecated since version 0.9.2**: This function has been deprecated in
|
||||
## favour of readLine.
|
||||
|
||||
template addNLIfEmpty(): stmt =
|
||||
template addNLIfEmpty(): untyped =
|
||||
if line.len == 0:
|
||||
line.add("\c\L")
|
||||
|
||||
|
|
@ -1319,7 +1318,7 @@ proc readLine*(socket: Socket, line: var TaintedString, timeout = -1) {.
|
|||
## A timeout can be specified in milliseconds, if data is not received within
|
||||
## the specified time an ETimeout exception will be raised.
|
||||
|
||||
template addNLIfEmpty(): stmt =
|
||||
template addNLIfEmpty(): untyped =
|
||||
if line.len == 0:
|
||||
line.add("\c\L")
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ proc checkNil(arg: string): string =
|
|||
else:
|
||||
return arg
|
||||
|
||||
template formatStr*(howExpr, namegetter, idgetter: expr): expr =
|
||||
template formatStr*(howExpr, namegetter, idgetter): untyped =
|
||||
let how = howExpr
|
||||
var val = newStringOfCap(how.len)
|
||||
var i = 0
|
||||
|
|
|
|||
|
|
@ -765,7 +765,7 @@ proc renderTocEntries*(d: var RstGenerator, j: var int, lvl: int,
|
|||
result.add(tmp)
|
||||
|
||||
proc renderImage(d: PDoc, n: PRstNode, result: var string) =
|
||||
template valid(s): expr =
|
||||
template valid(s): bool =
|
||||
s.len > 0 and allCharsInSet(s, {'.','/',':','%','_','\\','\128'..'\xFF'} +
|
||||
Digits + Letters + WhiteSpace)
|
||||
let
|
||||
|
|
@ -1194,7 +1194,7 @@ proc defaultConfig*(): StringTableRef =
|
|||
## ``rstToHtml`` to generate the bare minimum HTML.
|
||||
result = newStringTable(modeStyleInsensitive)
|
||||
|
||||
template setConfigVar(key, val: expr) =
|
||||
template setConfigVar(key, val) =
|
||||
result[key] = val
|
||||
|
||||
# If you need to modify these values, it might be worth updating the template
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@ var
|
|||
# Compare a character C to a value VAL from the `cc' array in a
|
||||
# `struct termios'. If VAL is _POSIX_VDISABLE, no character can match it.
|
||||
|
||||
template cceq*(val, c: expr): expr =
|
||||
template cceq*(val, c): untyped =
|
||||
c == val and val != POSIX_VDISABLE
|
||||
|
||||
# Return the output baud rate stored in *TERMIOS_P.
|
||||
|
|
|
|||
|
|
@ -1317,7 +1317,7 @@ proc recvLine*(socket: AsyncFD): Future[string] {.async, deprecated.} =
|
|||
##
|
||||
## **Deprecated since version 0.15.0**: Use ``asyncnet.recvLine()`` instead.
|
||||
|
||||
template addNLIfEmpty(): stmt =
|
||||
template addNLIfEmpty(): untyped =
|
||||
if result.len == 0:
|
||||
result.add("\c\L")
|
||||
|
||||
|
|
|
|||
|
|
@ -220,7 +220,7 @@ when defineSsl:
|
|||
raiseSSLError("Cannot appease SSL.")
|
||||
|
||||
template sslLoop(socket: AsyncSocket, flags: set[SocketFlag],
|
||||
op: expr) =
|
||||
op: untyped) =
|
||||
var opResult {.inject.} = -1.cint
|
||||
while opResult < 0:
|
||||
# Call the desired operation.
|
||||
|
|
@ -490,7 +490,7 @@ proc recvLineInto*(socket: AsyncSocket, resString: FutureVar[string],
|
|||
# them when the result future is completed.
|
||||
# Can we replace the result future with the FutureVar?
|
||||
|
||||
template addNLIfEmpty(): stmt =
|
||||
template addNLIfEmpty(): untyped =
|
||||
if resString.mget.len == 0:
|
||||
resString.mget.add("\c\L")
|
||||
|
||||
|
|
|
|||
|
|
@ -116,13 +116,13 @@ proc safeArccos(v:float):float=
|
|||
return arccos(clamp(v,-1.0,1.0))
|
||||
|
||||
|
||||
template makeBinOpVector(s:expr)=
|
||||
template makeBinOpVector(s) =
|
||||
## implements binary operators ``+``, ``-``, ``*`` and ``/`` for vectors
|
||||
proc s*(a,b:Vector2d):Vector2d {.inline,noInit.} = vector2d(s(a.x,b.x),s(a.y,b.y))
|
||||
proc s*(a:Vector2d,b:float):Vector2d {.inline,noInit.} = vector2d(s(a.x,b),s(a.y,b))
|
||||
proc s*(a:float,b:Vector2d):Vector2d {.inline,noInit.} = vector2d(s(a,b.x),s(a,b.y))
|
||||
|
||||
template makeBinOpAssignVector(s:expr)=
|
||||
template makeBinOpAssignVector(s)=
|
||||
## implements inplace binary operators ``+=``, ``-=``, ``/=`` and ``*=`` for vectors
|
||||
proc s*(a:var Vector2d,b:Vector2d) {.inline.} = s(a.x,b.x) ; s(a.y,b.y)
|
||||
proc s*(a:var Vector2d,b:float) {.inline.} = s(a.x,b) ; s(a.y,b)
|
||||
|
|
@ -853,5 +853,3 @@ proc degToRad*(deg:float):float {.inline.}=
|
|||
proc radToDeg*(rad:float):float {.inline.}=
|
||||
## converts `rad` radians to degrees
|
||||
rad * RAD2DEGCONST
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ proc safeArccos(v:float):float=
|
|||
## due to rounding issues
|
||||
return arccos(clamp(v,-1.0,1.0))
|
||||
|
||||
template makeBinOpVector(s:expr)=
|
||||
template makeBinOpVector(s) =
|
||||
proc s*(a,b:Vector3d):Vector3d {.inline,noInit.} =
|
||||
vector3d(s(a.x,b.x),s(a.y,b.y),s(a.z,b.z))
|
||||
proc s*(a:Vector3d,b:float):Vector3d {.inline,noInit.} =
|
||||
|
|
@ -124,7 +124,7 @@ template makeBinOpVector(s:expr)=
|
|||
proc s*(a:float,b:Vector3d):Vector3d {.inline,noInit.} =
|
||||
vector3d(s(a,b.x),s(a,b.y),s(a,b.z))
|
||||
|
||||
template makeBinOpAssignVector(s:expr)=
|
||||
template makeBinOpAssignVector(s) =
|
||||
proc s*(a:var Vector3d,b:Vector3d) {.inline.} =
|
||||
s(a.x,b.x); s(a.y,b.y); s(a.z,b.z)
|
||||
proc s*(a:var Vector3d,b:float) {.inline.} =
|
||||
|
|
|
|||
|
|
@ -143,15 +143,16 @@ proc `[]=`*[T](c: var CritBitTree[T], key: string, val: T) =
|
|||
var n = rawInsert(c, key)
|
||||
n.val = val
|
||||
|
||||
template get[T](c: CritBitTree[T], key: string): T {.immediate.} =
|
||||
template get[T](c: CritBitTree[T], key: string): T =
|
||||
let n = rawGet(c, key)
|
||||
if n != nil: result = n.val
|
||||
else:
|
||||
if n == nil:
|
||||
when compiles($key):
|
||||
raise newException(KeyError, "key not found: " & $key)
|
||||
else:
|
||||
raise newException(KeyError, "key not found")
|
||||
|
||||
n.val
|
||||
|
||||
proc `[]`*[T](c: CritBitTree[T], key: string): T {.inline, deprecatedGet.} =
|
||||
## retrieves the value at ``c[key]``. If `key` is not in `t`, the
|
||||
## ``KeyError`` exception is raised. One can check with ``hasKey`` whether
|
||||
|
|
|
|||
|
|
@ -189,7 +189,7 @@ iterator items*(s: IntSet): int {.inline.} =
|
|||
inc(i)
|
||||
r = r.next
|
||||
|
||||
template dollarImpl(): stmt =
|
||||
template dollarImpl(): untyped =
|
||||
result = "{"
|
||||
for key in items(s):
|
||||
if result.len > 1: result.add(", ")
|
||||
|
|
|
|||
|
|
@ -455,7 +455,7 @@ template anyIt*(seq1, pred: untyped): bool =
|
|||
break
|
||||
result
|
||||
|
||||
template toSeq*(iter: untyped): untyped {.oldimmediate.} =
|
||||
template toSeq*(iter: untyped): untyped =
|
||||
## Transforms any iterator into a sequence.
|
||||
##
|
||||
## Example:
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ type
|
|||
counter, dataLen: int
|
||||
lock: Lock
|
||||
|
||||
template maxHash(t): expr = t.dataLen-1
|
||||
template maxHash(t): untyped = t.dataLen-1
|
||||
|
||||
include tableimpl
|
||||
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ template addImpl(enlarge) {.dirty.} =
|
|||
rawInsert(t, t.data, key, val, hc, j)
|
||||
inc(t.counter)
|
||||
|
||||
template maybeRehashPutImpl(enlarge) {.oldimmediate, dirty.} =
|
||||
template maybeRehashPutImpl(enlarge) {.dirty.} =
|
||||
if mustRehash(t.dataLen, t.counter):
|
||||
enlarge(t)
|
||||
index = rawGetKnownHC(t, key, hc)
|
||||
|
|
@ -93,7 +93,7 @@ template maybeRehashPutImpl(enlarge) {.oldimmediate, dirty.} =
|
|||
rawInsert(t, t.data, key, val, hc, index)
|
||||
inc(t.counter)
|
||||
|
||||
template putImpl(enlarge) {.oldimmediate, dirty.} =
|
||||
template putImpl(enlarge) {.dirty.} =
|
||||
var hc: Hash
|
||||
var index = rawGet(t, key, hc)
|
||||
if index >= 0: t.data[index].val = val
|
||||
|
|
|
|||
|
|
@ -19,18 +19,18 @@ type
|
|||
proc `==` *(a, b: Color): bool {.borrow.}
|
||||
## compares two colors.
|
||||
|
||||
template extract(a: Color, r, g, b: expr) {.immediate.}=
|
||||
template extract(a: Color, r, g, b: untyped) =
|
||||
var r = a.int shr 16 and 0xff
|
||||
var g = a.int shr 8 and 0xff
|
||||
var b = a.int and 0xff
|
||||
|
||||
template rawRGB(r, g, b: int): expr =
|
||||
template rawRGB(r, g, b: int): Color =
|
||||
Color(r shl 16 or g shl 8 or b)
|
||||
|
||||
template colorOp(op: expr) {.immediate.} =
|
||||
template colorOp(op): Color =
|
||||
extract(a, ar, ag, ab)
|
||||
extract(b, br, bg, bb)
|
||||
result = rawRGB(op(ar, br), op(ag, bg), op(ab, bb))
|
||||
rawRGB(op(ar, br), op(ag, bg), op(ab, bb))
|
||||
|
||||
proc satPlus(a, b: int): int {.inline.} =
|
||||
result = a +% b
|
||||
|
|
@ -67,12 +67,12 @@ proc intensity*(a: Color, f: float): Color =
|
|||
if b >% 255: b = 255
|
||||
result = rawRGB(r, g, b)
|
||||
|
||||
template mix*(a, b: Color, fn: expr): expr =
|
||||
template mix*(a, b: Color, fn: untyped): untyped =
|
||||
## uses `fn` to mix the colors `a` and `b`. `fn` is invoked for each component
|
||||
## R, G, and B. This is a template because `fn` should be inlined and the
|
||||
## compiler cannot inline proc pointers yet. If `fn`'s result is not in the
|
||||
## range[0..255], it will be saturated to be so.
|
||||
template `><` (x: expr): expr =
|
||||
template `><` (x: untyped): untyped =
|
||||
# keep it in the range 0..255
|
||||
block:
|
||||
var y = x # eval only once
|
||||
|
|
|
|||
|
|
@ -409,20 +409,20 @@ proc preferSpawn*(): bool =
|
|||
## it is not necessary to call this directly; use 'spawnX' instead.
|
||||
result = gSomeReady.counter > 0
|
||||
|
||||
proc spawn*(call: expr): expr {.magic: "Spawn".}
|
||||
proc spawn*(call: typed): void {.magic: "Spawn".}
|
||||
## always spawns a new task, so that the 'call' is never executed on
|
||||
## the calling thread. 'call' has to be proc call 'p(...)' where 'p'
|
||||
## is gcsafe and has a return type that is either 'void' or compatible
|
||||
## with ``FlowVar[T]``.
|
||||
|
||||
proc pinnedSpawn*(id: ThreadId; call: expr): expr {.magic: "Spawn".}
|
||||
proc pinnedSpawn*(id: ThreadId; call: typed): void {.magic: "Spawn".}
|
||||
## always spawns a new task on the worker thread with ``id``, so that
|
||||
## the 'call' is **always** executed on
|
||||
## the thread. 'call' has to be proc call 'p(...)' where 'p'
|
||||
## is gcsafe and has a return type that is either 'void' or compatible
|
||||
## with ``FlowVar[T]``.
|
||||
|
||||
template spawnX*(call: expr): expr =
|
||||
template spawnX*(call): void =
|
||||
## spawns a new task if a CPU core is ready, otherwise executes the
|
||||
## call in the calling thread. Usually it is advised to
|
||||
## use 'spawn' in order to not block the producer for an unknown
|
||||
|
|
@ -431,7 +431,7 @@ template spawnX*(call: expr): expr =
|
|||
## with ``FlowVar[T]``.
|
||||
(if preferSpawn(): spawn call else: call)
|
||||
|
||||
proc parallel*(body: stmt) {.magic: "Parallel".}
|
||||
proc parallel*(body: untyped) {.magic: "Parallel".}
|
||||
## a parallel section can be used to execute a block in parallel. ``body``
|
||||
## has to be in a DSL that is a particular subset of the language. Please
|
||||
## refer to the manual for further information.
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ proc open*(filename: string, mode: FileMode = fmRead,
|
|||
result.size = 0
|
||||
|
||||
when defined(windows):
|
||||
template fail(errCode: OSErrorCode, msg: expr) =
|
||||
template fail(errCode: OSErrorCode, msg: untyped) =
|
||||
rollback()
|
||||
if result.fHandle != 0: discard closeHandle(result.fHandle)
|
||||
if result.mapHandle != 0: discard closeHandle(result.mapHandle)
|
||||
|
|
@ -131,7 +131,7 @@ proc open*(filename: string, mode: FileMode = fmRead,
|
|||
# return false
|
||||
#raise newException(EIO, msg)
|
||||
|
||||
template callCreateFile(winApiProc, filename: expr): expr =
|
||||
template callCreateFile(winApiProc, filename): untyped =
|
||||
winApiProc(
|
||||
filename,
|
||||
# GENERIC_ALL != (GENERIC_READ or GENERIC_WRITE)
|
||||
|
|
@ -198,7 +198,7 @@ proc open*(filename: string, mode: FileMode = fmRead,
|
|||
result.fHandle = INVALID_HANDLE_VALUE
|
||||
|
||||
else:
|
||||
template fail(errCode: OSErrorCode, msg: expr) =
|
||||
template fail(errCode: OSErrorCode, msg: string) =
|
||||
rollback()
|
||||
if result.handle != -1: discard close(result.handle)
|
||||
raiseOSError(errCode)
|
||||
|
|
|
|||
|
|
@ -797,7 +797,7 @@ when false: #defineSsl:
|
|||
##
|
||||
## ``AcceptNoClient`` will be returned when no client is currently attempting
|
||||
## to connect.
|
||||
template doHandshake(): stmt =
|
||||
template doHandshake(): untyped =
|
||||
when defineSsl:
|
||||
if server.isSSL:
|
||||
client.setBlocking(false)
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ proc addChoice(dest: var Peg, elem: Peg) =
|
|||
else: add(dest, elem)
|
||||
else: add(dest, elem)
|
||||
|
||||
template multipleOp(k: PegKind, localOpt: expr) =
|
||||
template multipleOp(k: PegKind, localOpt: untyped) =
|
||||
result.kind = k
|
||||
result.sons = @[]
|
||||
for x in items(a):
|
||||
|
|
@ -328,32 +328,32 @@ proc newNonTerminal*(name: string, line, column: int): NonTerminal {.
|
|||
result.line = line
|
||||
result.col = column
|
||||
|
||||
template letters*: expr =
|
||||
template letters*: Peg =
|
||||
## expands to ``charset({'A'..'Z', 'a'..'z'})``
|
||||
charSet({'A'..'Z', 'a'..'z'})
|
||||
|
||||
template digits*: expr =
|
||||
template digits*: Peg =
|
||||
## expands to ``charset({'0'..'9'})``
|
||||
charSet({'0'..'9'})
|
||||
|
||||
template whitespace*: expr =
|
||||
template whitespace*: Peg =
|
||||
## expands to ``charset({' ', '\9'..'\13'})``
|
||||
charSet({' ', '\9'..'\13'})
|
||||
|
||||
template identChars*: expr =
|
||||
template identChars*: Peg =
|
||||
## expands to ``charset({'a'..'z', 'A'..'Z', '0'..'9', '_'})``
|
||||
charSet({'a'..'z', 'A'..'Z', '0'..'9', '_'})
|
||||
|
||||
template identStartChars*: expr =
|
||||
template identStartChars*: Peg =
|
||||
## expands to ``charset({'A'..'Z', 'a'..'z', '_'})``
|
||||
charSet({'a'..'z', 'A'..'Z', '_'})
|
||||
|
||||
template ident*: expr =
|
||||
template ident*: Peg =
|
||||
## same as ``[a-zA-Z_][a-zA-z_0-9]*``; standard identifier
|
||||
sequence(charSet({'a'..'z', 'A'..'Z', '_'}),
|
||||
*charSet({'a'..'z', 'A'..'Z', '0'..'9', '_'}))
|
||||
|
||||
template natural*: expr =
|
||||
template natural*: Peg =
|
||||
## same as ``\d+``
|
||||
+digits
|
||||
|
||||
|
|
@ -514,10 +514,10 @@ proc bounds*(c: Captures,
|
|||
when not useUnicode:
|
||||
type
|
||||
Rune = char
|
||||
template fastRuneAt(s, i, ch: expr) =
|
||||
template fastRuneAt(s, i, ch) =
|
||||
ch = s[i]
|
||||
inc(i)
|
||||
template runeLenAt(s, i: expr): expr = 1
|
||||
template runeLenAt(s, i): untyped = 1
|
||||
|
||||
proc isAlpha(a: char): bool {.inline.} = return a in {'a'..'z','A'..'Z'}
|
||||
proc isUpper(a: char): bool {.inline.} = return a in {'A'..'Z'}
|
||||
|
|
@ -735,7 +735,7 @@ proc rawMatch*(s: string, p: Peg, start: int, c: var Captures): int {.
|
|||
else: result = -1
|
||||
of pkRule, pkList: assert false
|
||||
|
||||
template fillMatches(s, caps, c: expr) =
|
||||
template fillMatches(s, caps, c) =
|
||||
for k in 0..c.ml-1:
|
||||
let startIdx = c.matches[k][0]
|
||||
let endIdx = c.matches[k][1]
|
||||
|
|
|
|||
|
|
@ -46,12 +46,12 @@ type
|
|||
num, i, lineLen: int
|
||||
{.deprecated: [TFormatParser: FormatParser].}
|
||||
|
||||
template call(x: stmt) {.immediate.} =
|
||||
template call(x: untyped): untyped =
|
||||
p.i = i
|
||||
x
|
||||
i = p.i
|
||||
|
||||
template callNoLineLenTracking(x: stmt) {.immediate.} =
|
||||
template callNoLineLenTracking(x: untyped): untyped =
|
||||
let oldLineLen = p.lineLen
|
||||
p.i = i
|
||||
x
|
||||
|
|
|
|||
|
|
@ -578,7 +578,7 @@ template styledEchoProcessArg(f: File, cmd: TerminalCmd) =
|
|||
when cmd == resetStyle:
|
||||
resetAttributes(f)
|
||||
|
||||
macro styledWriteLine*(f: File, m: varargs[expr]): stmt =
|
||||
macro styledWriteLine*(f: File, m: varargs[typed]): untyped =
|
||||
## Similar to ``writeLine``, but treating terminal style arguments specially.
|
||||
## When some argument is ``Style``, ``set[Style]``, ``ForegroundColor``,
|
||||
## ``BackgroundColor`` or ``TerminalCmd`` then it is not sent directly to
|
||||
|
|
@ -614,16 +614,13 @@ macro styledWriteLine*(f: File, m: varargs[expr]): stmt =
|
|||
result.add(newCall(bindSym"write", f, newStrLitNode("\n")))
|
||||
if reset: result.add(newCall(bindSym"resetAttributes", f))
|
||||
|
||||
macro callStyledEcho(args: varargs[expr]): stmt =
|
||||
macro styledEcho*(args: varargs[untyped]): untyped =
|
||||
## Echoes styles arguments to stdout using ``styledWriteLine``.
|
||||
result = newCall(bindSym"styledWriteLine")
|
||||
result.add(bindSym"stdout")
|
||||
for arg in children(args[0][1]):
|
||||
for arg in children(args):
|
||||
result.add(arg)
|
||||
|
||||
template styledEcho*(args: varargs[expr]): expr =
|
||||
## Echoes styles arguments to stdout using ``styledWriteLine``.
|
||||
callStyledEcho(args)
|
||||
|
||||
proc getch*(): char =
|
||||
## Read a single character from the terminal, blocking until it is entered.
|
||||
## The character is not printed to the terminal.
|
||||
|
|
|
|||
|
|
@ -215,7 +215,7 @@ proc combine*(base: Uri, reference: Uri): Uri =
|
|||
## let bar = combine(parseUri("http://example.com/foo/bar/"), parseUri("baz"))
|
||||
## assert bar.path == "/foo/bar/baz"
|
||||
|
||||
template setAuthority(dest, src: expr): stmt =
|
||||
template setAuthority(dest, src): untyped =
|
||||
dest.hostname = src.hostname
|
||||
dest.username = src.username
|
||||
dest.port = src.port
|
||||
|
|
|
|||
|
|
@ -338,7 +338,7 @@ proc xmlConstructor(e: NimNode): NimNode {.compileTime.} =
|
|||
else:
|
||||
result = newCall("newXmlTree", toStrLit(a))
|
||||
|
||||
macro `<>`*(x: expr): expr {.immediate.} =
|
||||
macro `<>`*(x: untyped): untyped =
|
||||
## Constructor macro for XML. Example usage:
|
||||
##
|
||||
## .. code-block:: nim
|
||||
|
|
|
|||
|
|
@ -80,9 +80,10 @@ type
|
|||
`nil` {.magic: "Nil".}
|
||||
|
||||
expr* {.magic: Expr, deprecated.} ## meta type to denote an expression (for templates)
|
||||
## **Deprecated** since version 0.15. Use ``untyped`` instead.
|
||||
## **Deprecated** since version 0.15. Use ``untyped`` instead.
|
||||
stmt* {.magic: Stmt, deprecated.} ## meta type to denote a statement (for templates)
|
||||
## **Deprecated** since version 0.15. Use ``typed`` instead.
|
||||
## **Deprecated** since version 0.15. Use ``typed`` instead.
|
||||
|
||||
void* {.magic: "VoidType".} ## meta type to denote the absence of any type
|
||||
auto* {.magic: Expr.} ## meta type for automatic type determination
|
||||
any* = distinct auto ## meta type for any supported type
|
||||
|
|
@ -1951,30 +1952,34 @@ iterator countdown*[T](a, b: T, step = 1): T {.inline.} =
|
|||
yield res
|
||||
dec(res, step)
|
||||
|
||||
template countupImpl(incr: untyped) {.oldimmediate, dirty.} =
|
||||
when T is IntLikeForCount:
|
||||
var res = int(a)
|
||||
while res <= int(b):
|
||||
yield T(res)
|
||||
incr
|
||||
else:
|
||||
var res: T = T(a)
|
||||
while res <= b:
|
||||
yield res
|
||||
incr
|
||||
|
||||
iterator countup*[S, T](a: S, b: T, step = 1): T {.inline.} =
|
||||
## Counts from ordinal value `a` up to `b` (inclusive) with the given
|
||||
## step count. `S`, `T` may be any ordinal type, `step` may only
|
||||
## be positive. **Note**: This fails to count to ``high(int)`` if T = int for
|
||||
## efficiency reasons.
|
||||
countupImpl:
|
||||
inc(res, step)
|
||||
when T is IntLikeForCount:
|
||||
var res = int(a)
|
||||
while res <= int(b):
|
||||
yield T(res)
|
||||
inc(res, step)
|
||||
else:
|
||||
var res: T = T(a)
|
||||
while res <= b:
|
||||
yield res
|
||||
inc(res, step)
|
||||
|
||||
iterator `..`*[S, T](a: S, b: T): T {.inline.} =
|
||||
## An alias for `countup`.
|
||||
countupImpl:
|
||||
inc(res)
|
||||
when T is IntLikeForCount:
|
||||
var res = int(a)
|
||||
while res <= int(b):
|
||||
yield T(res)
|
||||
inc(res)
|
||||
else:
|
||||
var res: T = T(a)
|
||||
while res <= b:
|
||||
yield res
|
||||
inc(res)
|
||||
|
||||
iterator `||`*[S, T](a: S, b: T, annotation=""): T {.
|
||||
inline, magic: "OmpParFor", sideEffect.} =
|
||||
|
|
|
|||
|
|
@ -203,12 +203,12 @@ proc rawRecv(q: PRawChannel, data: pointer, typ: PNimType) =
|
|||
storeAux(data, addr(q.data[q.rd * typ.size]), typ, q, mLoad)
|
||||
q.rd = (q.rd + 1) and q.mask
|
||||
|
||||
template lockChannel(q: expr, action: stmt) {.immediate.} =
|
||||
template lockChannel(q, action): untyped =
|
||||
acquireSys(q.lock)
|
||||
action
|
||||
releaseSys(q.lock)
|
||||
|
||||
template sendImpl(q: expr) {.immediate.} =
|
||||
template sendImpl(q) =
|
||||
if q.mask == ChannelDeadMask:
|
||||
sysFatal(DeadThreadError, "cannot send message; thread died")
|
||||
acquireSys(q.lock)
|
||||
|
|
|
|||
|
|
@ -276,11 +276,11 @@ proc raiseExceptionAux(e: ref Exception) =
|
|||
quitOrDebug()
|
||||
else:
|
||||
# ugly, but avoids heap allocations :-)
|
||||
template xadd(buf, s, slen: expr) =
|
||||
template xadd(buf, s, slen) =
|
||||
if L + slen < high(buf):
|
||||
copyMem(addr(buf[L]), cstring(s), slen)
|
||||
inc L, slen
|
||||
template add(buf, s: expr) =
|
||||
template add(buf, s) =
|
||||
xadd(buf, s, s.len)
|
||||
var buf: array[0..2000, char]
|
||||
var L = 0
|
||||
|
|
@ -387,7 +387,8 @@ when not defined(noSignalHandler):
|
|||
GC_enable()
|
||||
else:
|
||||
var msg: cstring
|
||||
template asgn(y: expr) = msg = y
|
||||
template asgn(y) =
|
||||
msg = y
|
||||
processSignal(sign, asgn)
|
||||
showErrorMessage(msg)
|
||||
when defined(endb): dbgAborting = true
|
||||
|
|
|
|||
|
|
@ -447,7 +447,7 @@ proc threadProcWrapStackFrame[TArg](thrd: ptr Thread[TArg]) =
|
|||
else:
|
||||
threadProcWrapDispatch(thrd)
|
||||
|
||||
template threadProcWrapperBody(closure: expr) {.immediate.} =
|
||||
template threadProcWrapperBody(closure: untyped): untyped =
|
||||
var thrd = cast[ptr Thread[TArg]](closure)
|
||||
var core = thrd.core
|
||||
when declared(globalsSlot): threadVarSetValue(globalsSlot, thrd.core)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue