@@ -5544,7 +5544,7 @@ fn trans_expr(&@block_ctxt cx, &@ast::expr e) -> result {
5544
5544
}
5545
5545
5546
5546
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) ;
5548
5548
}
5549
5549
5550
5550
case ( _) {
@@ -5883,9 +5883,12 @@ fn trans_chan(&@block_ctxt cx, &@ast::expr e, &ast::ann ann) -> result {
5883
5883
ret res( bcx, chan_val) ;
5884
5884
}
5885
5885
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,
5887
5888
& @ast:: expr func, & vec[ @ast:: expr] args,
5888
5889
& ast:: ann ann) -> result {
5890
+ auto bcx = cx;
5891
+
5889
5892
// Make the task name
5890
5893
auto tname = alt( name) {
5891
5894
case( none) {
@@ -5913,22 +5916,62 @@ fn trans_spawn(&ast::spawn_dom dom, &option::t[str] name,
5913
5916
// 2. Alloca a tuple that holds these arguments (they must be in reverse
5914
5917
// order, so that they match the expected stack layout for the spawnee)
5915
5918
//
5916
- // 3. Fill the tutple with the arguments we evaluated.
5919
+ // 3. Fill the tuple with the arguments we evaluated.
5917
5920
//
5918
5921
// 4. Pass a pointer to the spawnee function and the argument tuple to
5919
5922
// upcall_start_task.
5920
5923
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) ;
5921
5943
5944
+ // Allocate and fill the tuple.
5945
+ auto llargs = alloc_ty( bcx, args_ty) ;
5946
+
5947
+ auto i = vec:: len[ ValueRef ] ( arg_vals) - 1 u;
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 -= 1 u;
5960
+ }
5961
+
5962
+ // Now we're ready to do the upcall.
5963
+
5922
5964
alt( dom) {
5923
5965
case( ast:: dom_implicit) {
5924
5966
// TODO
5925
5967
log_err "Spawning implicit domain tasks is not implemented." ;
5926
- fail;
5968
+ // fail;
5927
5969
}
5928
5970
5929
5971
case( ast:: dom_thread) {
5930
5972
// TODO
5931
5973
log_err "Spawining new thread tasks is not implemented." ;
5974
+ // TODO: for now use the normal unimpl thing.
5932
5975
fail;
5933
5976
}
5934
5977
}
0 commit comments