about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2011-09-22 18:05:36 -0700
committerBrian Anderson <banderson@mozilla.com>2011-09-22 18:05:36 -0700
commit1a48023a797a6192362bd182eabed2c3ea4cc897 (patch)
tree4eee6974de4d7e3beea1ded67d4aaa8a3a861ca7 /src/comp
parent77fcab043ed7c85338997ae57921ada903a782f1 (diff)
downloadrust-1a48023a797a6192362bd182eabed2c3ea4cc897.tar.gz
rust-1a48023a797a6192362bd182eabed2c3ea4cc897.zip
Add take glue for unique boxes
Closes #962
Issue #409
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/middle/trans.rs3
-rw-r--r--src/comp/middle/trans_uniq.rs16
2 files changed, 18 insertions, 1 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index 5833be8aaff..0c90de1ac38 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -1295,6 +1295,9 @@ fn make_take_glue(cx: @block_ctxt, v: ValueRef, t: ty::t) {
     // NB: v is an *alias* of type t here, not a direct value.
     if ty::type_is_boxed(bcx_tcx(bcx), t) {
         bcx = incr_refcnt_of_boxed(bcx, Load(bcx, v));
+    } else if ty::type_is_unique_box(bcx_tcx(bcx), t) {
+        check trans_uniq::type_is_unique_box(bcx, t);
+        bcx = trans_uniq::duplicate(bcx, v, t);
     } else if ty::type_is_structural(bcx_tcx(bcx), t) {
         bcx = iter_structural_ty(bcx, v, t, take_ty);
     } else if ty::type_is_vec(bcx_tcx(bcx), t) {
diff --git a/src/comp/middle/trans_uniq.rs b/src/comp/middle/trans_uniq.rs
index 2c75ccc67b9..a7649961c74 100644
--- a/src/comp/middle/trans_uniq.rs
+++ b/src/comp/middle/trans_uniq.rs
@@ -15,7 +15,8 @@ import trans::{
     new_sub_block_ctxt
 };
 
-export trans_uniq, make_free_glue, type_is_unique_box, copy_val, autoderef;
+export trans_uniq, make_free_glue, type_is_unique_box, copy_val,
+autoderef, duplicate;
 
 pure fn type_is_unique_box(bcx: @block_ctxt, ty: ty::t) -> bool {
     unchecked {
@@ -106,4 +107,17 @@ fn autoderef(bcx: @block_ctxt, v: ValueRef, t: ty::t)
 
     let content_ty = content_ty(bcx, t);
     ret {v: v, t: content_ty};
+}
+
+fn duplicate(bcx: @block_ctxt, v: ValueRef, t: ty::t)
+    : type_is_unique_box(bcx, t) -> @block_ctxt {
+
+    let content_ty = content_ty(bcx, t);
+    let {bcx, val: llptr} = alloc_uniq(bcx, t);
+
+    let src = Load(bcx, Load(bcx, v));
+    let dst = llptr;
+    let bcx = trans::copy_val(bcx, INIT, dst, src, content_ty);
+    Store(bcx, dst, v);
+    ret bcx;
 }
\ No newline at end of file