aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Anderson <[email protected]>2011-03-21 21:13:08 -0400
committerGraydon Hoare <[email protected]>2011-03-22 08:04:45 -0700
commitc02cdc32a82c37e887add86773cbf49e446b335f (patch)
tree89f8a94c689fbc3a1aa33b4ea55472f1efd88cf4
parentUn-XFAIL task-comm-4, 5 & 6 (diff)
downloadrust-c02cdc32a82c37e887add86773cbf49e446b335f.tar.xz
rust-c02cdc32a82c37e887add86773cbf49e446b335f.zip
Generalize send/recv to work for more types
-rw-r--r--src/comp/middle/trans.rs34
-rw-r--r--src/test/run-pass/task-comm-16.rs105
2 files changed, 124 insertions, 15 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index aac7dce2..a95ebcab 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -4790,17 +4790,19 @@ fn trans_send(@block_ctxt cx, @ast.expr lhs, @ast.expr rhs,
}
}
- auto llunit_ty = type_of(bcx.fcx.ccx, unit_ty);
- auto data_alloca = bcx.build.Alloca(llunit_ty);
- bcx.build.Store(data.val, data_alloca);
+ auto data_alloc = alloc_ty(bcx, unit_ty);
+ bcx = data_alloc.bcx;
+ auto data_tmp = copy_ty(bcx, INIT, data_alloc.val, data.val, unit_ty);
+ bcx = data_tmp.bcx;
- auto chn_val = vp2i(bcx, chn.val);
- auto data_val = vp2i(bcx, data_alloca);
+ // TODO: Cleanups?
- auto sub = trans_upcall(bcx, "upcall_send", vec(chn_val, data_val));
+ auto sub = trans_upcall(bcx, "upcall_send",
+ vec(vp2i(bcx, chn.val),
+ vp2i(bcx, data_alloc.val)));
bcx = sub.bcx;
- ret res(bcx, chn_val);
+ ret res(bcx, chn.val);
}
fn trans_recv(@block_ctxt cx, @ast.expr lhs, @ast.expr rhs,
@@ -4813,17 +4815,19 @@ fn trans_recv(@block_ctxt cx, @ast.expr lhs, @ast.expr rhs,
auto prt = trans_expr(bcx, rhs);
bcx = prt.bcx;
+ auto sub = trans_upcall(bcx, "upcall_recv",
+ vec(vp2i(bcx, data.res.val),
+ vp2i(bcx, prt.val)));
+ bcx = sub.bcx;
+
auto unit_ty = node_ann_type(cx.fcx.ccx, ann);
- auto llunit_ty = type_of(bcx.fcx.ccx, unit_ty);
- auto data_alloca = bcx.build.Alloca(llunit_ty);
+ auto data_load = load_scalar_or_boxed(bcx, data.res.val, unit_ty);
+ auto cp = copy_ty(bcx, DROP_EXISTING, data.res.val, data_load, unit_ty);
+ bcx = cp.bcx;
- auto data_val = vp2i(bcx, data_alloca);
- auto prt_val = vp2i(bcx, prt.val);
- auto sub = trans_upcall(bcx, "upcall_recv", vec(data_val, prt_val));
- bcx = sub.bcx;
+ // TODO: Cleanups?
- auto data_load = bcx.build.Load(data_alloca);
- ret copy_ty(bcx, DROP_EXISTING, data.res.val, data_load, unit_ty);
+ ret res(bcx, data.res.val);
}
fn init_local(@block_ctxt cx, @ast.local local) -> result {
diff --git a/src/test/run-pass/task-comm-16.rs b/src/test/run-pass/task-comm-16.rs
new file mode 100644
index 00000000..0b568cbc
--- /dev/null
+++ b/src/test/run-pass/task-comm-16.rs
@@ -0,0 +1,105 @@
+// -*- rust -*-
+
+// Tests of ports and channels on various types
+
+impure fn test_rec() {
+ type r = rec(int val0, u8 val1, char val2);
+
+ let port[r] po = port();
+ let chan[r] ch = chan(po);
+ let r r0 = rec(val0 = 0, val1 = 1u8, val2 = '2');
+
+ ch <| r0;
+
+ let r r1;
+ r1 <- po;
+
+ check (r1.val0 == 0);
+ check (r1.val1 == 1u8);
+ check (r1.val2 == '2');
+}
+
+impure fn test_vec() {
+ let port[vec[int]] po = port();
+ let chan[vec[int]] ch = chan(po);
+ let vec[int] v0 = vec(0, 1, 2);
+
+ ch <| v0;
+
+ let vec[int] v1;
+ v1 <- po;
+
+ check (v1.(0) == 0);
+ check (v1.(1) == 1);
+ check (v1.(2) == 2);
+}
+
+impure fn test_tup() {
+ type t = tup(int, u8, char);
+
+ let port[t] po = port();
+ let chan[t] ch = chan(po);
+ let t t0 = tup(0, 1u8, '2');
+
+ ch <| t0;
+
+ let t t1;
+ t1 <- po;
+
+ check (t0._0 == 0);
+ check (t0._1 == 1u8);
+ check (t0._2 == '2');
+}
+
+impure fn test_tag() {
+ tag t {
+ tag1;
+ tag2(int);
+ tag3(int, u8, char);
+ }
+
+ let port[t] po = port();
+ let chan[t] ch = chan(po);
+
+ ch <| tag1;
+ ch <| tag2(10);
+ ch <| tag3(10, 11u8, 'A');
+
+ let t t1;
+
+ t1 <- po;
+ check (t1 == tag1);
+ t1 <- po;
+ check (t1 == tag2(10));
+ t1 <- po;
+ check (t1 == tag3(10, 11u8, 'A'));
+}
+
+impure fn test_chan() {
+ let port[chan[int]] po = port();
+ let chan[chan[int]] ch = chan(po);
+
+ let port[int] po0 = port();
+ let chan[int] ch0 = chan(po0);
+
+ ch <| ch0;
+
+ let chan[int] ch1;
+ ch1 <- po;
+
+ // Does the transmitted channel still work?
+ ch1 <| 10;
+
+ let int i;
+ i <- po0;
+
+ check (i == 10);
+}
+
+impure fn main() {
+ test_rec();
+ test_vec();
+ test_tup();
+ test_tag();
+ test_chan();
+}