Clean up build_environment by having it return a rec with usefully named fields.
This commit is contained in:
parent
4170390cb6
commit
a0a2cee896
1 changed files with 5 additions and 7 deletions
|
@ -3793,7 +3793,7 @@ fn find_variable(&@fn_ctxt fcx, ast::node_id nid) -> ValueRef {
|
||||||
// contains pointers to all of the upvars and all of the tydescs in
|
// contains pointers to all of the upvars and all of the tydescs in
|
||||||
// scope. Return the ValueRef and TypeRef corresponding to the closure.
|
// scope. Return the ValueRef and TypeRef corresponding to the closure.
|
||||||
fn build_environment(&@block_ctxt cx, &ast::node_id[] upvars) ->
|
fn build_environment(&@block_ctxt cx, &ast::node_id[] upvars) ->
|
||||||
tup(ValueRef, TypeRef) {
|
rec(ValueRef ptr, TypeRef ptrty) {
|
||||||
auto upvar_count = std::ivec::len(upvars);
|
auto upvar_count = std::ivec::len(upvars);
|
||||||
auto has_iterbody = !option::is_none(cx.fcx.lliterbody);
|
auto has_iterbody = !option::is_none(cx.fcx.lliterbody);
|
||||||
if (has_iterbody) { upvar_count += 1u; }
|
if (has_iterbody) { upvar_count += 1u; }
|
||||||
|
@ -3852,7 +3852,7 @@ fn build_environment(&@block_ctxt cx, &ast::node_id[] upvars) ->
|
||||||
i += 1u;
|
i += 1u;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret tup(llenvptr, llenvptrty);
|
ret rec(ptr=llenvptr, ptrty=llenvptrty);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Given an enclosing block context, a new function context, a closure type,
|
// Given an enclosing block context, a new function context, a closure type,
|
||||||
|
@ -3943,9 +3943,7 @@ fn trans_for_each(&@block_ctxt cx, &@ast::local local, &@ast::expr seq,
|
||||||
auto decl_id = local.node.id;
|
auto decl_id = local.node.id;
|
||||||
auto upvars = get_freevars(lcx.ccx.tcx, body.node.id);
|
auto upvars = get_freevars(lcx.ccx.tcx, body.node.id);
|
||||||
|
|
||||||
auto environment_data = build_environment(cx, *upvars);
|
auto llenv = build_environment(cx, *upvars);
|
||||||
auto llenvptr = environment_data._0;
|
|
||||||
auto llenvptrty = environment_data._1;
|
|
||||||
|
|
||||||
// Step 2: Declare foreach body function.
|
// Step 2: Declare foreach body function.
|
||||||
let str s =
|
let str s =
|
||||||
|
@ -3966,7 +3964,7 @@ fn trans_for_each(&@block_ctxt cx, &@ast::local local, &@ast::expr seq,
|
||||||
|
|
||||||
// Generate code to load the environment out of the
|
// Generate code to load the environment out of the
|
||||||
// environment pointer.
|
// environment pointer.
|
||||||
load_environment(cx, fcx, llenvptrty, *upvars);
|
load_environment(cx, fcx, llenv.ptrty, *upvars);
|
||||||
|
|
||||||
// Add an upvar for the loop variable alias.
|
// Add an upvar for the loop variable alias.
|
||||||
fcx.llupvars.insert(decl_id, llvm::LLVMGetParam(fcx.llfn, 3u));
|
fcx.llupvars.insert(decl_id, llvm::LLVMGetParam(fcx.llfn, 3u));
|
||||||
|
@ -3984,7 +3982,7 @@ fn trans_for_each(&@block_ctxt cx, &@ast::local local, &@ast::expr seq,
|
||||||
alt (seq.node) {
|
alt (seq.node) {
|
||||||
case (ast::expr_call(?f, ?args)) {
|
case (ast::expr_call(?f, ?args)) {
|
||||||
auto pair = create_real_fn_pair(cx, iter_body_llty,
|
auto pair = create_real_fn_pair(cx, iter_body_llty,
|
||||||
lliterbody, llenvptr);
|
lliterbody, llenv.ptr);
|
||||||
r = trans_call(cx, f, some[ValueRef](cx.build.Load(pair)),
|
r = trans_call(cx, f, some[ValueRef](cx.build.Load(pair)),
|
||||||
args, seq.id);
|
args, seq.id);
|
||||||
ret rslt(r.bcx, C_nil());
|
ret rslt(r.bcx, C_nil());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue