aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/_vec.rs25
-rw-r--r--src/rt/rust_builtin.cpp6
2 files changed, 31 insertions, 0 deletions
diff --git a/src/lib/_vec.rs b/src/lib/_vec.rs
index 80cd242d..ce052283 100644
--- a/src/lib/_vec.rs
+++ b/src/lib/_vec.rs
@@ -20,6 +20,7 @@ native "rust" mod rustrt {
* want to invoke this as vec_alloc[vec[U], U].
*/
fn vec_alloc[T, U](uint n_elts) -> vec[U];
+ fn vec_alloc_mut[T, U](uint n_elts) -> vec[mutable U];
fn refcount[T](vec[T] v) -> uint;
@@ -30,6 +31,10 @@ fn alloc[T](uint n_elts) -> vec[T] {
ret rustrt.vec_alloc[vec[T], T](n_elts);
}
+fn alloc_mut[T](uint n_elts) -> vec[mutable T] {
+ ret rustrt.vec_alloc_mut[vec[mutable T], T](n_elts);
+}
+
fn refcount[T](vec[T] v) -> uint {
auto r = rustrt.refcount[T](v);
if (r == dbg.const_refcount) {
@@ -52,6 +57,16 @@ fn init_fn[T](&init_op[T] op, uint n_elts) -> vec[T] {
ret v;
}
+fn init_fn_mut[T](&init_op[T] op, uint n_elts) -> vec[mutable T] {
+ let vec[mutable T] v = alloc_mut[T](n_elts);
+ let uint i = 0u;
+ while (i < n_elts) {
+ v += vec(mutable op(i));
+ i += 1u;
+ }
+ ret v;
+}
+
fn init_elt[T](&T t, uint n_elts) -> vec[T] {
/**
* FIXME (issue #81): should be:
@@ -69,6 +84,16 @@ fn init_elt[T](&T t, uint n_elts) -> vec[T] {
ret v;
}
+fn init_elt_mut[T](&T t, uint n_elts) -> vec[mutable T] {
+ let vec[mutable T] v = alloc_mut[T](n_elts);
+ let uint i = n_elts;
+ while (i > 0u) {
+ i -= 1u;
+ v += vec(mutable t);
+ }
+ ret v;
+}
+
fn buf[T](vec[T] v) -> vbuf {
ret rustrt.vec_buf[T](v, 0u);
}
diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp
index 1f17fc8c..1d8f8ba8 100644
--- a/src/rt/rust_builtin.cpp
+++ b/src/rt/rust_builtin.cpp
@@ -100,6 +100,12 @@ vec_alloc(rust_task *task, type_desc *t, type_desc *elem_t, size_t n_elts)
return vec;
}
+extern "C" CDECL rust_vec*
+vec_alloc_mut(rust_task *task, type_desc *t, type_desc *elem_t, size_t n_elts)
+{
+ return vec_alloc(task, t, elem_t, n_elts);
+}
+
extern "C" CDECL void *
vec_buf(rust_task *task, type_desc *ty, rust_vec *v, size_t offset)
{