auto merge of #5445 : nikomatsakis/rust/issue-3678-refactor-trans_call, r=graydon

Refactor trans_call to separate out the translation of the arguments, environment, and return pointer.  Towards #3678.  r? @brson
This commit is contained in:
bors 2013-03-20 13:15:58 -07:00
commit 99ac243e7b

View File

@ -492,12 +492,14 @@ pub fn trans_call_inner(
} }
}; };
let args_res = trans_args(bcx, llenv, args, fn_expr_ty, let llretslot = trans_ret_slot(bcx, fn_expr_ty, dest);
dest, ret_flag, autoref_arg);
bcx = args_res.bcx; let mut llargs = ~[];
let mut llargs = /*bad*/copy args_res.args; llargs.push(llretslot);
llargs.push(llenv);
bcx = trans_args(bcx, args, fn_expr_ty,
ret_flag, autoref_arg, &mut llargs);
let llretslot = args_res.retslot;
// Now that the arguments have finished evaluating, we need to revoke // Now that the arguments have finished evaluating, we need to revoke
// the cleanup for the self argument, if it exists // the cleanup for the self argument, if it exists
@ -555,30 +557,12 @@ pub enum CallArgs {
ArgVals(&'self [ValueRef]) ArgVals(&'self [ValueRef])
} }
pub struct Args { pub fn trans_ret_slot(+bcx: block,
bcx: block, +fn_ty: ty::t,
args: ~[ValueRef], +dest: expr::Dest) -> ValueRef
retslot: ValueRef {
}
pub fn trans_args(cx: block,
llenv: ValueRef,
+args: CallArgs,
fn_ty: ty::t,
dest: expr::Dest,
ret_flag: Option<ValueRef>,
+autoref_arg: AutorefArg) -> Args {
let _icx = cx.insn_ctxt("trans_args");
let mut temp_cleanups = ~[];
let arg_tys = ty::ty_fn_args(fn_ty);
let mut llargs: ~[ValueRef] = ~[];
let mut bcx = cx;
let retty = ty::ty_fn_ret(fn_ty); let retty = ty::ty_fn_ret(fn_ty);
match dest {
// Arg 0: Output pointer.
let llretslot = match dest {
expr::SaveIn(dst) => dst, expr::SaveIn(dst) => dst,
expr::Ignore => { expr::Ignore => {
if ty::type_is_nil(retty) { if ty::type_is_nil(retty) {
@ -589,13 +573,21 @@ pub fn trans_args(cx: block,
alloc_ty(bcx, retty) alloc_ty(bcx, retty)
} }
} }
}; }
llargs.push(llretslot); }
// Arg 1: Env (closure-bindings / self value) pub fn trans_args(+cx: block,
llargs.push(llenv); +args: CallArgs,
+fn_ty: ty::t,
+ret_flag: Option<ValueRef>,
+autoref_arg: AutorefArg,
+llargs: &mut ~[ValueRef]) -> block
{
let _icx = cx.insn_ctxt("trans_args");
let mut temp_cleanups = ~[];
let arg_tys = ty::ty_fn_args(fn_ty);
// ... then explicit args. let mut bcx = cx;
// First we figure out the caller's view of the types of the arguments. // First we figure out the caller's view of the types of the arguments.
// This will be needed if this is a generic call, because the callee has // This will be needed if this is a generic call, because the callee has
@ -624,7 +616,7 @@ pub fn trans_args(cx: block,
revoke_clean(bcx, *c) revoke_clean(bcx, *c)
} }
Args { bcx: bcx, args: llargs, retslot: llretslot } return bcx;
} }
pub enum AutorefArg { pub enum AutorefArg {