Ensures that asyncmacro2 does not raise exceptions (#172)

* Ensures that asyncmacro2 does not raise exceptions

* Remove unnecessary include
This commit is contained in:
markspanbroek 2021-03-30 16:48:20 +02:00 committed by GitHub
parent 075b7abf4c
commit e5d3ecdd01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 11 deletions

View File

@ -10,8 +10,6 @@
{.push raises: [Defect].}
include "system/inclrtl"
import std/[os, tables, strutils, heapqueue, lists, options, nativesockets, net,
deques]
import ./timer
@ -1073,12 +1071,8 @@ proc wait*[T](fut: Future[T], timeout = -1): Future[T] {.
else:
wait(fut, timeout.milliseconds())
{.pop.}
include asyncmacro2
{.push raises: [Defect].}
proc runForever*() {.raises: [Defect, CatchableError].} =
## Begins a never ending global dispatcher poll loop.
## Raises different exceptions depending on the platform.

View File

@ -161,7 +161,7 @@ proc processBody(node, retFutureSym: NimNode,
proc getName(node: NimNode): string {.compileTime.} =
case node.kind
of nnkSym:
return $node
return node.strVal
of nnkPostfix:
return node[1].strVal
of nnkIdent:
@ -184,8 +184,7 @@ proc isInvalidReturnType(typeName: string): bool =
proc verifyReturnType(typeName: string) {.compileTime.} =
if typeName.isInvalidReturnType:
error("Expected return type of 'Future' got '$1'" %
typeName)
error("Expected return type of 'Future' got '" & typeName & "'")
macro unsupported(s: static[string]): untyped =
error s
@ -309,7 +308,7 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} =
))
# If proc has an explicit gcsafe pragma, we add it to iterator as well.
if prc.pragma.findChild(it.kind in {nnkSym, nnkIdent} and $it == "gcsafe") != nil:
if prc.pragma.findChild(it.kind in {nnkSym, nnkIdent} and it.strVal == "gcsafe") != nil:
closureIterator.addPragma(newIdentNode("gcsafe"))
outerProcBody.add(closureIterator)
@ -335,7 +334,10 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} =
# Add discardable pragma.
if returnType.kind == nnkEmpty:
# Add Future[void]
result.params[0] = parseExpr("Future[void]")
result.params[0] =
newNimNode(nnkBracketExpr, prc)
.add(newIdentNode("Future"))
.add(newIdentNode("void"))
if procBody.kind != nnkEmpty:
result.body = outerProcBody
#echo(treeRepr(result))