Skip to content

Commit 219351e

Browse files
author
Eric Holk
committed
A little closure towards translating spawn. We're about ready to do the upcall, except that rustc segfaults.
1 parent d6338a8 commit 219351e

File tree

1 file changed

+47
-4
lines changed

1 file changed

+47
-4
lines changed

src/comp/middle/trans.rs

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5544,7 +5544,7 @@ fn trans_expr(&@block_ctxt cx, &@ast::expr e) -> result {
55445544
}
55455545

55465546
case (ast::expr_spawn(?dom, ?name, ?func, ?args, ?ann)) {
5547-
ret trans_spawn(dom, name, func, args, ann);
5547+
ret trans_spawn(cx, dom, name, func, args, ann);
55485548
}
55495549

55505550
case (_) {
@@ -5883,9 +5883,12 @@ fn trans_chan(&@block_ctxt cx, &@ast::expr e, &ast::ann ann) -> result {
58835883
ret res(bcx, chan_val);
58845884
}
58855885

5886-
fn trans_spawn(&ast::spawn_dom dom, &option::t[str] name,
5886+
fn trans_spawn(&@block_ctxt cx,
5887+
&ast::spawn_dom dom, &option::t[str] name,
58875888
&@ast::expr func, &vec[@ast::expr] args,
58885889
&ast::ann ann) -> result {
5890+
auto bcx = cx;
5891+
58895892
// Make the task name
58905893
auto tname = alt(name) {
58915894
case(none) {
@@ -5913,22 +5916,62 @@ fn trans_spawn(&ast::spawn_dom dom, &option::t[str] name,
59135916
// 2. Alloca a tuple that holds these arguments (they must be in reverse
59145917
// order, so that they match the expected stack layout for the spawnee)
59155918
//
5916-
// 3. Fill the tutple with the arguments we evaluated.
5919+
// 3. Fill the tuple with the arguments we evaluated.
59175920
//
59185921
// 4. Pass a pointer to the spawnee function and the argument tuple to
59195922
// upcall_start_task.
59205923

5924+
// Translate the arguments, remembering their types and where the values
5925+
// ended up.
5926+
let vec[ty::t] arg_tys = [];
5927+
let vec[ValueRef] arg_vals = [];
5928+
for(@ast::expr e in args) {
5929+
auto arg = trans_expr(bcx, e);
5930+
5931+
bcx = arg.bcx;
5932+
5933+
vec::push[ValueRef](arg_vals, arg.val);
5934+
vec::push[ty::t](arg_tys,
5935+
ty::expr_ty(cx.fcx.lcx.ccx.tcx,
5936+
e));
5937+
}
5938+
5939+
// Make the tuple. We have to reverse the types first though.
5940+
vec::reverse[ty::t](arg_tys);
5941+
vec::reverse[ValueRef](arg_vals);
5942+
auto args_ty = ty::mk_imm_tup(cx.fcx.lcx.ccx.tcx, arg_tys);
59215943

5944+
// Allocate and fill the tuple.
5945+
auto llargs = alloc_ty(bcx, args_ty);
5946+
5947+
auto i = vec::len[ValueRef](arg_vals) - 1u;
5948+
for(ValueRef v in arg_vals) {
5949+
// log_err #fmt("ty(llargs) = %s",
5950+
// val_str(bcx.fcx.lcx.ccx.tn, llargs.val));
5951+
auto target = bcx.build.GEP(llargs.val, [C_int(0), C_int(i as int)]);
5952+
5953+
// log_err #fmt("ty(v) = %s", val_str(bcx.fcx.lcx.ccx.tn, v));
5954+
// log_err #fmt("ty(target) = %s",
5955+
// val_str(bcx.fcx.lcx.ccx.tn, target));
5956+
5957+
bcx.build.Store(v, target);
5958+
5959+
i -= 1u;
5960+
}
5961+
5962+
// Now we're ready to do the upcall.
5963+
59225964
alt(dom) {
59235965
case(ast::dom_implicit) {
59245966
// TODO
59255967
log_err "Spawning implicit domain tasks is not implemented.";
5926-
fail;
5968+
//fail;
59275969
}
59285970

59295971
case(ast::dom_thread) {
59305972
// TODO
59315973
log_err "Spawining new thread tasks is not implemented.";
5974+
// TODO: for now use the normal unimpl thing.
59325975
fail;
59335976
}
59345977
}

0 commit comments

Comments
 (0)