Skip to content

Instantly share code, notes, and snippets.

@marijnh
Created April 28, 2011 16:32
Show Gist options
  • Save marijnh/946703 to your computer and use it in GitHub Desktop.
Save marijnh/946703 to your computer and use it in GitHub Desktop.
commit ff98487d35883e8a55827c992da9c2f43fa55068
Author: Marijn Haverbeke <marijnh@gmail.com>
Date: Thu Apr 28 14:20:35 2011 +0200
stab at taking/dropping function args
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index 3e316ab..335b706 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -4602,7 +4602,7 @@ fn trans_arg_expr(@block_ctxt cx,
if (ty.type_is_structural(cx.fcx.lcx.ccx.tcx, e_ty)) {
auto re = trans_expr(bcx, e);
val = re.val;
- bcx = re.bcx;
+ bcx = take_ty(re.bcx, re.val, arg.ty).bcx;
} else if (arg.mode == ast.alias) {
let lval_result lv;
if (ty.is_lval(e)) {
@@ -4751,6 +4751,22 @@ fn trans_args(@block_ctxt cx,
ret tup(bcx, llargs, llretslot);
}
+fn trans_drop_args(@block_ctxt cx, vec[ValueRef] arg_vals, ty.t fn_ty)
+ -> @block_ctxt {
+ auto bcx = cx;
+ let vec[ty.arg] arg_tys = ty.ty_fn_args(bcx.fcx.lcx.ccx.tcx, fn_ty);
+ // Only the last N ValueRefs are formal parameters
+ auto val_i = _vec.len[ValueRef](arg_vals) - _vec.len[ty.arg](arg_tys);
+ for (ty.arg arg_ty in arg_tys) {
+ auto arg_val = arg_vals.(val_i);
+ if (arg_ty.mode == ast.val) {
+ bcx = drop_ty(bcx, arg_val, arg_ty.ty).bcx;
+ }
+ val_i += 1u;
+ }
+ ret bcx;
+}
+
fn trans_call(@block_ctxt cx, @ast.expr f,
option.t[ValueRef] lliterbody,
vec[@ast.expr] args,
@@ -4818,6 +4834,7 @@ fn trans_call(@block_ctxt cx, @ast.expr f,
*/
bcx.build.FastCall(faddr, llargs);
+ bcx = trans_drop_args(bcx, llargs, fn_ty);
auto retval = C_nil();
alt (lliterbody) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment