Revert "Clean up a bunch of box related code."

This reverts commit bacf9e9887.
This commit is contained in:
Michael Sullivan 2012-06-26 12:58:58 -07:00
parent 6141f5ce5a
commit f85fbcb67f
2 changed files with 38 additions and 27 deletions

View file

@ -398,16 +398,18 @@ fn malloc_general_dyn(bcx: block, t: ty::t, heap: heap, size: ValueRef) ->
ret {box: box, body: body};
}
fn malloc_general(bcx: block, t: ty::t, heap: heap) ->
{box: ValueRef, body: ValueRef} {
malloc_general_dyn(bcx, t, heap,
fn malloc_boxed(bcx: block, t: ty::t) -> {box: ValueRef, body: ValueRef} {
malloc_general_dyn(bcx, t, heap_shared,
llsize_of(bcx.ccx(), type_of(bcx.ccx(), t)))
}
fn malloc_boxed(bcx: block, t: ty::t) -> {box: ValueRef, body: ValueRef} {
malloc_general(bcx, t, heap_shared)
}
fn malloc_unique(bcx: block, t: ty::t) -> {box: ValueRef, body: ValueRef} {
malloc_general(bcx, t, heap_exchange)
malloc_general_dyn(bcx, t, heap_exchange,
llsize_of(bcx.ccx(), type_of(bcx.ccx(), t)))
}
fn malloc_unique_dyn(bcx: block, t: ty::t, size: ValueRef
) -> {box: ValueRef, body: ValueRef} {
malloc_general_dyn(bcx, t, heap_exchange, size)
}
// Type descriptor and type glue stuff
@ -1485,19 +1487,6 @@ fn trans_lit(cx: block, e: @ast::expr, lit: ast::lit, dest: dest) -> block {
}
}
fn trans_boxed_expr(bcx: block, contents: @ast::expr,
t: ty::t, heap: heap,
dest: dest) -> block {
let _icx = bcx.insn_ctxt("trans_boxed_expr");
let {box, body} = malloc_general(bcx, t, heap);
add_clean_free(bcx, box, true);
let bcx = trans_expr_save_in(bcx, contents, body);
revoke_clean(bcx, box);
ret store_in_dest(bcx, box, dest);
}
fn trans_unary(bcx: block, op: ast::unop, e: @ast::expr,
un_expr: @ast::expr, dest: dest) -> block {
let _icx = bcx.insn_ctxt("trans_unary");
@ -1520,25 +1509,35 @@ fn trans_unary(bcx: block, op: ast::unop, e: @ast::expr,
alt op {
ast::not {
let {bcx, val} = trans_temp_expr(bcx, e);
store_in_dest(bcx, Not(bcx, val), dest)
ret store_in_dest(bcx, Not(bcx, val), dest);
}
ast::neg {
let {bcx, val} = trans_temp_expr(bcx, e);
let neg = if ty::type_is_fp(e_ty) {
FNeg(bcx, val)
} else { Neg(bcx, val) };
store_in_dest(bcx, neg, dest)
ret store_in_dest(bcx, neg, dest);
}
ast::box(_) {
trans_boxed_expr(bcx, e, e_ty, heap_shared, dest)
let mut {box, body} = malloc_boxed(bcx, e_ty);
add_clean_free(bcx, box, false);
// Cast the body type to the type of the value. This is needed to
// make enums work, since enums have a different LLVM type depending
// on whether they're boxed or not
let ccx = bcx.ccx();
let llety = T_ptr(type_of(ccx, e_ty));
body = PointerCast(bcx, body, llety);
let bcx = trans_expr_save_in(bcx, e, body);
revoke_clean(bcx, box);
ret store_in_dest(bcx, box, dest);
}
ast::uniq(_) {
trans_boxed_expr(bcx, e, e_ty, heap_exchange, dest)
ret uniq::trans_uniq(bcx, e, un_expr.id, dest);
}
ast::deref {
bcx.sess().bug("deref expressions should have been \
translated using trans_lval(), not \
trans_unary()")
trans_unary()");
}
}
}

View file

@ -5,7 +5,19 @@ import build::*;
import base::*;
import shape::llsize_of;
export make_free_glue, autoderef, duplicate;
export trans_uniq, make_free_glue, autoderef, duplicate;
fn trans_uniq(bcx: block, contents: @ast::expr,
node_id: ast::node_id, dest: dest) -> block {
let _icx = bcx.insn_ctxt("uniq::trans_uniq");
let uniq_ty = node_id_type(bcx, node_id);
let contents_ty = content_ty(uniq_ty);
let {box, body} = malloc_unique(bcx, contents_ty);
add_clean_free(bcx, box, true);
let bcx = trans_expr_save_in(bcx, contents, body);
revoke_clean(bcx, box);
ret store_in_dest(bcx, box, dest);
}
fn make_free_glue(bcx: block, vptr: ValueRef, t: ty::t)
-> block {
@ -52,4 +64,4 @@ fn duplicate(bcx: block, v: ValueRef, t: ty::t) -> result {
Store(bcx, td, dst_tydesc_ptr);
ret rslt(bcx, dst_box);
}
}