From 8d3f477fada2883ecc312f9342a9847d25fcf741 Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Tue, 16 May 2017 21:04:12 +0200 Subject: [PATCH 1/2] Create correct C protoypes in genMainProc. (#5822) This avoids a -Wstrict-prototypes warning in the generated C file. --- compiler/cgen.nim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/cgen.nim b/compiler/cgen.nim index b27d9cbce6..fab35c5846 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -889,14 +889,14 @@ proc genMainProc(m: BModule) = # prevents inlining of the NimMainInner function and dependent # functions, which might otherwise merge their stack frames. PreMainBody = - "void PreMainInner() {$N" & + "void PreMainInner(void) {$N" & "\tsystemInit000();$N" & "$1" & "$2" & "$3" & "}$N$N" & - "void PreMain() {$N" & - "\tvoid (*volatile inner)();$N" & + "void PreMain(void) {$N" & + "\tvoid (*volatile inner)(void);$N" & "\tsystemDatInit000();$N" & "\tinner = PreMainInner;$N" & "$4$5" & @@ -915,7 +915,7 @@ proc genMainProc(m: BModule) = NimMainProc = "N_CDECL(void, NimMain)(void) {$N" & - "\tvoid (*volatile inner)();$N" & + "\tvoid (*volatile inner)(void);$N" & "\tPreMain();$N" & "\tinner = NimMainInner;$N" & "$2" & From 6599cae2810148d0a36d9c2d9be964d73c514559 Mon Sep 17 00:00:00 2001 From: Yuriy Glukhov Date: Tue, 16 May 2017 23:09:19 +0300 Subject: [PATCH 2/2] Async macro fixes (#5739) --- compiler/semstmts.nim | 3 +++ lib/pure/asyncmacro.nim | 38 ++++++++++++++++------------------ tests/async/tasync_forward.nim | 9 ++++++++ 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index c7f27f0a2b..a1a33d8892 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -982,6 +982,9 @@ proc semProcAnnotation(c: PContext, prc: PNode; var x = newNodeI(nkCall, n.info) x.add(newSymNode(m)) prc.sons[pragmasPos] = copyExcept(n, i) + if prc[pragmasPos].kind != nkEmpty and prc[pragmasPos].len == 0: + prc.sons[pragmasPos] = emptyNode + if it.kind == nkExprColonExpr: # pass pragma argument to the macro too: x.add(it.sons[1]) diff --git a/lib/pure/asyncmacro.nim b/lib/pure/asyncmacro.nim index ce4c9a9c94..fccda3bfb0 100644 --- a/lib/pure/asyncmacro.nim +++ b/lib/pure/asyncmacro.nim @@ -305,9 +305,10 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} = error("Cannot transform this node kind into an async proc." & " proc/method definition or lambda node expected.") - hint("Processing " & prc[0].getName & " as an async proc.") + let prcName = prc.name.getName + hint("Processing " & prcName & " as an async proc.") - let returnType = prc[3][0] + let returnType = prc.params[0] var baseType: NimNode # Verify that the return type is a Future[T] if returnType.kind == nnkBracketExpr: @@ -326,9 +327,9 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} = let subtypeIsVoid = returnType.kind == nnkEmpty or (baseType.kind == nnkIdent and returnType[1].ident == !"void") - let futureVarIdents = getFutureVarIdents(prc[3]) + let futureVarIdents = getFutureVarIdents(prc.params) - var outerProcBody = newNimNode(nnkStmtList, prc[6]) + var outerProcBody = newNimNode(nnkStmtList, prc.body) # -> var retFuture = newFuture[T]() var retFutureSym = genSym(nskVar, "retFuture") @@ -338,10 +339,10 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} = outerProcBody.add( newVarStmt(retFutureSym, newCall( - newNimNode(nnkBracketExpr, prc[6]).add( + newNimNode(nnkBracketExpr, prc.body).add( newIdentNode(!"newFuture"), # TODO: Strange bug here? Remove the `!`. subRetType), - newLit(prc[0].getName)))) # Get type from return type of this proc + newLit(prcName)))) # Get type from return type of this proc # -> iterator nameIter(): FutureBase {.closure.} = # -> {.push warning[resultshadowed]: off.} @@ -349,8 +350,8 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} = # -> {.pop.} # -> # -> complete(retFuture, result) - var iteratorNameSym = genSym(nskIterator, $prc[0].getName & "Iter") - var procBody = prc[6].processBody(retFutureSym, subtypeIsVoid, + var iteratorNameSym = genSym(nskIterator, $prcName & "Iter") + var procBody = prc.body.processBody(retFutureSym, subtypeIsVoid, futureVarIdents, nil) # don't do anything with forward bodies (empty) if procBody.kind != nnkEmpty: @@ -362,7 +363,7 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} = newIdentNode("warning"), newIdentNode("resultshadowed")), newIdentNode("off")))) # -> {.push warning[resultshadowed]: off.} - procBody.insert(1, newNimNode(nnkVarSection, prc[6]).add( + procBody.insert(1, newNimNode(nnkVarSection, prc.body).add( newIdentDefs(newIdentNode("result"), baseType))) # -> var result: T procBody.insert(2, newNimNode(nnkPragma).add( @@ -377,35 +378,32 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} = var closureIterator = newProc(iteratorNameSym, [newIdentNode("FutureBase")], procBody, nnkIteratorDef) - closureIterator[4] = newNimNode(nnkPragma, prc[6]).add(newIdentNode("closure")) + closureIterator.pragma = copyNimTree(prc.pragma) + closureIterator.addPragma(newIdentNode("closure")) + closureIterator.addPragma(newIdentNode("gcsafe")) outerProcBody.add(closureIterator) # -> createCb(retFuture) #var cbName = newIdentNode("cb") var procCb = getAst createCb(retFutureSym, iteratorNameSym, - newStrLitNode(prc[0].getName), + newStrLitNode(prcName), createFutureVarCompletions(futureVarIdents, nil)) outerProcBody.add procCb # -> return retFuture - outerProcBody.add newNimNode(nnkReturnStmt, prc[6][prc[6].len-1]).add(retFutureSym) + outerProcBody.add newNimNode(nnkReturnStmt, prc.body[^1]).add(retFutureSym) result = prc - # Remove the 'async' pragma. - for i in 0 ..