async macro: general stability improvements [bugfix] (#11787)
This commit is contained in:
parent
903d06bab8
commit
70e8551e37
1 changed files with 13 additions and 10 deletions
|
|
@ -129,7 +129,7 @@ proc processBody(node, retFutureSym: NimNode,
|
||||||
result.add newNimNode(nnkReturnStmt, node).add(newNilLit())
|
result.add newNimNode(nnkReturnStmt, node).add(newNilLit())
|
||||||
return # Don't process the children of this return stmt
|
return # Don't process the children of this return stmt
|
||||||
of nnkCommand, nnkCall:
|
of nnkCommand, nnkCall:
|
||||||
if node[0].kind == nnkIdent and node[0].eqIdent("await"):
|
if node[0].eqIdent("await"):
|
||||||
case node[1].kind
|
case node[1].kind
|
||||||
of nnkIdent, nnkInfix, nnkDotExpr, nnkCall, nnkCommand:
|
of nnkIdent, nnkInfix, nnkDotExpr, nnkCall, nnkCommand:
|
||||||
# await x
|
# await x
|
||||||
|
|
@ -142,7 +142,7 @@ proc processBody(node, retFutureSym: NimNode,
|
||||||
else:
|
else:
|
||||||
error("Invalid node kind in 'await', got: " & $node[1].kind)
|
error("Invalid node kind in 'await', got: " & $node[1].kind)
|
||||||
elif node.len > 1 and node[1].kind == nnkCommand and
|
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
|
# foo await x
|
||||||
var newCommand = node
|
var newCommand = node
|
||||||
result.createVar("future" & $node[0].toStrLit, node[1][1], newCommand[1],
|
result.createVar("future" & $node[0].toStrLit, node[1][1], newCommand[1],
|
||||||
|
|
@ -151,7 +151,7 @@ proc processBody(node, retFutureSym: NimNode,
|
||||||
of nnkVarSection, nnkLetSection:
|
of nnkVarSection, nnkLetSection:
|
||||||
case node[0][^1].kind
|
case node[0][^1].kind
|
||||||
of nnkCommand:
|
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 x = await y
|
||||||
var newVarSection = node # TODO: Should this use copyNimNode?
|
var newVarSection = node # TODO: Should this use copyNimNode?
|
||||||
result.createVar("future" & node[0][0].strVal, node[0][^1][1],
|
result.createVar("future" & node[0][0].strVal, node[0][^1][1],
|
||||||
|
|
@ -167,7 +167,7 @@ proc processBody(node, retFutureSym: NimNode,
|
||||||
else: discard
|
else: discard
|
||||||
of nnkDiscardStmt:
|
of nnkDiscardStmt:
|
||||||
# discard await x
|
# 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"):
|
node[0][0].eqIdent("await"):
|
||||||
var newDiscard = node
|
var newDiscard = node
|
||||||
result.createVar("futureDiscard_" & $toStrLit(node[0][1]), node[0][1],
|
result.createVar("futureDiscard_" & $toStrLit(node[0][1]), node[0][1],
|
||||||
|
|
@ -358,16 +358,15 @@ proc stripAwait(node: NimNode): NimNode =
|
||||||
|
|
||||||
case node.kind
|
case node.kind
|
||||||
of nnkCommand, nnkCall:
|
of nnkCommand, nnkCall:
|
||||||
if node[0].kind == nnkIdent and node[0].eqIdent("await"):
|
if node[0].eqIdent("await"):
|
||||||
node[0] = emptyNoopSym
|
node[0] = emptyNoopSym
|
||||||
elif node.len > 1 and node[1].kind == nnkCommand and
|
elif node.len > 1 and node[1].kind == nnkCommand and node[1][0].eqIdent("await"):
|
||||||
node[1][0].kind == nnkIdent and node[1][0].eqIdent("await"):
|
|
||||||
# foo await x
|
# foo await x
|
||||||
node[1][0] = emptyNoopSym
|
node[1][0] = emptyNoopSym
|
||||||
of nnkVarSection, nnkLetSection:
|
of nnkVarSection, nnkLetSection:
|
||||||
case node[0][^1].kind
|
case node[0][^1].kind
|
||||||
of nnkCommand:
|
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 x = await y
|
||||||
node[0][^1][0] = emptyNoopSym
|
node[0][^1][0] = emptyNoopSym
|
||||||
else: discard
|
else: discard
|
||||||
|
|
@ -380,8 +379,7 @@ proc stripAwait(node: NimNode): NimNode =
|
||||||
else: discard
|
else: discard
|
||||||
of nnkDiscardStmt:
|
of nnkDiscardStmt:
|
||||||
# discard await x
|
# 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"):
|
||||||
node[0][0].eqIdent("await"):
|
|
||||||
node[0][0] = emptyNoopSym
|
node[0][0] = emptyNoopSym
|
||||||
else: discard
|
else: discard
|
||||||
|
|
||||||
|
|
@ -441,3 +439,8 @@ macro multisync*(prc: untyped): untyped =
|
||||||
result = newStmtList()
|
result = newStmtList()
|
||||||
result.add(asyncSingleProc(asyncPrc))
|
result.add(asyncSingleProc(asyncPrc))
|
||||||
result.add(sync)
|
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".}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue