about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2013-12-17 16:46:18 -0800
committerPatrick Walton <pcwalton@mimiga.net>2014-01-09 16:05:34 -0800
commite12711540a00ded4021250f7b2a31773fc4dc734 (patch)
tree036d04e2767d3bda4217c832f1a083c1a68b2c55 /src/libstd
parentdd11fe17c7cf3661905c952d8233527abbff4c11 (diff)
downloadrust-e12711540a00ded4021250f7b2a31773fc4dc734.tar.gz
rust-e12711540a00ded4021250f7b2a31773fc4dc734.zip
librustc: Implement placement `box` for GC and unique pointers.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/gc.rs18
-rw-r--r--src/libstd/owned.rs14
-rw-r--r--src/libstd/prelude.rs4
3 files changed, 36 insertions, 0 deletions
diff --git a/src/libstd/gc.rs b/src/libstd/gc.rs
index 1b53c70a9a1..4cbecc9b42f 100644
--- a/src/libstd/gc.rs
+++ b/src/libstd/gc.rs
@@ -21,6 +21,14 @@ use clone::{Clone, DeepClone};
 use managed;
 
 /// Immutable garbage-collected pointer type
+#[lang="gc"]
+#[cfg(not(test))]
+#[no_send]
+pub struct Gc<T> {
+    priv ptr: @T
+}
+
+#[cfg(test)]
 #[no_send]
 pub struct Gc<T> {
     priv ptr: @T
@@ -54,6 +62,16 @@ impl<T> Clone for Gc<T> {
     }
 }
 
+/// An value that represents the task-local managed heap.
+///
+/// Use this like `let foo = box(GC) Bar::new(...);`
+#[lang="managed_heap"]
+#[cfg(not(test))]
+pub static GC: () = ();
+
+#[cfg(test)]
+pub static GC: () = ();
+
 /// The `Send` bound restricts this to acyclic graphs where it is well-defined.
 ///
 /// A `Freeze` bound would also work, but `Send` *or* `Freeze` cannot be expressed.
diff --git a/src/libstd/owned.rs b/src/libstd/owned.rs
index 424c4fd6b2f..dc8ea34c84b 100644
--- a/src/libstd/owned.rs
+++ b/src/libstd/owned.rs
@@ -12,6 +12,20 @@
 
 #[cfg(not(test))] use cmp::*;
 
+/// A value that represents the global exchange heap. This is the default
+/// place that the `box` keyword allocates into when no place is supplied.
+///
+/// The following two examples are equivalent:
+///
+///     let foo = box(HEAP) Bar::new(...);
+///     let foo = box Bar::new(...);
+#[lang="exchange_heap"]
+#[cfg(not(test))]
+pub static HEAP: () = ();
+
+#[cfg(test)]
+pub static HEAP: () = ();
+
 #[cfg(not(test))]
 impl<T:Eq> Eq for ~T {
     #[inline]
diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs
index afacc4e8c17..36bcc81c06d 100644
--- a/src/libstd/prelude.rs
+++ b/src/libstd/prelude.rs
@@ -86,6 +86,10 @@ pub use vec::{Vector, VectorVector, CopyableVector, ImmutableVector};
 pub use comm::{Port, Chan, SharedChan};
 pub use task::spawn;
 
+// Reexported statics
+#[cfg(not(test))]
+pub use gc::GC;
+
 /// Disposes of a value.
 #[inline]
 pub fn drop<T>(_x: T) { }