summary refs log tree commit diff stats
path: root/compiler/ccgstmts.nim
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-11-15 08:45:16 +0100
committerAraq <rumpf_a@web.de>2012-11-15 08:45:16 +0100
commit1fada12a5f6a7af7cc22f49f02a9c63cef6ea130 (patch)
tree61a326d56d379f4ef8d91bca14df7b3b3ae5a7d2 /compiler/ccgstmts.nim
parente4211230e8424d0522b3a827b8d1981ed22a22ed (diff)
downloadNim-1fada12a5f6a7af7cc22f49f02a9c63cef6ea130.tar.gz
improvements for first class iterators
Diffstat (limited to 'compiler/ccgstmts.nim')
-rwxr-xr-xcompiler/ccgstmts.nim7
1 files changed, 6 insertions, 1 deletions
diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim
index 9c9b61088..5e3504cd9 100755
--- a/compiler/ccgstmts.nim
+++ b/compiler/ccgstmts.nim
@@ -115,7 +115,12 @@ proc genGotoState(p: BProc, n: PNode) =
 proc genBreakState(p: BProc, n: PNode) =
   var a: TLoc
   initLocExpr(p, n.sons[0], a)
-  lineF(p, cpsStmts, "if (($1) < 0) break;$n", [rdLoc(a)])
+  if n.sons[0].kind == nkClosure:
+    # XXX this produces quite inefficient code!
+    # the environment is guaranteed to contain the 'state' field at offset 0:
+    lineF(p, cpsStmts, "if ((((NI*) $1.ClEnv)[0]) < 0) break;$n", [rdLoc(a)])
+  else:
+    lineF(p, cpsStmts, "if (($1) < 0) break;$n", [rdLoc(a)])
 
 proc genSingleVar(p: BProc, a: PNode) =
   var v = a.sons[0].sym