Merge ../Nim into devel
This commit is contained in:
commit
8b38e8b2a4
2 changed files with 22 additions and 8 deletions
|
|
@ -124,7 +124,8 @@ export Port, SocketFlag
|
||||||
##
|
##
|
||||||
## * The effect system (``raises: []``) does not work with async procedures.
|
## * The effect system (``raises: []``) does not work with async procedures.
|
||||||
## * Can't await in a ``except`` body
|
## * Can't await in a ``except`` body
|
||||||
|
## * Forward declarations for async procs are broken,
|
||||||
|
## link includes workaround: https://github.com/nim-lang/Nim/issues/3182.
|
||||||
|
|
||||||
# TODO: Check if yielded future is nil and throw a more meaningful exception
|
# TODO: Check if yielded future is nil and throw a more meaningful exception
|
||||||
|
|
||||||
|
|
@ -1412,9 +1413,9 @@ proc getName(node: NimNode): string {.compileTime.} =
|
||||||
else:
|
else:
|
||||||
error("Unknown name.")
|
error("Unknown name.")
|
||||||
|
|
||||||
macro async*(prc: stmt): stmt {.immediate.} =
|
proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} =
|
||||||
## Macro which processes async procedures into the appropriate
|
## This macro transforms a single procedure into a closure iterator.
|
||||||
## iterators and yield statements.
|
## The ``async`` macro supports a stmtList holding multiple async procedures.
|
||||||
if prc.kind notin {nnkProcDef, nnkLambda}:
|
if prc.kind notin {nnkProcDef, nnkLambda}:
|
||||||
error("Cannot transform this node kind into an async proc." &
|
error("Cannot transform this node kind into an async proc." &
|
||||||
" Proc definition or lambda node expected.")
|
" Proc definition or lambda node expected.")
|
||||||
|
|
@ -1504,9 +1505,19 @@ macro async*(prc: stmt): stmt {.immediate.} =
|
||||||
result[6] = outerProcBody
|
result[6] = outerProcBody
|
||||||
|
|
||||||
#echo(treeRepr(result))
|
#echo(treeRepr(result))
|
||||||
if prc[0].getName == "getAsync":
|
if prc[0].getName == "hubConnectionLoop":
|
||||||
echo(toStrLit(result))
|
echo(toStrLit(result))
|
||||||
|
|
||||||
|
macro async*(prc: stmt): stmt {.immediate.} =
|
||||||
|
## Macro which processes async procedures into the appropriate
|
||||||
|
## iterators and yield statements.
|
||||||
|
if prc.kind == nnkStmtList:
|
||||||
|
for oneProc in prc:
|
||||||
|
result = newStmtList()
|
||||||
|
result.add asyncSingleProc(oneProc)
|
||||||
|
else:
|
||||||
|
result = asyncSingleProc(prc)
|
||||||
|
|
||||||
proc recvLine*(socket: AsyncFD): Future[string] {.async.} =
|
proc recvLine*(socket: AsyncFD): Future[string] {.async.} =
|
||||||
## Reads a line of data from ``socket``. Returned future will complete once
|
## Reads a line of data from ``socket``. Returned future will complete once
|
||||||
## a full line is read or an error occurs.
|
## a full line is read or an error occurs.
|
||||||
|
|
|
||||||
|
|
@ -178,7 +178,10 @@ proc new*[T](a: var ref T) {.magic: "New", noSideEffect.}
|
||||||
|
|
||||||
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``,
|
||||||
|
## otherwise it will be ``ref T``.
|
||||||
when (T is ref):
|
when (T is ref):
|
||||||
var r: T
|
var r: T
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue