summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2014-11-08 15:47:00 +0100
committerAraq <rumpf_a@web.de>2014-11-08 15:47:00 +0100
commit830e0c0009d25d84a26fc997722eee4ecd015fd9 (patch)
tree1902dc5afe39a9f57052891c37f34e5e590a1e47 /compiler
parentcb976c9c9a0ff0ff16fabc7543a4594c60458caa (diff)
downloadNim-830e0c0009d25d84a26fc997722eee4ecd015fd9.tar.gz
the codegen doesn't emit deepCopy for parallel statements
Diffstat (limited to 'compiler')
-rw-r--r--compiler/lowerings.nim27
-rw-r--r--compiler/nimconf.nim8
2 files changed, 22 insertions, 13 deletions
diff --git a/compiler/lowerings.nim b/compiler/lowerings.nim
index ae19f5366..661472a05 100644
--- a/compiler/lowerings.nim
+++ b/compiler/lowerings.nim
@@ -204,7 +204,7 @@ proc flowVarKind(t: PType): TFlowVarKind =
   else: fvBlob
 
 proc addLocalVar(varSection, varInit: PNode; owner: PSym; typ: PType;
-                 v: PNode): PSym =
+                 v: PNode; useShallowCopy=false): PSym =
   result = newSym(skTemp, getIdent(genPrefix), owner, varSection.info)
   result.typ = typ
   incl(result.flags, sfFromGeneric)
@@ -215,11 +215,14 @@ proc addLocalVar(varSection, varInit: PNode; owner: PSym; typ: PType;
   vpart.sons[2] = if varInit.isNil: v else: ast.emptyNode
   varSection.add vpart
   if varInit != nil:
-    let deepCopyCall = newNodeI(nkCall, varInit.info, 3)
-    deepCopyCall.sons[0] = newSymNode(createMagic("deepCopy", mDeepCopy))
-    deepCopyCall.sons[1] = newSymNode(result)
-    deepCopyCall.sons[2] = v
-    varInit.add deepCopyCall
+    if useShallowCopy:
+      varInit.add newFastAsgnStmt(newSymNode(result), v)
+    else:
+      let deepCopyCall = newNodeI(nkCall, varInit.info, 3)
+      deepCopyCall.sons[0] = newSymNode(createMagic("deepCopy", mDeepCopy))
+      deepCopyCall.sons[1] = newSymNode(result)
+      deepCopyCall.sons[2] = v
+      varInit.add deepCopyCall
 
 discard """
 We generate roughly this:
@@ -420,7 +423,8 @@ proc setupArgsForParallelism(n: PNode; objType: PType; scratchObj: PSym;
         result.add newFastAsgnStmt(newDotExpr(scratchObj, fieldB), n[3])
 
         let threadLocal = addLocalVar(varSection,nil, objType.owner, fieldA.typ,
-                                      indirectAccess(castExpr, fieldA, n.info))
+                                      indirectAccess(castExpr, fieldA, n.info),
+                                      useShallowCopy=true)
         slice.sons[2] = threadLocal.newSymNode
       else:
         let a = genAddrOf(n)
@@ -434,7 +438,8 @@ proc setupArgsForParallelism(n: PNode; objType: PType; scratchObj: PSym;
       slice.sons[1] = genDeref(indirectAccess(castExpr, field, n.info))
 
       let threadLocal = addLocalVar(varSection,nil, objType.owner, fieldB.typ,
-                                    indirectAccess(castExpr, fieldB, n.info))
+                                    indirectAccess(castExpr, fieldB, n.info),
+                                    useShallowCopy=true)
       slice.sons[3] = threadLocal.newSymNode
       call.add slice
     elif (let size = computeSize(argType); size < 0 or size > 16) and
@@ -445,7 +450,8 @@ proc setupArgsForParallelism(n: PNode; objType: PType; scratchObj: PSym;
       objType.addField(field)
       result.add newFastAsgnStmt(newDotExpr(scratchObj, field), a)
       let threadLocal = addLocalVar(varSection,nil, objType.owner, field.typ,
-                                    indirectAccess(castExpr, field, n.info))
+                                    indirectAccess(castExpr, field, n.info),
+                                    useShallowCopy=true)
       call.add(genDeref(threadLocal.newSymNode))
     else:
       # boring case
@@ -454,7 +460,8 @@ proc setupArgsForParallelism(n: PNode; objType: PType; scratchObj: PSym;
       result.add newFastAsgnStmt(newDotExpr(scratchObj, field), n)
       let threadLocal = addLocalVar(varSection, varInit,
                                     objType.owner, field.typ,
-                                    indirectAccess(castExpr, field, n.info))
+                                    indirectAccess(castExpr, field, n.info),
+                                    useShallowCopy=true)
       call.add(threadLocal.newSymNode)
 
 proc wrapProcForSpawn*(owner: PSym; spawnExpr: PNode; retType: PType; 
diff --git a/compiler/nimconf.nim b/compiler/nimconf.nim
index 98fe831d3..bcf9b5359 100644
--- a/compiler/nimconf.nim
+++ b/compiler/nimconf.nim
@@ -113,7 +113,7 @@ proc parseDirective(L: var TLexer, tok: var TToken) =
   case whichKeyword(tok.ident)
   of wIf:
     setLen(condStack, len(condStack) + 1)
-    var res = evalppIf(L, tok)
+    let res = evalppIf(L, tok)
     condStack[high(condStack)] = res
     if not res: jumpToDirective(L, tok, jdElseEndif)
   of wElif: doElif(L, tok)
@@ -224,8 +224,10 @@ proc loadConfigs*(cfg: string) =
   if libpath == "": 
     # choose default libpath:
     var prefix = getPrefixDir()
-    if prefix == "/usr": libpath = "/usr/lib/nim"
-    elif prefix == "/usr/local": libpath = "/usr/local/lib/nim"
+    when defined(posix):
+      if prefix == "/usr": libpath = "/usr/lib/nim"
+      elif prefix == "/usr/local": libpath = "/usr/local/lib/nim"
+      else: libpath = joinPath(prefix, "lib")
     else: libpath = joinPath(prefix, "lib")
 
   if optSkipConfigFile notin gGlobalOptions: