Skip to content

Instantly share code, notes, and snippets.

@eholk
Created May 20, 2011 01:19
Show Gist options
  • Save eholk/982159 to your computer and use it in GitHub Desktop.
Save eholk/982159 to your computer and use it in GitHub Desktop.
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index 3009478..64a6bcb 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -5562,7 +5562,7 @@ fn trans_expr(&@block_ctxt cx, &@ast::expr e) -> result {
}
case (ast::expr_spawn(?dom, ?name, ?func, ?args, ?ann)) {
- ret trans_spawn(dom, name, func, args, ann);
+ ret trans_spawn(cx, dom, name, func, args, ann);
}
case (_) {
@@ -5901,9 +5901,12 @@ fn trans_chan(&@block_ctxt cx, &@ast::expr e, &ast::ann ann) -> result {
ret res(bcx, chan_val);
}
-fn trans_spawn(&ast::spawn_dom dom, &option::t[str] name,
+fn trans_spawn(&@block_ctxt cx,
+ &ast::spawn_dom dom, &option::t[str] name,
&@ast::expr func, &vec[@ast::expr] args,
&ast::ann ann) -> result {
+ auto bcx = cx;
+
// Make the task name
auto tname = alt(name) {
case(none) {
@@ -5931,12 +5934,51 @@ fn trans_spawn(&ast::spawn_dom dom, &option::t[str] name,
// 2. Alloca a tuple that holds these arguments (they must be in reverse
// order, so that they match the expected stack layout for the spawnee)
//
- // 3. Fill the tutple with the arguments we evaluated.
+ // 3. Fill the tuple with the arguments we evaluated.
//
// 4. Pass a pointer to the spawnee function and the argument tuple to
// upcall_start_task.
+ // Translate the arguments, remembering their types and where the values
+ // ended up.
+ let vec[ty::t] arg_tys = [];
+ let vec[ValueRef] arg_vals = [];
+ for(@ast::expr e in args) {
+ auto arg = trans_expr(bcx, e);
+
+ bcx = arg.bcx;
+
+ vec::push[ValueRef](arg_vals, arg.val);
+ vec::push[ty::t](arg_tys,
+ ty::expr_ty(cx.fcx.lcx.ccx.tcx,
+ e));
+ }
+
+ // Make the tuple. We have to reverse the types first though.
+ vec::reverse[ty::t](arg_tys);
+ vec::reverse[ValueRef](arg_vals);
+ auto args_ty = ty::mk_imm_tup(cx.fcx.lcx.ccx.tcx, arg_tys);
+ // Allocate and fill the tuple.
+ auto llargs = alloc_ty(bcx, args_ty);
+
+ auto i = vec::len[ValueRef](arg_vals) - 1u;
+ for(@ValueRef v in arg_vals) {
+ log_err #fmt("ty(llargs) = %s",
+ val_str(bcx.fcx.lcx.ccx.tn, llargs.val));
+ auto target = bcx.build.GEP(llargs.val, [C_int(i as int)]);
+
+ log_err #fmt("ty(v) = %s", val_str(bcx.fcx.lcx.ccx.tn, *v));
+ log_err #fmt("ty(target) = %s",
+ val_str(bcx.fcx.lcx.ccx.tn, target));
+
+ bcx.build.Store(*v, target);
+
+ i -= 1u;
+ }
+
+ // Now we're ready to do the upcall.
+
alt(dom) {
case(ast::dom_implicit) {
// TODO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment