Fix processing of 'await' with a nnkCall.
Specifically, ``discard readMessages(disp, await disp.accept(server))`` works now, i.e. using 'await' as one of the params to a proc call.
This commit is contained in:
parent
cac39b27cf
commit
17ef758cc3
2 changed files with 12 additions and 9 deletions
|
|
@ -498,10 +498,14 @@ proc processBody(node, retFutureSym: PNimrodNode): PNimrodNode {.compileTime.} =
|
||||||
of nnkCommand:
|
of nnkCommand:
|
||||||
if node[0].ident == !"await":
|
if node[0].ident == !"await":
|
||||||
case node[1].kind
|
case node[1].kind
|
||||||
of nnkIdent, nnkCall:
|
of nnkIdent:
|
||||||
# await x
|
# await x
|
||||||
# await foo(p, x)
|
|
||||||
result = newNimNode(nnkYieldStmt).add(node[1]) # -> yield x
|
result = newNimNode(nnkYieldStmt).add(node[1]) # -> yield x
|
||||||
|
of nnkCall:
|
||||||
|
# await foo(p, x)
|
||||||
|
var futureValue: PNimrodNode
|
||||||
|
createVar("future" & $node[1][0].toStrLit, node[1], futureValue)
|
||||||
|
result.add futureValue
|
||||||
else:
|
else:
|
||||||
error("Invalid node kind in 'await', got: " & $node[1].kind)
|
error("Invalid node kind in 'await', got: " & $node[1].kind)
|
||||||
elif node[1].kind == nnkCommand and node[1][0].kind == nnkIdent and
|
elif node[1].kind == nnkCommand and node[1][0].kind == nnkIdent and
|
||||||
|
|
@ -510,6 +514,7 @@ proc processBody(node, retFutureSym: PNimrodNode): PNimrodNode {.compileTime.} =
|
||||||
var newCommand = node
|
var newCommand = node
|
||||||
createVar("future" & $node[0].ident, node[1][0], newCommand[1])
|
createVar("future" & $node[0].ident, node[1][0], newCommand[1])
|
||||||
result.add newCommand
|
result.add newCommand
|
||||||
|
|
||||||
of nnkVarSection, nnkLetSection:
|
of nnkVarSection, nnkLetSection:
|
||||||
case node[0][2].kind
|
case node[0][2].kind
|
||||||
of nnkCommand:
|
of nnkCommand:
|
||||||
|
|
@ -534,11 +539,10 @@ proc processBody(node, retFutureSym: PNimrodNode): PNimrodNode {.compileTime.} =
|
||||||
if node[0][0].ident == !"await":
|
if node[0][0].ident == !"await":
|
||||||
var dummy = newNimNode(nnkStmtList)
|
var dummy = newNimNode(nnkStmtList)
|
||||||
createVar("futureDiscard_" & $toStrLit(node[0][1]), node[0][1], dummy)
|
createVar("futureDiscard_" & $toStrLit(node[0][1]), node[0][1], dummy)
|
||||||
else:
|
else: discard
|
||||||
for i in 0 .. <node.len:
|
|
||||||
result[i] = processBody(node[i], retFutureSym)
|
for i in 0 .. <result.len:
|
||||||
|
result[i] = processBody(result[i], retFutureSym)
|
||||||
assert(not result.isNil)
|
|
||||||
#echo(treeRepr(result))
|
#echo(treeRepr(result))
|
||||||
|
|
||||||
proc getName(node: PNimrodNode): string {.compileTime.} =
|
proc getName(node: PNimrodNode): string {.compileTime.} =
|
||||||
|
|
|
||||||
|
|
@ -52,8 +52,7 @@ proc createServer(disp: PDispatcher, port: TPort): PFuture[int] {.async.} =
|
||||||
server.bindAddr(port)
|
server.bindAddr(port)
|
||||||
server.listen()
|
server.listen()
|
||||||
while true:
|
while true:
|
||||||
var client = await disp.accept(server)
|
discard readMessages(disp, await disp.accept(server))
|
||||||
discard readMessages(disp, client)
|
|
||||||
|
|
||||||
discard disp.createServer(TPort(10335))
|
discard disp.createServer(TPort(10335))
|
||||||
discard disp.launchSwarm(TPort(10335))
|
discard disp.launchSwarm(TPort(10335))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue