Skip to content

Commit f089f53

Browse files
committed
Move expr_cast and expr_copy to DPS style
Issue #667
1 parent d946e09 commit f089f53

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

src/comp/middle/trans.rs

+12-18
Original file line numberDiff line numberDiff line change
@@ -3392,7 +3392,8 @@ fn float_cast(bcx: @block_ctxt, lldsttype: TypeRef, llsrctype: TypeRef,
33923392
} else { llsrc };
33933393
}
33943394

3395-
fn trans_cast(cx: @block_ctxt, e: @ast::expr, id: ast::node_id) -> result {
3395+
fn trans_cast(cx: @block_ctxt, e: @ast::expr, id: ast::node_id,
3396+
dest: dest) -> @block_ctxt {
33963397
let ccx = bcx_ccx(cx);
33973398
let e_res = trans_expr(cx, e);
33983399
let ll_t_in = val_ty(e_res.val);
@@ -3446,7 +3447,7 @@ fn trans_cast(cx: @block_ctxt, e: @ast::expr, id: ast::node_id) -> result {
34463447
}
34473448
_ { ccx.sess.bug("Translating unsupported cast.") }
34483449
};
3449-
ret rslt(e_res.bcx, newval);
3450+
ret store_in_dest(e_res.bcx, newval, dest);
34503451
}
34513452

34523453
// pth is cx.path
@@ -4188,22 +4189,6 @@ fn trans_rec(bcx: @block_ctxt, fields: [ast::field],
41884189
fn trans_expr(cx: @block_ctxt, e: @ast::expr) -> result {
41894190
// Fixme Fill in cx.sp
41904191
alt e.node {
4191-
ast::expr_copy(a) {
4192-
let e_ty = ty::expr_ty(bcx_tcx(cx), a);
4193-
let lv = trans_lval(cx, a);
4194-
let bcx = lv.bcx;
4195-
if !lv.is_mem { ret {bcx: lv.bcx, val: lv.val}; }
4196-
let r = if type_is_immediate(bcx_ccx(cx), e_ty) {
4197-
rslt(bcx, Load(bcx, lv.val))
4198-
} else {
4199-
let {bcx, val: dest} = alloc_ty(bcx, e_ty);
4200-
bcx = copy_val(bcx, INIT, dest, lv.val, e_ty);
4201-
rslt(bcx, dest)
4202-
};
4203-
add_clean_temp(bcx, r.val, e_ty);
4204-
ret r;
4205-
}
4206-
ast::expr_cast(val, _) { ret trans_cast(cx, val, e.id); }
42074192
ast::expr_anon_obj(anon_obj) {
42084193
ret trans_anon_obj(cx, e.span, anon_obj, e.id);
42094194
}
@@ -4283,6 +4268,15 @@ fn trans_expr_dps(bcx: @block_ctxt, e: @ast::expr, dest: dest)
42834268
}
42844269
ast::expr_fn(f) { ret trans_expr_fn(bcx, f, e.span, e.id, dest); }
42854270
ast::expr_bind(f, args) { ret trans_bind(bcx, f, args, e.id, dest); }
4271+
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+
}
4278+
}
4279+
ast::expr_cast(val, _) { ret trans_cast(bcx, val, e.id, dest); }
42864280

42874281
// These return nothing
42884282
ast::expr_break. {

0 commit comments

Comments
 (0)