@@ -4768,20 +4768,10 @@ fn trans_for_each(&@block_ctxt cx, &@ast::local local, &@ast::expr seq,
4768
4768
// Step 3: Call iter passing [lliterbody, llenv], plus other args.
4769
4769
alt ( seq. node) {
4770
4770
case ( ast:: expr_call( ?f, ?args) ) {
4771
- auto pair = alloca( cx, T_fn_pair ( * lcx. ccx, iter_body_llty) ) ;
4772
- auto code_cell =
4773
- cx. build. GEP ( pair, ~[ C_int ( 0 ) , C_int ( abi:: fn_field_code) ] ) ;
4774
- cx. build. Store ( lliterbody, code_cell) ;
4775
- auto env_cell =
4776
- cx. build. GEP ( pair, ~[ C_int ( 0 ) , C_int ( abi:: fn_field_box) ] ) ;
4777
- auto llenvblobptr =
4778
- cx. build. PointerCast ( llenvptr,
4779
- T_opaque_closure_ptr ( * lcx. ccx) ) ;
4780
- cx. build. Store ( llenvblobptr, env_cell) ;
4781
- // log "lliterbody: " + val_str(lcx.ccx.tn, lliterbody);
4782
-
4783
- r = trans_call( cx, f, some[ ValueRef ] ( cx. build. Load ( pair) ) , args,
4784
- seq. id) ;
4771
+ auto pair = create_real_fn_pair( cx, iter_body_llty,
4772
+ lliterbody, llenvptr) ;
4773
+ r = trans_call( cx, f, some[ ValueRef ] ( cx. build. Load ( pair) ) ,
4774
+ args, seq. id) ;
4785
4775
ret rslt( r. bcx, C_nil ( ) ) ;
4786
4776
}
4787
4777
}
@@ -8714,6 +8704,26 @@ fn create_fn_pair(&@crate_ctxt cx, str ps, TypeRef llfnty, ValueRef llfn,
8714
8704
ret gvar;
8715
8705
}
8716
8706
8707
+ // Create a /real/ closure: this is like create_fn_pair, but creates a
8708
+ // a fn value on the stack with a specified environment (which need not be
8709
+ // on the stack).
8710
+ fn create_real_fn_pair( & @block_ctxt cx, TypeRef llfnty,
8711
+ ValueRef llfn, ValueRef llenvptr) -> ValueRef {
8712
+ auto lcx = cx. fcx. lcx;
8713
+
8714
+ auto pair = alloca( cx, T_fn_pair ( * lcx. ccx, llfnty) ) ;
8715
+ auto code_cell =
8716
+ cx. build. GEP ( pair, ~[ C_int ( 0 ) , C_int ( abi:: fn_field_code) ] ) ;
8717
+ cx. build. Store ( llfn, code_cell) ;
8718
+ auto env_cell =
8719
+ cx. build. GEP ( pair, ~[ C_int ( 0 ) , C_int ( abi:: fn_field_box) ] ) ;
8720
+ auto llenvblobptr =
8721
+ cx. build. PointerCast ( llenvptr,
8722
+ T_opaque_closure_ptr ( * lcx. ccx) ) ;
8723
+ cx. build. Store ( llenvblobptr, env_cell) ;
8724
+ ret pair;
8725
+ }
8726
+
8717
8727
fn register_fn_pair( & @crate_ctxt cx, str ps, TypeRef llfnty, ValueRef llfn,
8718
8728
ast:: node_id id) {
8719
8729
// FIXME: We should also hide the unexported pairs in crates.
0 commit comments