Skip to content

Commit ea9baac

Browse files
brsongraydon
authored andcommitted
---
yaml --- r: 1785 b: refs/heads/master c: c02cdc3 h: refs/heads/master i: 1783: 431daf5 v: v3
1 parent 97d5a47 commit ea9baac

File tree

3 files changed

+125
-16
lines changed

3 files changed

+125
-16
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: e20e7995ac39fdc879c436bc8d5a7ba5c3580f00
2+
refs/heads/master: c02cdc32a82c37e887add86773cbf49e446b335f

trunk/src/comp/middle/trans.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4790,17 +4790,19 @@ fn trans_send(@block_ctxt cx, @ast.expr lhs, @ast.expr rhs,
47904790
}
47914791
}
47924792

4793-
auto llunit_ty = type_of(bcx.fcx.ccx, unit_ty);
4794-
auto data_alloca = bcx.build.Alloca(llunit_ty);
4795-
bcx.build.Store(data.val, data_alloca);
4793+
auto data_alloc = alloc_ty(bcx, unit_ty);
4794+
bcx = data_alloc.bcx;
4795+
auto data_tmp = copy_ty(bcx, INIT, data_alloc.val, data.val, unit_ty);
4796+
bcx = data_tmp.bcx;
47964797

4797-
auto chn_val = vp2i(bcx, chn.val);
4798-
auto data_val = vp2i(bcx, data_alloca);
4798+
// TODO: Cleanups?
47994799

4800-
auto sub = trans_upcall(bcx, "upcall_send", vec(chn_val, data_val));
4800+
auto sub = trans_upcall(bcx, "upcall_send",
4801+
vec(vp2i(bcx, chn.val),
4802+
vp2i(bcx, data_alloc.val)));
48014803
bcx = sub.bcx;
48024804

4803-
ret res(bcx, chn_val);
4805+
ret res(bcx, chn.val);
48044806
}
48054807

48064808
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,
48134815
auto prt = trans_expr(bcx, rhs);
48144816
bcx = prt.bcx;
48154817

4818+
auto sub = trans_upcall(bcx, "upcall_recv",
4819+
vec(vp2i(bcx, data.res.val),
4820+
vp2i(bcx, prt.val)));
4821+
bcx = sub.bcx;
4822+
48164823
auto unit_ty = node_ann_type(cx.fcx.ccx, ann);
4817-
auto llunit_ty = type_of(bcx.fcx.ccx, unit_ty);
4818-
auto data_alloca = bcx.build.Alloca(llunit_ty);
4824+
auto data_load = load_scalar_or_boxed(bcx, data.res.val, unit_ty);
4825+
auto cp = copy_ty(bcx, DROP_EXISTING, data.res.val, data_load, unit_ty);
4826+
bcx = cp.bcx;
48194827

4820-
auto data_val = vp2i(bcx, data_alloca);
4821-
auto prt_val = vp2i(bcx, prt.val);
4822-
auto sub = trans_upcall(bcx, "upcall_recv", vec(data_val, prt_val));
4823-
bcx = sub.bcx;
4828+
// TODO: Cleanups?
48244829

4825-
auto data_load = bcx.build.Load(data_alloca);
4826-
ret copy_ty(bcx, DROP_EXISTING, data.res.val, data_load, unit_ty);
4830+
ret res(bcx, data.res.val);
48274831
}
48284832

48294833
fn init_local(@block_ctxt cx, @ast.local local) -> result {
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// -*- rust -*-
2+
3+
// Tests of ports and channels on various types
4+
5+
impure fn test_rec() {
6+
type r = rec(int val0, u8 val1, char val2);
7+
8+
let port[r] po = port();
9+
let chan[r] ch = chan(po);
10+
let r r0 = rec(val0 = 0, val1 = 1u8, val2 = '2');
11+
12+
ch <| r0;
13+
14+
let r r1;
15+
r1 <- po;
16+
17+
check (r1.val0 == 0);
18+
check (r1.val1 == 1u8);
19+
check (r1.val2 == '2');
20+
}
21+
22+
impure fn test_vec() {
23+
let port[vec[int]] po = port();
24+
let chan[vec[int]] ch = chan(po);
25+
let vec[int] v0 = vec(0, 1, 2);
26+
27+
ch <| v0;
28+
29+
let vec[int] v1;
30+
v1 <- po;
31+
32+
check (v1.(0) == 0);
33+
check (v1.(1) == 1);
34+
check (v1.(2) == 2);
35+
}
36+
37+
impure fn test_tup() {
38+
type t = tup(int, u8, char);
39+
40+
let port[t] po = port();
41+
let chan[t] ch = chan(po);
42+
let t t0 = tup(0, 1u8, '2');
43+
44+
ch <| t0;
45+
46+
let t t1;
47+
t1 <- po;
48+
49+
check (t0._0 == 0);
50+
check (t0._1 == 1u8);
51+
check (t0._2 == '2');
52+
}
53+
54+
impure fn test_tag() {
55+
tag t {
56+
tag1;
57+
tag2(int);
58+
tag3(int, u8, char);
59+
}
60+
61+
let port[t] po = port();
62+
let chan[t] ch = chan(po);
63+
64+
ch <| tag1;
65+
ch <| tag2(10);
66+
ch <| tag3(10, 11u8, 'A');
67+
68+
let t t1;
69+
70+
t1 <- po;
71+
check (t1 == tag1);
72+
t1 <- po;
73+
check (t1 == tag2(10));
74+
t1 <- po;
75+
check (t1 == tag3(10, 11u8, 'A'));
76+
}
77+
78+
impure fn test_chan() {
79+
let port[chan[int]] po = port();
80+
let chan[chan[int]] ch = chan(po);
81+
82+
let port[int] po0 = port();
83+
let chan[int] ch0 = chan(po0);
84+
85+
ch <| ch0;
86+
87+
let chan[int] ch1;
88+
ch1 <- po;
89+
90+
// Does the transmitted channel still work?
91+
ch1 <| 10;
92+
93+
let int i;
94+
i <- po0;
95+
96+
check (i == 10);
97+
}
98+
99+
impure fn main() {
100+
test_rec();
101+
test_vec();
102+
test_tup();
103+
test_tag();
104+
test_chan();
105+
}

0 commit comments

Comments
 (0)