about summary refs log tree commit diff
path: root/src/rustc
diff options
context:
space:
mode:
authorMichael Sullivan <sully@msully.net>2012-06-26 12:58:58 -0700
committerMichael Sullivan <sully@msully.net>2012-06-26 12:58:58 -0700
commitf85fbcb67fd7d82aaeb784b80997cac54ecdc999 (patch)
tree24a45012575897f9a47c1ef5cbccb751a4cb2f57 /src/rustc
parent6141f5ce5a6da9dd67f96585feda88e4cbc747d9 (diff)
downloadrust-f85fbcb67fd7d82aaeb784b80997cac54ecdc999.tar.gz
rust-f85fbcb67fd7d82aaeb784b80997cac54ecdc999.zip
Revert "Clean up a bunch of box related code."
This reverts commit bacf9e9887872a40d16798813aa66b6916cc6a4e.
Diffstat (limited to 'src/rustc')
-rw-r--r--src/rustc/middle/trans/base.rs49
-rw-r--r--src/rustc/middle/trans/uniq.rs16
2 files changed, 38 insertions, 27 deletions
diff --git a/src/rustc/middle/trans/base.rs b/src/rustc/middle/trans/base.rs
index 1adcbf85115..05ec7d074c8 100644
--- a/src/rustc/middle/trans/base.rs
+++ b/src/rustc/middle/trans/base.rs
@@ -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,
-                       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)
+    malloc_general_dyn(bcx, t, heap_shared,
+                       llsize_of(bcx.ccx(), type_of(bcx.ccx(), t)))
 }
 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()");
       }
     }
 }
diff --git a/src/rustc/middle/trans/uniq.rs b/src/rustc/middle/trans/uniq.rs
index e0440147f16..ec4fd7680ba 100644
--- a/src/rustc/middle/trans/uniq.rs
+++ b/src/rustc/middle/trans/uniq.rs
@@ -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);
-}
+}
\ No newline at end of file