Skip to content

Commit 58e6d44

Browse files
committed
---
yaml --- r: 1276 b: refs/heads/master c: 6daec40 h: refs/heads/master v: v3
1 parent e0442f7 commit 58e6d44

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 8bc57fa85e6191117c8c27bf53f8e051e13783c3
2+
refs/heads/master: 6daec4004a8bcd57701690e8a704dde6102bf10e

trunk/src/comp/middle/trans.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,6 +1793,40 @@ fn trans_if(@block_ctxt cx, @ast.expr cond,
17931793
vec(then_res, else_res));
17941794
}
17951795

1796+
fn trans_for(@block_ctxt cx,
1797+
@ast.decl decl,
1798+
@ast.expr seq,
1799+
&ast.block body) -> result {
1800+
1801+
fn inner(@block_ctxt cx,
1802+
@ast.local local, ValueRef curr,
1803+
@ty.t t, ast.block body) -> result {
1804+
1805+
auto scope_cx = new_scope_block_ctxt(cx, "for loop scope");
1806+
auto next_cx = new_sub_block_ctxt(cx, "next");
1807+
1808+
cx.build.Br(scope_cx.llbb);
1809+
auto local_res = alloc_local(scope_cx, local);
1810+
auto bcx = copy_ty(local_res.bcx, true, local_res.val, curr, t).bcx;
1811+
trans_block(bcx, body);
1812+
bcx.build.Br(next_cx.llbb);
1813+
ret res(next_cx, C_nil());
1814+
}
1815+
1816+
1817+
let @ast.local local;
1818+
alt (decl.node) {
1819+
case (ast.decl_local(?loc)) {
1820+
local = loc;
1821+
}
1822+
}
1823+
1824+
auto seq_ty = ty.expr_ty(seq);
1825+
auto seq_res = trans_expr(cx, seq);
1826+
ret iter_sequence(seq_res.bcx, seq_res.val, seq_ty,
1827+
bind inner(_, local, _, _, body));
1828+
}
1829+
17961830
fn trans_while(@block_ctxt cx, @ast.expr cond,
17971831
&ast.block body) -> result {
17981832

@@ -2648,6 +2682,10 @@ fn trans_expr(@block_ctxt cx, @ast.expr e) -> result {
26482682
ret trans_if(cx, cond, thn, els);
26492683
}
26502684

2685+
case (ast.expr_for(?decl, ?seq, ?body, _)) {
2686+
ret trans_for(cx, decl, seq, body);
2687+
}
2688+
26512689
case (ast.expr_while(?cond, ?body, _)) {
26522690
ret trans_while(cx, cond, body);
26532691
}

0 commit comments

Comments
 (0)