aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrian Anderson <[email protected]>2011-03-17 23:33:00 -0400
committerGraydon Hoare <[email protected]>2011-03-22 08:04:39 -0700
commitb2ee569c2303fcfe888bf7431537b9487d9967f8 (patch)
treed2ff0c422d137e3b3c98ef1ca95b2468b0e15f06 /src
parentAdd codegen for ports and chans (diff)
downloadrust-b2ee569c2303fcfe888bf7431537b9487d9967f8.tar.xz
rust-b2ee569c2303fcfe888bf7431537b9487d9967f8.zip
Implement trans_send and a broken trans_recv
Diffstat (limited to 'src')
-rw-r--r--src/comp/middle/trans.rs46
1 files changed, 42 insertions, 4 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index d4b4923e..fbab4987 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -4754,8 +4754,6 @@ fn trans_chan(@block_ctxt cx, @ast.expr e, ast.ann ann) -> result {
auto prt = trans_expr(bcx, e);
bcx = prt.bcx;
- auto prt_ty = ty.expr_ty(e);
- auto prt_llty = type_of(bcx.fcx.ccx, prt_ty);
auto prt_val = vp2i(bcx, prt.val);
auto sub = trans_upcall(bcx, "upcall_new_chan", vec(prt_val));
bcx = sub.bcx;
@@ -4773,12 +4771,52 @@ fn trans_chan(@block_ctxt cx, @ast.expr e, ast.ann ann) -> result {
fn trans_send(@block_ctxt cx, @ast.expr lhs, @ast.expr rhs,
ast.ann ann) -> result {
- fail;
+
+ auto bcx = cx;
+ auto chn = trans_expr(bcx, lhs);
+ bcx = chn.bcx;
+ auto data = trans_expr(bcx, rhs);
+ bcx = data.bcx;
+
+ auto chan_ty = node_ann_type(cx.fcx.ccx, ann);
+ auto unit_ty;
+ alt (chan_ty.struct) {
+ case (ty.ty_chan(?t)) {
+ unit_ty = t;
+ }
+ case (_) {
+ bcx.fcx.ccx.sess.bug("non-chan type in trans_send");
+ fail;
+ }
+ }
+
+ 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 chn_val = vp2i(bcx, chn.val);
+ auto data_val = vp2i(bcx, data_alloca);
+
+ auto sub = trans_upcall(bcx, "upcall_send", vec(chn_val, data_val));
+ bcx = sub.bcx;
+
+ ret res(bcx, chn_val);
}
fn trans_recv(@block_ctxt cx, @ast.expr lhs, @ast.expr rhs,
ast.ann ann) -> result {
- fail;
+
+ auto bcx = cx;
+ auto data = trans_expr(bcx, lhs);
+ bcx = data.bcx;
+ auto prt = trans_expr(bcx, rhs);
+ bcx = prt.bcx;
+ auto data_val = vp2i(bcx, data.val);
+ auto prt_val = vp2i(bcx, prt.val);
+ auto sub = trans_upcall(bcx, "upcall_recv", vec(data_val, prt_val));
+ bcx = sub.bcx;
+
+ ret res(bcx, data_val);
}
fn init_local(@block_ctxt cx, @ast.local local) -> result {