fixes #3356
This commit is contained in:
parent
ec357a3edd
commit
7c012cb797
1 changed files with 20 additions and 11 deletions
|
|
@ -1468,16 +1468,25 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} =
|
||||||
hint("Processing " & prc[0].getName & " as an async proc.")
|
hint("Processing " & prc[0].getName & " as an async proc.")
|
||||||
|
|
||||||
let returnType = prc[3][0]
|
let returnType = prc[3][0]
|
||||||
|
var baseType: NimNode
|
||||||
# Verify that the return type is a Future[T]
|
# Verify that the return type is a Future[T]
|
||||||
if returnType.kind == nnkIdent:
|
if returnType.kind == nnkBracketExpr:
|
||||||
error("Expected return type of 'Future' got '" & $returnType & "'")
|
let fut = repr(returnType[0])
|
||||||
elif returnType.kind == nnkBracketExpr:
|
if fut != "Future":
|
||||||
if $returnType[0] != "Future":
|
error("Expected return type of 'Future' got '" & fut & "'")
|
||||||
error("Expected return type of 'Future' got '" & $returnType[0] & "'")
|
baseType = returnType[1]
|
||||||
|
elif returnType.kind in nnkCallKinds and $returnType[0] == "[]":
|
||||||
|
let fut = repr(returnType[1])
|
||||||
|
if fut != "Future":
|
||||||
|
error("Expected return type of 'Future' got '" & fut & "'")
|
||||||
|
baseType = returnType[2]
|
||||||
|
elif returnType.kind == nnkEmpty:
|
||||||
|
baseType = returnType
|
||||||
|
else:
|
||||||
|
error("Expected return type of 'Future' got '" & repr(returnType) & "'")
|
||||||
|
|
||||||
let subtypeIsVoid = returnType.kind == nnkEmpty or
|
let subtypeIsVoid = returnType.kind == nnkEmpty or
|
||||||
(returnType.kind == nnkBracketExpr and
|
(baseType.kind == nnkIdent and returnType[1].ident == !"void")
|
||||||
returnType[1].kind == nnkIdent and returnType[1].ident == !"void")
|
|
||||||
|
|
||||||
var outerProcBody = newNimNode(nnkStmtList, prc[6])
|
var outerProcBody = newNimNode(nnkStmtList, prc[6])
|
||||||
|
|
||||||
|
|
@ -1485,7 +1494,7 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} =
|
||||||
var retFutureSym = genSym(nskVar, "retFuture")
|
var retFutureSym = genSym(nskVar, "retFuture")
|
||||||
var subRetType =
|
var subRetType =
|
||||||
if returnType.kind == nnkEmpty: newIdentNode("void")
|
if returnType.kind == nnkEmpty: newIdentNode("void")
|
||||||
else: returnType[1]
|
else: baseType
|
||||||
outerProcBody.add(
|
outerProcBody.add(
|
||||||
newVarStmt(retFutureSym,
|
newVarStmt(retFutureSym,
|
||||||
newCall(
|
newCall(
|
||||||
|
|
@ -1509,7 +1518,7 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} =
|
||||||
newIdentNode("off")))) # -> {.push warning[resultshadowed]: off.}
|
newIdentNode("off")))) # -> {.push warning[resultshadowed]: off.}
|
||||||
|
|
||||||
procBody.insert(1, newNimNode(nnkVarSection, prc[6]).add(
|
procBody.insert(1, newNimNode(nnkVarSection, prc[6]).add(
|
||||||
newIdentDefs(newIdentNode("result"), returnType[1]))) # -> var result: T
|
newIdentDefs(newIdentNode("result"), baseType))) # -> var result: T
|
||||||
|
|
||||||
procBody.insert(2, newNimNode(nnkPragma).add(
|
procBody.insert(2, newNimNode(nnkPragma).add(
|
||||||
newIdentNode("pop"))) # -> {.pop.})
|
newIdentNode("pop"))) # -> {.pop.})
|
||||||
|
|
@ -1550,8 +1559,8 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} =
|
||||||
result[6] = outerProcBody
|
result[6] = outerProcBody
|
||||||
|
|
||||||
#echo(treeRepr(result))
|
#echo(treeRepr(result))
|
||||||
if prc[0].getName == "hubConnectionLoop":
|
#if prc[0].getName == "hubConnectionLoop":
|
||||||
echo(toStrLit(result))
|
# echo(toStrLit(result))
|
||||||
|
|
||||||
macro async*(prc: stmt): stmt {.immediate.} =
|
macro async*(prc: stmt): stmt {.immediate.} =
|
||||||
## Macro which processes async procedures into the appropriate
|
## Macro which processes async procedures into the appropriate
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue