summary refs log tree commit diff stats
path: root/compiler/ccgstmts.nim
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/ccgstmts.nim')
-rwxr-xr-xcompiler/ccgstmts.nim31
1 files changed, 30 insertions, 1 deletions
diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim
index db6d5bd67..46e4f75df 100755
--- a/compiler/ccgstmts.nim
+++ b/compiler/ccgstmts.nim
@@ -32,7 +32,7 @@ proc genVarTuple(p: BProc, n: PNode) =
       assignLocalVar(p, v)
       initLocalVar(p, v, immediateAsgn=true)
     initLoc(field, locExpr, t.sons[i], tup.s)
-    if t.n == nil: 
+    if t.kind == tyTuple: 
       field.r = ropef("$1.Field$2", [rdLoc(tup), toRope(i)])
     else: 
       if (t.n.sons[i].kind != nkSym): InternalError(n.info, "genVarTuple")
@@ -258,6 +258,34 @@ proc genBlock(p: BProc, t: PNode, d: var TLoc) =
     else: genStmts(p, t.sons[1])
     endBlock(p)
   
+proc genParForStmt(p: BProc, t: PNode) =
+  assert(sonsLen(t) == 3)
+  inc(p.withinLoop)
+  genLineDir(p, t)
+
+  preserveBreakIdx:
+    let forLoopVar = t.sons[0].sym
+    var rangeA, rangeB: TLoc
+    assignLocalVar(P, forLoopVar)
+    #initLoc(forLoopVar.loc, locLocalVar, forLoopVar.typ, onStack)
+    #discard mangleName(forLoopVar)
+    let call = t.sons[1]
+    initLocExpr(p, call.sons[1], rangeA)
+    initLocExpr(p, call.sons[2], rangeB)
+    
+    appf(p.s(cpsStmts), "#pragma omp parallel for $4$n" &
+                        "for ($1 = $2; $1 <= $3; ++$1)", 
+                        forLoopVar.loc.rdLoc,
+                        rangeA.rdLoc, rangeB.rdLoc,
+                        call.sons[3].getStr.toRope)
+    
+    p.breakIdx = startBlock(p)
+    p.blocks[p.breakIdx].isLoop = true
+    genStmts(p, t.sons[2])
+    endBlock(p)
+
+  dec(p.withinLoop)
+  
 proc genBreakStmt(p: BProc, t: PNode) = 
   var idx = p.breakIdx
   if t.sons[0].kind != nkEmpty: 
@@ -815,5 +843,6 @@ proc genStmts(p: BProc, t: PNode) =
         # we have not only the header: 
         if prc.getBody.kind != nkEmpty or lfDynamicLib in prc.loc.flags: 
           genProc(p.module, prc)
+  of nkParForStmt: genParForStmt(p, t)
   else: internalError(t.info, "genStmts(" & $t.kind & ')')