@@ -2178,50 +2178,45 @@ fn node_type(cx: @crate_ctxt, sp: span, id: ast::node_id) -> TypeRef {
2178
2178
type_of ( cx, sp, ty)
2179
2179
}
2180
2180
2181
- fn trans_unary ( cx : @block_ctxt , op : ast:: unop , e : @ast:: expr ,
2182
- id : ast:: node_id ) -> result {
2183
- let e_ty = ty:: expr_ty ( bcx_tcx ( cx) , e) ;
2181
+ fn trans_unary ( bcx : @block_ctxt , op : ast:: unop , e : @ast:: expr ,
2182
+ id : ast:: node_id , dest : dest ) -> @block_ctxt {
2183
+ if dest == ignore { ret trans_expr_dps ( bcx, e, ignore) ; }
2184
+ let e_ty = ty:: expr_ty ( bcx_tcx ( bcx) , e) ;
2184
2185
alt op {
2185
2186
ast : : not. {
2186
- let sub = trans_expr ( cx , e) ;
2187
- ret rslt ( sub . bcx , Not ( sub . bcx , sub . val ) ) ;
2187
+ let { bcx , val } = trans_expr ( bcx , e) ;
2188
+ ret store_in_dest ( bcx, Not ( bcx, val) , dest ) ;
2188
2189
}
2189
2190
ast:: neg. {
2190
- let sub = trans_expr ( cx, e) ;
2191
- if ty:: struct ( bcx_tcx ( cx) , e_ty) == ty:: ty_float {
2192
- ret rslt ( sub. bcx , FNeg ( sub. bcx , sub. val ) ) ;
2193
- } else { ret rslt ( sub. bcx , Neg ( sub. bcx , sub. val ) ) ; }
2191
+ let { bcx, val} = trans_expr ( bcx, e) ;
2192
+ let neg = if ty:: struct ( bcx_tcx ( bcx) , e_ty) == ty:: ty_float {
2193
+ FNeg ( bcx, val)
2194
+ } else { Neg ( bcx, val) } ;
2195
+ ret store_in_dest ( bcx, neg, dest) ;
2194
2196
}
2195
2197
ast:: box ( _) {
2196
- let lv = trans_lval ( cx, e) ;
2197
- let box_ty = node_id_type ( bcx_ccx ( lv. bcx ) , id) ;
2198
- let sub = trans_malloc_boxed ( lv. bcx , e_ty) ;
2199
- let body = sub. body ;
2200
- add_clean_temp ( cx, sub. box , box_ty) ;
2201
-
2198
+ let { bcx, box, body} = trans_malloc_boxed ( bcx, e_ty) ;
2199
+ add_clean_free ( bcx, box, false ) ;
2202
2200
// Cast the body type to the type of the value. This is needed to
2203
2201
// make tags work, since tags have a different LLVM type depending
2204
2202
// on whether they're boxed or not.
2205
- let sub_ccx = bcx_ccx ( sub . bcx ) ;
2206
- if check type_has_static_size ( sub_ccx , e_ty) {
2203
+ let ccx = bcx_ccx ( bcx) ;
2204
+ if check type_has_static_size ( ccx , e_ty) {
2207
2205
let e_sp = e. span ;
2208
- let llety = T_ptr ( type_of ( sub_ccx, e_sp, e_ty) ) ;
2209
- body = PointerCast ( sub. bcx , body, llety) ;
2210
- } else {
2211
- } // FIXME: can remove the else{} once we have
2212
- // a new snapshot
2213
-
2214
-
2215
- let bcx = move_val_if_temp ( sub. bcx , INIT , body, lv, e_ty) ;
2216
- ret rslt( bcx, sub. box ) ;
2206
+ let llety = T_ptr ( type_of ( ccx, e_sp, e_ty) ) ;
2207
+ body = PointerCast ( bcx, body, llety) ;
2208
+ }
2209
+ bcx = trans_expr_save_in ( bcx, e, body) ;
2210
+ revoke_clean ( bcx, box) ;
2211
+ ret store_in_dest ( bcx, box, dest) ;
2217
2212
}
2218
2213
ast:: uniq ( _) {
2219
- ret trans_uniq:: trans_uniq ( cx , e, id) ;
2214
+ ret trans_uniq:: trans_uniq ( bcx , e, id, dest ) ;
2220
2215
}
2221
2216
ast:: deref. {
2222
- bcx_ccx ( cx ) . sess . bug ( "deref expressions should have been \
2223
- translated using trans_lval(), not \
2224
- trans_unary()") ;
2217
+ bcx_ccx ( bcx ) . sess . bug ( "deref expressions should have been \
2218
+ translated using trans_lval(), not \
2219
+ trans_unary()") ;
2225
2220
}
2226
2221
}
2227
2222
}
@@ -2498,7 +2493,7 @@ fn join_returns(parent_cx: @block_ctxt, in_cxs: [@block_ctxt],
2498
2493
ret out;
2499
2494
}
2500
2495
2501
- // Used to put an immediate value in a dest
2496
+ // Used to put an immediate value in a dest.
2502
2497
fn store_in_dest ( bcx : @block_ctxt , val : ValueRef , dest : dest ) -> @block_ctxt {
2503
2498
alt dest {
2504
2499
ignore. { }
@@ -4092,23 +4087,23 @@ fn trans_rec(bcx: @block_ctxt, fields: [ast::field],
4092
4087
let ty_fields = alt ty:: struct ( bcx_tcx ( bcx) , t) { ty:: ty_rec ( f) { f } } ;
4093
4088
let temp_cleanups = [ ] , i = 0 ;
4094
4089
for tf in ty_fields {
4095
- let gep = GEP_tup_like_1 ( bcx, t, addr, [ 0 , i] ) ;
4096
- bcx = gep . bcx ;
4090
+ let dst = GEP_tup_like_1 ( bcx, t, addr, [ 0 , i] ) ;
4091
+ bcx = dst . bcx ;
4097
4092
// FIXME make this {|f| str::eq(f.node.ident, tf.ident)} again when
4098
4093
// bug #913 is fixed
4099
4094
fn test ( n : str , f : ast:: field ) -> bool { str:: eq ( f. node . ident , n) }
4100
4095
alt vec:: find ( bind test ( tf. ident , _) , fields) {
4101
4096
some ( f) {
4102
- bcx = trans_expr_save_in ( bcx, f. node . expr , gep . val ) ;
4097
+ bcx = trans_expr_save_in ( bcx, f. node . expr , dst . val ) ;
4103
4098
}
4104
4099
none. {
4105
4100
let base = GEP_tup_like_1 ( bcx, t, base_val, [ 0 , i] ) ;
4106
4101
let val = load_if_immediate ( base. bcx , base. val , tf. mt . ty ) ;
4107
- bcx = copy_val ( base. bcx , INIT , gep . val , val, tf. mt . ty ) ;
4102
+ bcx = copy_val ( base. bcx , INIT , dst . val , val, tf. mt . ty ) ;
4108
4103
}
4109
4104
}
4110
- add_clean_temp_mem ( bcx, addr , tf. mt . ty ) ;
4111
- temp_cleanups += [ addr ] ;
4105
+ add_clean_temp_mem ( bcx, dst . val , tf. mt . ty ) ;
4106
+ temp_cleanups += [ dst . val ] ;
4112
4107
i += 1 ;
4113
4108
}
4114
4109
// Now revoke the cleanups as we pass responsibility for the data
@@ -4193,9 +4188,6 @@ fn trans_expr(cx: @block_ctxt, e: @ast::expr) -> result {
4193
4188
if sub. is_mem { v = load_if_immediate ( sub. bcx , v, t) ; }
4194
4189
ret rslt( sub. bcx , v) ;
4195
4190
}
4196
- ast:: expr_unary ( op, x) {
4197
- ret trans_unary ( cx, op, x, e. id ) ;
4198
- }
4199
4191
// Fall through to DPS-style
4200
4192
_ {
4201
4193
ret dps_to_result( cx, { |bcx, dest| trans_expr_dps ( bcx, e, dest) } ,
@@ -4259,6 +4251,12 @@ fn trans_expr_dps(bcx: @block_ctxt, e: @ast::expr, dest: dest)
4259
4251
ast:: expr_lit ( lit) { ret trans_lit ( bcx, * lit, dest) ; }
4260
4252
ast:: expr_vec ( args, _) { ret tvec:: trans_vec ( bcx, args, e. id , dest) ; }
4261
4253
ast:: expr_binary ( op, x, y) { ret trans_binary ( bcx, op, x, y, dest) ; }
4254
+ ast:: expr_unary ( op, x) {
4255
+ if op == ast:: deref {
4256
+ ret trans_expr_backwards_compat ( bcx, e, dest) ;
4257
+ }
4258
+ ret trans_unary ( bcx, op, x, e. id , dest) ;
4259
+ }
4262
4260
4263
4261
ast:: expr_break. {
4264
4262
assert dest == ignore;
@@ -4365,40 +4363,43 @@ fn trans_expr_dps(bcx: @block_ctxt, e: @ast::expr, dest: dest)
4365
4363
4366
4364
ast:: expr_mac ( _) { ret bcx_ccx ( bcx) . sess . bug ( "unexpanded macro" ) ; }
4367
4365
// Convert back from result to DPS
4368
- _ {
4369
- let lv = trans_lval ( bcx, e) ;
4370
- let { bcx, val, is_mem} = lv;
4371
- let ty = ty:: expr_ty ( bcx_tcx ( bcx) , e) ;
4372
- alt dest {
4373
- by_val( cell) {
4374
- if !is_mem {
4375
- revoke_clean ( bcx, val) ;
4376
- * cell = val;
4377
- } else if ty:: type_is_unique ( bcx_tcx ( bcx) , ty) {
4378
- // Do a song and a dance to work around the fact that take_ty
4379
- // for unique boxes overwrites the pointer.
4380
- let oldval = Load ( bcx, val) ;
4381
- bcx = take_ty ( bcx, val, ty) ;
4382
- * cell = Load ( bcx, val) ;
4383
- Store ( bcx, oldval, val) ;
4384
- } else {
4385
- bcx = take_ty ( bcx, val, ty) ;
4386
- * cell = Load ( bcx, val) ;
4387
- }
4388
- }
4389
- by_ref ( cell) {
4390
- assert is_mem;
4366
+ _ { ret trans_expr_backwards_compat( bcx, e, dest) ; }
4367
+ }
4368
+ }
4369
+
4370
+ fn trans_expr_backwards_compat ( bcx : @block_ctxt , e : @ast:: expr , dest : dest )
4371
+ -> @block_ctxt {
4372
+ let lv = trans_lval ( bcx, e) ;
4373
+ let { bcx, val, is_mem} = lv;
4374
+ let ty = ty:: expr_ty ( bcx_tcx ( bcx) , e) ;
4375
+ alt dest {
4376
+ by_val( cell) {
4377
+ if !is_mem {
4378
+ revoke_clean ( bcx, val) ;
4391
4379
* cell = val;
4392
- }
4393
- save_in ( loc) { bcx = move_val_if_temp ( bcx, INIT , loc, lv, ty) ; }
4394
- overwrite ( loc, _) {
4395
- bcx = move_val_if_temp ( bcx, DROP_EXISTING , loc, lv, ty) ;
4396
- }
4397
- ignore. { }
4380
+ } else if ty:: type_is_unique ( bcx_tcx ( bcx) , ty) {
4381
+ // Do a song and a dance to work around the fact that take_ty
4382
+ // for unique boxes overwrites the pointer.
4383
+ let oldval = Load ( bcx, val) ;
4384
+ bcx = take_ty ( bcx, val, ty) ;
4385
+ * cell = Load ( bcx, val) ;
4386
+ Store ( bcx, oldval, val) ;
4387
+ } else {
4388
+ bcx = take_ty ( bcx, val, ty) ;
4389
+ * cell = Load ( bcx, val) ;
4398
4390
}
4399
- ret bcx ;
4400
4391
}
4392
+ by_ref ( cell) {
4393
+ assert is_mem;
4394
+ * cell = val;
4395
+ }
4396
+ save_in ( loc) { bcx = move_val_if_temp ( bcx, INIT , loc, lv, ty) ; }
4397
+ overwrite ( loc, _) {
4398
+ bcx = move_val_if_temp ( bcx, DROP_EXISTING , loc, lv, ty) ;
4399
+ }
4400
+ ignore. { }
4401
4401
}
4402
+ ret bcx;
4402
4403
}
4403
4404
4404
4405
// We pass structural values around the compiler "by pointer" and
0 commit comments