@@ -2243,10 +2243,7 @@ fn trans_expr_fn(bcx: @block_ctxt, f: ast::_fn, sp: span,
2243
2243
trans_closure ( sub_cx, sp, f, llfn, none, [ ] , id, { |_fcx|} ) ;
2244
2244
}
2245
2245
} ;
2246
- let addr = alt dest {
2247
- save_in( a) { a }
2248
- overwrite ( a, ty) { bcx = drop_ty ( bcx, a, ty) ; a }
2249
- } ;
2246
+ let { bcx, val: addr } = get_dest_addr ( bcx, dest) ;
2250
2247
fill_fn_pair ( bcx, addr, llfn, env) ;
2251
2248
ret bcx;
2252
2249
}
@@ -2537,6 +2534,13 @@ fn store_in_dest(bcx: @block_ctxt, val: ValueRef, dest: dest) -> @block_ctxt {
2537
2534
ret bcx;
2538
2535
}
2539
2536
2537
+ fn get_dest_addr ( bcx : @block_ctxt , dest : dest ) -> result {
2538
+ alt dest {
2539
+ save_in( a) { rslt ( bcx, a) }
2540
+ overwrite ( a, t) { rslt ( drop_ty ( bcx, a, t) , a) }
2541
+ }
2542
+ }
2543
+
2540
2544
// Wrapper through which legacy non-DPS code can use DPS functions
2541
2545
fn dps_to_result ( bcx : @block_ctxt ,
2542
2546
work : block ( @block_ctxt , dest ) -> @block_ctxt ,
@@ -3675,12 +3679,8 @@ fn trans_bind_1(cx: @block_ctxt, outgoing_fty: ty::t,
3675
3679
let lv = lval_maybe_callee_to_lval ( f_res, pair_ty) ;
3676
3680
bcx = lv. bcx ;
3677
3681
// FIXME[DPS] factor this out
3678
- let addr = alt dest {
3679
- save_in( a) { a }
3680
- overwrite ( a, ty) { bcx = drop_ty ( bcx, a, ty) ; a }
3681
- } ;
3682
- bcx = memmove_ty ( bcx, addr, lv. val , pair_ty) ;
3683
- ret bcx;
3682
+ let { bcx, val: addr } = get_dest_addr ( bcx, dest) ;
3683
+ ret memmove_ty( bcx, addr, lv. val , pair_ty) ;
3684
3684
}
3685
3685
let closure = alt f_res. env {
3686
3686
null_env. { none }
@@ -3717,10 +3717,7 @@ fn trans_bind_1(cx: @block_ctxt, outgoing_fty: ty::t,
3717
3717
closure. ptrty , ty_param_count, target_res) ;
3718
3718
3719
3719
// Fill the function pair
3720
- let addr = alt dest {
3721
- save_in( a) { a }
3722
- overwrite ( a, ty) { bcx = drop_ty ( bcx, a, ty) ; a }
3723
- } ;
3720
+ let { bcx, val: addr } = get_dest_addr ( bcx, dest) ;
3724
3721
fill_fn_pair ( bcx, addr, llthunk. val , closure. ptr ) ;
3725
3722
ret bcx;
3726
3723
}
@@ -4186,25 +4183,18 @@ fn trans_rec(bcx: @block_ctxt, fields: [ast::field],
4186
4183
ret bcx ;
4187
4184
}
4188
4185
4186
+ // FIXME[DPS] remove this entirely, rename trans_expr_dps to trans_expr
4189
4187
fn trans_expr ( cx : @block_ctxt , e : @ast:: expr ) -> result {
4190
- // Fixme Fill in cx.sp
4191
- alt e. node {
4192
- ast:: expr_anon_obj ( anon_obj) {
4193
- ret trans_anon_obj ( cx, e. span , anon_obj, e. id ) ;
4194
- }
4195
- ast:: expr_call ( _, _) | ast:: expr_field ( _, _) | ast:: expr_index ( _, _) |
4196
- ast:: expr_path ( _) | ast:: expr_unary ( ast:: deref. , _) {
4188
+ if expr_is_lval ( bcx_tcx ( cx) , e) {
4197
4189
let t = ty:: expr_ty ( bcx_tcx ( cx) , e) ;
4198
4190
let sub = trans_lval ( cx, e) ;
4199
4191
let v = sub. val ;
4200
4192
if sub. is_mem { v = load_if_immediate ( sub. bcx , v, t) ; }
4201
4193
ret rslt( sub. bcx , v) ;
4202
- }
4203
- // Fall through to DPS-style
4204
- _ {
4194
+ } else {
4195
+ // Fall through to DPS-style
4205
4196
ret dps_to_result ( cx, { |bcx, dest| trans_expr_dps ( bcx, e, dest) } ,
4206
4197
ty:: expr_ty ( bcx_tcx ( cx) , e) ) ;
4207
- }
4208
4198
}
4209
4199
}
4210
4200
@@ -4234,6 +4224,9 @@ fn trans_expr_by_ref(bcx: @block_ctxt, e: @ast::expr) -> result {
4234
4224
// - exprs returning non-immediates get save_in (or by_ref when lval)
4235
4225
fn trans_expr_dps ( bcx : @block_ctxt , e : @ast:: expr , dest : dest )
4236
4226
-> @block_ctxt {
4227
+ let tcx = bcx_tcx ( bcx) ;
4228
+ if expr_is_lval ( tcx, e) { ret lval_to_dps ( bcx, e, dest) ; }
4229
+
4237
4230
alt e. node {
4238
4231
ast:: expr_if ( cond, thn, els) | ast:: expr_if_check ( cond, thn, els) {
4239
4232
ret trans_if ( bcx, cond, thn, els, dest) ;
@@ -4261,22 +4254,23 @@ fn trans_expr_dps(bcx: @block_ctxt, e: @ast::expr, dest: dest)
4261
4254
ast:: expr_vec ( args, _) { ret tvec:: trans_vec ( bcx, args, e. id , dest) ; }
4262
4255
ast:: expr_binary ( op, x, y) { ret trans_binary ( bcx, op, x, y, dest) ; }
4263
4256
ast:: expr_unary ( op, x) {
4264
- if op == ast:: deref {
4265
- ret trans_expr_backwards_compat ( bcx, e, dest) ;
4266
- }
4257
+ assert op != ast:: deref; // lvals are handled above
4267
4258
ret trans_unary ( bcx, op, x, e. id , dest) ;
4268
4259
}
4269
4260
ast:: expr_fn ( f) { ret trans_expr_fn ( bcx, f, e. span , e. id , dest) ; }
4270
4261
ast:: expr_bind ( f, args) { ret trans_bind ( bcx, f, args, e. id , dest) ; }
4271
4262
ast:: expr_copy ( a) {
4272
- if !expr_is_lval ( bcx_tcx ( bcx) , a) {
4273
- ret trans_expr_dps ( bcx, a, dest) ;
4274
- } else {
4275
- // FIXME[DPS] give this a name that makes more sense
4276
- ret trans_expr_backwards_compat ( bcx, e, dest) ;
4277
- }
4263
+ if !expr_is_lval ( tcx, a) { ret trans_expr_dps ( bcx, a, dest) ; }
4264
+ else { ret lval_to_dps ( bcx, a, dest) ; }
4278
4265
}
4279
4266
ast:: expr_cast ( val, _) { ret trans_cast ( bcx, val, e. id , dest) ; }
4267
+ ast:: expr_anon_obj ( anon_obj) {
4268
+ ret trans_anon_obj ( bcx, e. span , anon_obj, e. id , dest) ;
4269
+ }
4270
+ // FIXME[DPS] untangle non-lval calls and fields from trans_lval
4271
+ ast:: expr_call ( _, _) | ast:: expr_field ( _, _) {
4272
+ ret lval_to_dps ( bcx, e, dest) ;
4273
+ }
4280
4274
4281
4275
// These return nothing
4282
4276
ast:: expr_break. {
@@ -4366,11 +4360,11 @@ fn trans_expr_dps(bcx: @block_ctxt, e: @ast::expr, dest: dest)
4366
4360
let { bcx, val: addr , is_mem } = trans_lval ( bcx, dst) ;
4367
4361
assert is_mem;
4368
4362
// FIXME: calculate copy init-ness in typestate.
4369
- if expr_is_lval ( bcx_tcx ( bcx ) , src) {
4363
+ if expr_is_lval ( tcx , src) {
4370
4364
ret trans_expr_save_in ( bcx, src, addr, DROP_EXISTING ) ;
4371
4365
} else {
4372
4366
let srclv = trans_lval ( bcx, src) ;
4373
- let t = ty:: expr_ty ( bcx_tcx ( bcx ) , src) ;
4367
+ let t = ty:: expr_ty ( tcx , src) ;
4374
4368
ret move_val( srclv. bcx , DROP_EXISTING , addr, srclv, t) ;
4375
4369
}
4376
4370
}
@@ -4379,7 +4373,7 @@ fn trans_expr_dps(bcx: @block_ctxt, e: @ast::expr, dest: dest)
4379
4373
let lhs_res = trans_lval ( bcx, dst) ;
4380
4374
assert ( lhs_res. is_mem ) ;
4381
4375
let rhs_res = trans_lval ( lhs_res. bcx , src) ;
4382
- let t = ty:: expr_ty ( bcx_tcx ( bcx ) , src) ;
4376
+ let t = ty:: expr_ty ( tcx , src) ;
4383
4377
let { bcx: bcx , val : tmp_alloc } = alloc_ty ( rhs_res. bcx , t) ;
4384
4378
// Swap through a temporary.
4385
4379
bcx = move_val ( bcx, INIT , tmp_alloc, lhs_res, t) ;
@@ -4390,15 +4384,10 @@ fn trans_expr_dps(bcx: @block_ctxt, e: @ast::expr, dest: dest)
4390
4384
assert dest == ignore;
4391
4385
ret trans_assign_op ( bcx, op, dst, src) ;
4392
4386
}
4393
-
4394
- ast:: expr_mac ( _) { ret bcx_ccx ( bcx) . sess . bug ( "unexpanded macro" ) ; }
4395
- // Convert back from result to DPS
4396
- _ { ret trans_expr_backwards_compat( bcx, e, dest) ; }
4397
4387
}
4398
4388
}
4399
4389
4400
- fn trans_expr_backwards_compat ( bcx : @block_ctxt , e : @ast:: expr , dest : dest )
4401
- -> @block_ctxt {
4390
+ fn lval_to_dps ( bcx : @block_ctxt , e : @ast:: expr , dest : dest ) -> @block_ctxt {
4402
4391
let lv = trans_lval ( bcx, e) ;
4403
4392
let { bcx, val, is_mem} = lv;
4404
4393
let ty = ty:: expr_ty ( bcx_tcx ( bcx) , e) ;
0 commit comments