summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2014-06-01 15:02:13 +0200
committerAraq <rumpf_a@web.de>2014-06-01 15:02:13 +0200
commite6d12f3f6ee933f295dd83a64f5f0e6eba77e1d1 (patch)
treec366b6a8d1d5fc8724ae848bffe5e80462761373 /compiler
parent40baebebfe425f03fbdd41da4c6d2e4c6778d241 (diff)
downloadNim-e6d12f3f6ee933f295dd83a64f5f0e6eba77e1d1.tar.gz
fixed codegen for return values
Diffstat (limited to 'compiler')
-rw-r--r--compiler/lowerings.nim27
1 files changed, 15 insertions, 12 deletions
diff --git a/compiler/lowerings.nim b/compiler/lowerings.nim
index d370f21f0..df2816a0e 100644
--- a/compiler/lowerings.nim
+++ b/compiler/lowerings.nim
@@ -155,6 +155,17 @@ proc promiseKind(t: PType): TPromiseKind =
   elif containsGarbageCollectedRef(t): promInvalid
   else: promBlob
 
+proc addLocalVar(varSection: PNode; owner: PSym; typ: PType; v: PNode): PSym =
+  result = newSym(skTemp, getIdent(genPrefix), owner, varSection.info)
+  result.typ = typ
+  incl(result.flags, sfFromGeneric)
+
+  var vpart = newNodeI(nkIdentDefs, varSection.info, 3)
+  vpart.sons[0] = newSymNode(result)
+  vpart.sons[1] = ast.emptyNode
+  vpart.sons[2] = v
+  varSection.add vpart
+
 discard """
 We generate roughly this:
 
@@ -202,6 +213,9 @@ proc createWrapperProc(f: PNode; threadParam, argsParam: PSym;
   var body = newNodeI(nkStmtList, f.info)
   if barrier != nil:
     body.add callCodeGenProc("barrierEnter", barrier)
+  var threadLocalProm: PSym
+  if spawnKind == srByVar:
+    threadLocalProm = addLocalVar(varSection, argsParam.owner, prom.typ, prom)
   body.add varSection
   if prom != nil and spawnKind != srByVar:
     body.add createNimCreatePromiseCall(prom, threadParam.newSymNode)
@@ -210,7 +224,7 @@ proc createWrapperProc(f: PNode; threadParam, argsParam: PSym;
 
   body.add callCodeGenProc("nimArgsPassingDone", threadParam.newSymNode)
   if spawnKind == srByVar:
-    body.add newAsgnStmt(genDeref(prom), call)
+    body.add newAsgnStmt(genDeref(threadLocalProm.newSymNode), call)
   elif prom != nil:
     let fk = prom.typ.sons[1].promiseKind
     if fk == promInvalid:
@@ -251,17 +265,6 @@ proc createCastExpr(argsParam: PSym; objType: PType): PNode =
   result.typ = newType(tyPtr, objType.owner)
   result.typ.rawAddSon(objType)
 
-proc addLocalVar(varSection: PNode; owner: PSym; typ: PType; v: PNode): PSym =
-  result = newSym(skTemp, getIdent(genPrefix), owner, varSection.info)
-  result.typ = typ
-  incl(result.flags, sfFromGeneric)
-
-  var vpart = newNodeI(nkIdentDefs, varSection.info, 3)
-  vpart.sons[0] = newSymNode(result)
-  vpart.sons[1] = ast.emptyNode
-  vpart.sons[2] = v
-  varSection.add vpart
-
 proc setupArgsForConcurrency(n: PNode; objType: PType; scratchObj: PSym, 
                              castExpr, call, varSection, result: PNode) =
   let formals = n[0].typ.n