diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2019-07-19 16:47:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-19 16:47:38 +0200 |
commit | 70e8551e37ab66658f7b45b325ea6b7ac2bf3cb7 (patch) | |
tree | d5e9943e7c94ecfa90d29aaa2b137a9739bedf22 /lib | |
parent | 903d06bab8ba6c5fd2e30fb29dfc327f304f1ae1 (diff) | |
download | Nim-70e8551e37ab66658f7b45b325ea6b7ac2bf3cb7.tar.gz |
async macro: general stability improvements [bugfix] (#11787)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/asyncmacro.nim | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/lib/pure/asyncmacro.nim b/lib/pure/asyncmacro.nim index 477011285..e9c6f9322 100644 --- a/lib/pure/asyncmacro.nim +++ b/lib/pure/asyncmacro.nim @@ -129,7 +129,7 @@ proc processBody(node, retFutureSym: NimNode, result.add newNimNode(nnkReturnStmt, node).add(newNilLit()) return # Don't process the children of this return stmt of nnkCommand, nnkCall: - if node[0].kind == nnkIdent and node[0].eqIdent("await"): + if node[0].eqIdent("await"): case node[1].kind of nnkIdent, nnkInfix, nnkDotExpr, nnkCall, nnkCommand: # await x @@ -142,7 +142,7 @@ proc processBody(node, retFutureSym: NimNode, else: error("Invalid node kind in 'await', got: " & $node[1].kind) elif node.len > 1 and node[1].kind == nnkCommand and - node[1][0].kind == nnkIdent and node[1][0].eqIdent("await"): + node[1][0].eqIdent("await"): # foo await x var newCommand = node result.createVar("future" & $node[0].toStrLit, node[1][1], newCommand[1], @@ -151,7 +151,7 @@ proc processBody(node, retFutureSym: NimNode, of nnkVarSection, nnkLetSection: case node[0][^1].kind of nnkCommand: - if node[0][^1][0].kind == nnkIdent and node[0][^1][0].eqIdent("await"): + if node[0][^1][0].eqIdent("await"): # var x = await y var newVarSection = node # TODO: Should this use copyNimNode? result.createVar("future" & node[0][0].strVal, node[0][^1][1], @@ -167,7 +167,7 @@ proc processBody(node, retFutureSym: NimNode, else: discard of nnkDiscardStmt: # discard await x - if node[0].kind == nnkCommand and node[0][0].kind == nnkIdent and + if node[0].kind == nnkCommand and node[0][0].eqIdent("await"): var newDiscard = node result.createVar("futureDiscard_" & $toStrLit(node[0][1]), node[0][1], @@ -358,16 +358,15 @@ proc stripAwait(node: NimNode): NimNode = case node.kind of nnkCommand, nnkCall: - if node[0].kind == nnkIdent and node[0].eqIdent("await"): + if node[0].eqIdent("await"): node[0] = emptyNoopSym - elif node.len > 1 and node[1].kind == nnkCommand and - node[1][0].kind == nnkIdent and node[1][0].eqIdent("await"): + elif node.len > 1 and node[1].kind == nnkCommand and node[1][0].eqIdent("await"): # foo await x node[1][0] = emptyNoopSym of nnkVarSection, nnkLetSection: case node[0][^1].kind of nnkCommand: - if node[0][^1][0].kind == nnkIdent and node[0][^1][0].eqIdent("await"): + if node[0][^1][0].eqIdent("await"): # var x = await y node[0][^1][0] = emptyNoopSym else: discard @@ -380,8 +379,7 @@ proc stripAwait(node: NimNode): NimNode = else: discard of nnkDiscardStmt: # discard await x - if node[0].kind == nnkCommand and node[0][0].kind == nnkIdent and - node[0][0].eqIdent("await"): + if node[0].kind == nnkCommand and node[0][0].eqIdent("await"): node[0][0] = emptyNoopSym else: discard @@ -441,3 +439,8 @@ macro multisync*(prc: untyped): untyped = result = newStmtList() result.add(asyncSingleProc(asyncPrc)) result.add(sync) + +proc await*[T](x: T) = + ## The 'await' keyword is also defined here for technical + ## reasons. (Generic symbol lookup prepass.) + {.error: "Await only available within .async".} |