Skip to content

Commit 855a40d

Browse files
committed
---
yaml --- r: 3717 b: refs/heads/master c: 022363a h: refs/heads/master i: 3715: 0db4783 v: v3
1 parent 1b93fb7 commit 855a40d

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: faec0d77995cc54944959e807d20b1fdf9bbac59
2+
refs/heads/master: 022363a6747c50007a991aef82621b70441d25d9

trunk/src/comp/middle/trans.rs

+28-4
Original file line numberDiff line numberDiff line change
@@ -5201,7 +5201,7 @@ fn trans_index(&@block_ctxt cx, &span sp, &@ast::expr base, &@ast::expr idx,
52015201
// The additional bool returned indicates whether it's mem (that is
52025202
// represented as an alloca or heap, hence needs a 'load' to be used as an
52035203
// immediate).
5204-
fn trans_lval(&@block_ctxt cx, &@ast::expr e) -> lval_result {
5204+
fn trans_lval_gen(&@block_ctxt cx, &@ast::expr e) -> lval_result {
52055205
alt (e.node) {
52065206
case (ast::expr_path(?p)) { ret trans_path(cx, p, e.id); }
52075207
case (ast::expr_field(?base, ?ident)) {
@@ -5263,6 +5263,23 @@ fn trans_lval(&@block_ctxt cx, &@ast::expr e) -> lval_result {
52635263
}
52645264
}
52655265

5266+
fn trans_lval(&@block_ctxt cx, &@ast::expr e) -> lval_result {
5267+
auto lv = trans_lval_gen(cx, e);
5268+
alt (lv.generic) {
5269+
case (some(?gi)) {
5270+
auto t = ty::expr_ty(cx.fcx.lcx.ccx.tcx, e);
5271+
auto n_args =
5272+
std::ivec::len(ty::ty_fn_args(cx.fcx.lcx.ccx.tcx, t));
5273+
auto args = std::ivec::init_elt(none[@ast::expr], n_args);
5274+
auto bound = trans_bind_1(lv.res.bcx, e, lv, args, e.id);
5275+
ret lval_val(bound.bcx, bound.val);
5276+
}
5277+
case (none) {
5278+
ret lv;
5279+
}
5280+
}
5281+
}
5282+
52665283
fn int_cast(&@block_ctxt bcx, TypeRef lldsttype, TypeRef llsrctype,
52675284
ValueRef llsrc, bool signed) -> ValueRef {
52685285
if (llvm::LLVMGetIntTypeWidth(lldsttype) >
@@ -5489,7 +5506,12 @@ fn trans_bind_thunk(&@local_ctxt cx, &span sp, &ty::t incoming_fty,
54895506

54905507
fn trans_bind(&@block_ctxt cx, &@ast::expr f,
54915508
&(option::t[@ast::expr])[] args, ast::node_id id) -> result {
5492-
auto f_res = trans_lval(cx, f);
5509+
auto f_res = trans_lval_gen(cx, f);
5510+
ret trans_bind_1(cx, f, f_res, args, id);
5511+
}
5512+
5513+
fn trans_bind_1(&@block_ctxt cx, &@ast::expr f, &lval_result f_res,
5514+
&(option::t[@ast::expr])[] args, ast::node_id id) -> result {
54935515
if (f_res.is_mem) {
54945516
cx.fcx.lcx.ccx.sess.unimpl("re-binding existing function");
54955517
} else {
@@ -5839,7 +5861,7 @@ fn trans_call(&@block_ctxt cx, &@ast::expr f, &option::t[ValueRef] lliterbody,
58395861
// expression because of the hack that allows us to process self-calls
58405862
// with trans_call.
58415863

5842-
auto f_res = trans_lval(cx, f);
5864+
auto f_res = trans_lval_gen(cx, f);
58435865
let ty::t fn_ty;
58445866
alt (f_res.method_ty) {
58455867
case (some(?meth)) {
@@ -6361,7 +6383,9 @@ fn trans_expr_out(&@block_ctxt cx, &@ast::expr e, out_method output) ->
63616383

63626384
auto t = ty::expr_ty(cx.fcx.lcx.ccx.tcx, e);
63636385
auto sub = trans_lval(cx, e);
6364-
ret rslt(sub.res.bcx, load_if_immediate(sub.res.bcx, sub.res.val, t));
6386+
auto v = sub.res.val;
6387+
if (sub.is_mem) { v = load_if_immediate(sub.res.bcx, v, t); }
6388+
ret rslt(sub.res.bcx, v);
63656389
}
63666390

63676391
fn with_out_method(fn(&out_method) -> result work, @block_ctxt cx,

trunk/src/test/run-pass/autobind.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
fn f[T](&T[] x) -> T {
2+
ret x.(0);
3+
}
4+
5+
fn g(fn(&int[]) -> int act) -> int {
6+
ret act(~[1, 2, 3]);
7+
}
8+
9+
fn main() {
10+
assert g(f) == 1;
11+
let fn(&str[]) -> str f1 = f;
12+
assert f1(~["x", "y", "z"]) == "x";
13+
}

0 commit comments

Comments
 (0)