Skip to content

Commit ce3d633

Browse files
committed
rustc: Translate locals in DPS style
1 parent 242ec22 commit ce3d633

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/comp/middle/trans_dps.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,10 @@ fn store_imm(&@block_ctxt bcx, &dest dest, ValueRef llsrc, bool cast)
196196
fn store_ptr(&@block_ctxt bcx, &dest dest, ValueRef llsrcptr) -> @block_ctxt {
197197
alt (dest) {
198198
dst_nil { /* no-op */ }
199-
dst_imm(?box) { fail "dst_imm in store_ptr"; }
199+
dst_imm(?box) {
200+
assert (std::option::is_none(*box));
201+
*box = some(bcx.build.Load(llsrcptr));
202+
}
200203
dst_alias(?box) {
201204
assert (std::option::is_none(*box));
202205
*box = some(llsrcptr);
@@ -423,6 +426,23 @@ fn trans_log(&@block_ctxt cx, &span sp, int level, &@ast::expr expr)
423426
ret next_bcx;
424427
}
425428

429+
fn trans_path(&@block_ctxt bcx, &dest dest, &ast::path path, ast::node_id id)
430+
-> @block_ctxt {
431+
alt (bcx_tcx(bcx).def_map.get(id)) {
432+
ast::def_local(?def_id) {
433+
alt (bcx_fcx(bcx).lllocals.find(def_id._1)) {
434+
none { bcx_ccx(bcx).sess.unimpl("upvar in trans_path"); }
435+
some(?llptr) {
436+
// TODO: Copy hooks.
437+
store_ptr(bcx, dest, llptr);
438+
}
439+
}
440+
}
441+
_ { bcx_ccx(bcx).sess.unimpl("def variant in trans_dps::trans_path"); }
442+
}
443+
ret bcx;
444+
}
445+
426446
fn trans_expr(&@block_ctxt bcx, &dest dest, &@ast::expr expr) -> @block_ctxt {
427447
alt (expr.node) {
428448
ast::expr_lit(?lit) { trans_lit(bcx, dest, *lit); ret bcx; }
@@ -432,6 +452,7 @@ fn trans_expr(&@block_ctxt bcx, &dest dest, &@ast::expr expr) -> @block_ctxt {
432452
ast::expr_binary(?op, ?lhs, ?rhs) {
433453
ret trans_binary(bcx, dest, expr.span, op, lhs, rhs);
434454
}
455+
ast::expr_path(?path) { ret trans_path(bcx, dest, path, expr.id); }
435456
_ { fail "unhandled expr type in trans_expr"; }
436457
}
437458
}

0 commit comments

Comments
 (0)