about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorGraydon Hoare <graydon@mozilla.com>2011-01-21 07:59:06 -0800
committerGraydon Hoare <graydon@mozilla.com>2011-01-21 07:59:57 -0800
commit6daec4004a8bcd57701690e8a704dde6102bf10e (patch)
tree96a7eec60c2a0f385803ca7938c4f6b54fcf2060 /src/comp
parent8bc57fa85e6191117c8c27bf53f8e051e13783c3 (diff)
downloadrust-6daec4004a8bcd57701690e8a704dde6102bf10e.tar.gz
rust-6daec4004a8bcd57701690e8a704dde6102bf10e.zip
First cut of trans_for.
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/middle/trans.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index a7770b942e2..1a703d0a25b 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -1793,6 +1793,40 @@ fn trans_if(@block_ctxt cx, @ast.expr cond,
                      vec(then_res, else_res));
 }
 
+fn trans_for(@block_ctxt cx,
+             @ast.decl decl,
+             @ast.expr seq,
+             &ast.block body) -> result {
+
+    fn inner(@block_ctxt cx,
+             @ast.local local, ValueRef curr,
+             @ty.t t, ast.block body) -> result {
+
+        auto scope_cx = new_scope_block_ctxt(cx, "for loop scope");
+        auto next_cx = new_sub_block_ctxt(cx, "next");
+
+        cx.build.Br(scope_cx.llbb);
+        auto local_res = alloc_local(scope_cx, local);
+        auto bcx = copy_ty(local_res.bcx, true, local_res.val, curr, t).bcx;
+        trans_block(bcx, body);
+        bcx.build.Br(next_cx.llbb);
+        ret res(next_cx, C_nil());
+    }
+
+
+    let @ast.local local;
+    alt (decl.node) {
+        case (ast.decl_local(?loc)) {
+            local = loc;
+        }
+    }
+
+    auto seq_ty = ty.expr_ty(seq);
+    auto seq_res = trans_expr(cx, seq);
+    ret iter_sequence(seq_res.bcx, seq_res.val, seq_ty,
+                      bind inner(_, local, _, _, body));
+}
+
 fn trans_while(@block_ctxt cx, @ast.expr cond,
                &ast.block body) -> result {
 
@@ -2648,6 +2682,10 @@ fn trans_expr(@block_ctxt cx, @ast.expr e) -> result {
             ret trans_if(cx, cond, thn, els);
         }
 
+        case (ast.expr_for(?decl, ?seq, ?body, _)) {
+            ret trans_for(cx, decl, seq, body);
+        }
+
         case (ast.expr_while(?cond, ?body, _)) {
             ret trans_while(cx, cond, body);
         }