@@ -2731,7 +2731,7 @@ fn trans_for_each(cx: @block_ctxt, local: @ast::local, seq: @ast::expr,
2731
2731
ast:: expr_call ( f, args) {
2732
2732
let pair =
2733
2733
create_real_fn_pair ( cx, iter_body_llty, lliterbody, llenv. ptr ) ;
2734
- r = trans_call ( cx, f, some ( pair) , args, seq. id ) ;
2734
+ r = trans_call ( cx, f, some ( pair) , args, seq. id ) . res ;
2735
2735
ret rslt( r. bcx , C_nil ( ) ) ;
2736
2736
}
2737
2737
}
@@ -3089,6 +3089,12 @@ fn trans_lval_gen(cx: @block_ctxt, e: @ast::expr) -> lval_result {
3089
3089
}
3090
3090
}
3091
3091
}
3092
+ ast:: expr_call ( f, args) {
3093
+ let { res: { bcx , val } , by_ref } =
3094
+ trans_call ( cx, f, none, args, e. id ) ;
3095
+ if by_ref { ret lval_mem ( bcx, val) ; }
3096
+ else { ret lval_val ( bcx, val) ; }
3097
+ }
3092
3098
_ {
3093
3099
ret { res: trans_expr ( cx, e) ,
3094
3100
is_mem : false ,
@@ -3623,7 +3629,7 @@ fn trans_args(cx: @block_ctxt, llenv: ValueRef, gen: option::t<generic_info>,
3623
3629
3624
3630
fn trans_call ( in_cx : @block_ctxt , f : @ast:: expr ,
3625
3631
lliterbody : option:: t < ValueRef > , args : [ @ast:: expr ] ,
3626
- id : ast:: node_id ) -> result {
3632
+ id : ast:: node_id ) -> { res : result , by_ref : bool } {
3627
3633
// NB: 'f' isn't necessarily a function; it might be an entire self-call
3628
3634
// expression because of the hack that allows us to process self-calls
3629
3635
// with trans_call.
@@ -3690,8 +3696,7 @@ fn trans_call(in_cx: @block_ctxt, f: @ast::expr,
3690
3696
none. {
3691
3697
if !ty:: type_is_nil ( bcx_tcx ( cx) , ret_ty) {
3692
3698
if by_ref {
3693
- let retptr = Load ( bcx, llretslot) ;
3694
- retval = load_if_immediate ( bcx, retptr, ret_ty) ;
3699
+ retval = Load ( bcx, llretslot) ;
3695
3700
} else {
3696
3701
retval = load_if_immediate ( bcx, llretslot, ret_ty) ;
3697
3702
// Retval doesn't correspond to anything really tangible
@@ -3720,7 +3725,7 @@ fn trans_call(in_cx: @block_ctxt, f: @ast::expr,
3720
3725
Br ( bcx, next_cx. llbb ) ;
3721
3726
bcx = next_cx;
3722
3727
}
3723
- ret rslt( bcx, retval) ;
3728
+ ret { res : rslt ( bcx, retval) , by_ref : by_ref } ;
3724
3729
}
3725
3730
3726
3731
fn invoke ( bcx : @block_ctxt , llfn : ValueRef ,
@@ -3887,9 +3892,6 @@ fn trans_expr_out(cx: @block_ctxt, e: @ast::expr, output: out_method) ->
3887
3892
// Fixme Fill in cx.sp
3888
3893
alt e. node {
3889
3894
ast:: expr_lit ( lit) { ret trans_lit ( cx, * lit) ; }
3890
- ast:: expr_unary ( op, x) {
3891
- if op != ast:: deref { ret trans_unary ( cx, op, x, e. id ) ; }
3892
- }
3893
3895
ast:: expr_binary ( op, x, y) { ret trans_binary ( cx, op, x, y) ; }
3894
3896
ast:: expr_if ( cond, thn, els) {
3895
3897
ret with_out_method ( bind trans_if ( cx, cond, thn, els, _) , cx, e. id ,
@@ -4044,9 +4046,6 @@ fn trans_expr_out(cx: @block_ctxt, e: @ast::expr, output: out_method) ->
4044
4046
ret rslt( bcx, C_nil ( ) ) ;
4045
4047
}
4046
4048
ast:: expr_bind ( f, args) { ret trans_bind ( cx, f, args, e. id ) ; }
4047
- ast:: expr_call ( f, args) {
4048
- ret trans_call ( cx, f, none :: < ValueRef > , args, e. id ) ;
4049
- }
4050
4049
ast:: expr_cast ( val, _) { ret trans_cast ( cx, val, e. id ) ; }
4051
4050
ast:: expr_vec ( args, _) { ret tvec:: trans_vec ( cx, args, e. id ) ; }
4052
4051
ast:: expr_rec ( args, base) { ret trans_rec ( cx, args, base, e. id ) ; }
@@ -4092,21 +4091,18 @@ fn trans_expr_out(cx: @block_ctxt, e: @ast::expr, output: out_method) ->
4092
4091
ast:: expr_anon_obj ( anon_obj) {
4093
4092
ret trans_anon_obj ( cx, e. span , anon_obj, e. id ) ;
4094
4093
}
4095
- _ {
4096
- // The expression is an lvalue. Fall through.
4097
- assert ( ty:: is_lval ( e) ) ;
4098
- // make sure it really is and that we
4099
- // didn't forget to add a case for a new expr!
4094
+ ast:: expr_call ( _, _) | ast:: expr_field ( _, _) | ast:: expr_index ( _, _) |
4095
+ ast:: expr_path ( _) | ast:: expr_unary ( ast:: deref. , _) {
4096
+ let t = ty:: expr_ty ( bcx_tcx ( cx) , e) ;
4097
+ let sub = trans_lval ( cx, e) ;
4098
+ let v = sub. res . val ;
4099
+ if sub. is_mem { v = load_if_immediate ( sub. res . bcx , v, t) ; }
4100
+ ret rslt( sub. res . bcx , v) ;
4101
+ }
4102
+ ast:: expr_unary ( op, x) {
4103
+ ret trans_unary ( cx, op, x, e. id ) ;
4100
4104
}
4101
4105
}
4102
- // lval cases fall through to trans_lval and then
4103
- // possibly load the result (if it's non-structural).
4104
-
4105
- let t = ty:: expr_ty ( bcx_tcx ( cx) , e) ;
4106
- let sub = trans_lval ( cx, e) ;
4107
- let v = sub. res . val ;
4108
- if sub. is_mem { v = load_if_immediate ( sub. res . bcx , v, t) ; }
4109
- ret rslt( sub. res . bcx , v) ;
4110
4106
}
4111
4107
4112
4108
fn with_out_method ( work : fn ( out_method ) -> result , cx : @block_ctxt ,
@@ -4517,7 +4513,8 @@ fn init_ref_local(bcx: @block_ctxt, local: @ast::local) -> @block_ctxt {
4517
4513
let init_expr = option:: get ( local. node . init ) . expr ;
4518
4514
let val = trans_lval ( bcx, init_expr) ;
4519
4515
assert val. is_mem ;
4520
- ret trans_alt:: bind_irrefutable_pat ( bcx, local. node . pat , val. res . val ,
4516
+ ret trans_alt:: bind_irrefutable_pat ( val. res . bcx , local. node . pat ,
4517
+ val. res . val ,
4521
4518
bcx. fcx . lllocals , false ) ;
4522
4519
}
4523
4520
0 commit comments