提交 575aae40 编写于 作者: M Marijn Haverbeke

Saner approach to lvalues and callable values in trans

LValues no longer carry information about generics and objs, instead
there's an extended form of lvalue, lval_maybe_callee, only used by
call and bind, which holds this info.

This makes it possible to take the value of a method and get a working
closure, and will (with some more work) allow us to call statically
known functions without loading from their pair.

Closes #435
Closes #758
上级 d9c664e3
此差异已折叠。
...@@ -117,7 +117,7 @@ fn trans_vec(bcx: @block_ctxt, args: [@ast::expr], id: ast::node_id) -> ...@@ -117,7 +117,7 @@ fn trans_vec(bcx: @block_ctxt, args: [@ast::expr], id: ast::node_id) ->
let i = 0u; let i = 0u;
for e in args { for e in args {
let lv = trans_lval(bcx, e); let lv = trans_lval(bcx, e);
bcx = lv.res.bcx; bcx = lv.bcx;
let lleltptr = let lleltptr =
if ty::type_has_dynamic_size(bcx_tcx(bcx), unit_ty) { if ty::type_has_dynamic_size(bcx_tcx(bcx), unit_ty) {
InBoundsGEP(bcx, dataptr, [Mul(bcx, C_uint(i), llunitsz)]) InBoundsGEP(bcx, dataptr, [Mul(bcx, C_uint(i), llunitsz)])
......
// Test case for issue #435. // Test case for issue #435.
obj foo() { obj foo(x: int) {
fn add5(n: int) -> int { ret n + 5; } fn add5(n: int) -> int { ret n + x; }
} }
fn add5(n: int) -> int { ret n + 5; } fn add5(n: int) -> int { ret n + 5; }
...@@ -10,7 +10,7 @@ fn main() { ...@@ -10,7 +10,7 @@ fn main() {
assert (add5(7) == 12); assert (add5(7) == 12);
assert (fiveplusseven() == 12); assert (fiveplusseven() == 12);
let my_foo = foo(); let my_foo = foo(5);
let fiveplusseven_too = bind my_foo.add5(7); let fiveplusseven_too = bind my_foo.add5(7);
assert (my_foo.add5(7) == 12); assert (my_foo.add5(7) == 12);
assert (fiveplusseven_too() == 12); assert (fiveplusseven_too() == 12);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册