Skip to content

Commit b2ee569

Browse files
brsongraydon
authored andcommitted
Implement trans_send and a broken trans_recv
1 parent 261d1e4 commit b2ee569

File tree

1 file changed

+42
-4
lines changed

1 file changed

+42
-4
lines changed

src/comp/middle/trans.rs

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4754,8 +4754,6 @@ fn trans_chan(@block_ctxt cx, @ast.expr e, ast.ann ann) -> result {
47544754
auto prt = trans_expr(bcx, e);
47554755
bcx = prt.bcx;
47564756

4757-
auto prt_ty = ty.expr_ty(e);
4758-
auto prt_llty = type_of(bcx.fcx.ccx, prt_ty);
47594757
auto prt_val = vp2i(bcx, prt.val);
47604758
auto sub = trans_upcall(bcx, "upcall_new_chan", vec(prt_val));
47614759
bcx = sub.bcx;
@@ -4773,12 +4771,52 @@ fn trans_chan(@block_ctxt cx, @ast.expr e, ast.ann ann) -> result {
47734771

47744772
fn trans_send(@block_ctxt cx, @ast.expr lhs, @ast.expr rhs,
47754773
ast.ann ann) -> result {
4776-
fail;
4774+
4775+
auto bcx = cx;
4776+
auto chn = trans_expr(bcx, lhs);
4777+
bcx = chn.bcx;
4778+
auto data = trans_expr(bcx, rhs);
4779+
bcx = data.bcx;
4780+
4781+
auto chan_ty = node_ann_type(cx.fcx.ccx, ann);
4782+
auto unit_ty;
4783+
alt (chan_ty.struct) {
4784+
case (ty.ty_chan(?t)) {
4785+
unit_ty = t;
4786+
}
4787+
case (_) {
4788+
bcx.fcx.ccx.sess.bug("non-chan type in trans_send");
4789+
fail;
4790+
}
4791+
}
4792+
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);
4796+
4797+
auto chn_val = vp2i(bcx, chn.val);
4798+
auto data_val = vp2i(bcx, data_alloca);
4799+
4800+
auto sub = trans_upcall(bcx, "upcall_send", vec(chn_val, data_val));
4801+
bcx = sub.bcx;
4802+
4803+
ret res(bcx, chn_val);
47774804
}
47784805

47794806
fn trans_recv(@block_ctxt cx, @ast.expr lhs, @ast.expr rhs,
47804807
ast.ann ann) -> result {
4781-
fail;
4808+
4809+
auto bcx = cx;
4810+
auto data = trans_expr(bcx, lhs);
4811+
bcx = data.bcx;
4812+
auto prt = trans_expr(bcx, rhs);
4813+
bcx = prt.bcx;
4814+
auto data_val = vp2i(bcx, data.val);
4815+
auto prt_val = vp2i(bcx, prt.val);
4816+
auto sub = trans_upcall(bcx, "upcall_recv", vec(data_val, prt_val));
4817+
bcx = sub.bcx;
4818+
4819+
ret res(bcx, data_val);
47824820
}
47834821

47844822
fn init_local(@block_ctxt cx, @ast.local local) -> result {

0 commit comments

Comments
 (0)