@@ -1793,6 +1793,40 @@ fn trans_if(@block_ctxt cx, @ast.expr cond,
1793
1793
vec( then_res, else_res) ) ;
1794
1794
}
1795
1795
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
+
1796
1830
fn trans_while( @block_ctxt cx, @ast. expr cond,
1797
1831
& ast. block body) -> result {
1798
1832
@@ -2648,6 +2682,10 @@ fn trans_expr(@block_ctxt cx, @ast.expr e) -> result {
2648
2682
ret trans_if( cx, cond, thn, els) ;
2649
2683
}
2650
2684
2685
+ case ( ast. expr_for( ?decl, ?seq, ?body, _) ) {
2686
+ ret trans_for( cx, decl, seq, body) ;
2687
+ }
2688
+
2651
2689
case ( ast. expr_while( ?cond, ?body, _) ) {
2652
2690
ret trans_while( cx, cond, body) ;
2653
2691
}
0 commit comments