Skip to content

Commit b3f42e1

Browse files
committed
---
yaml --- r: 3976 b: refs/heads/master c: 6828759 h: refs/heads/master v: v3
1 parent a6e94f9 commit b3f42e1

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 437b77610001d7fc9b41ce50d82db94cc3c642ac
2+
refs/heads/master: 682875929efe558b42318d6ae8b2ef8dc625e94a

trunk/src/comp/middle/trans_dps.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,36 @@ fn malloc(&@block_ctxt bcx, ValueRef lldest, heap heap,
221221
ret bcx;
222222
}
223223

224+
// If the supplied destination is an alias, spills to a temporary. Returns the
225+
// new destination.
226+
fn spill_alias(&@block_ctxt cx, &dest dest, ty::t t)
227+
-> tup(@block_ctxt, dest) {
228+
auto bcx = cx;
229+
alt (dest) {
230+
dst_alias(?box) {
231+
// TODO: Mark the alias as needing a cleanup.
232+
assert (std::option::is_none(*box));
233+
auto r = trans::alloc_ty(cx, t);
234+
bcx = r.bcx; auto llptr = r.val;
235+
*box = some(llptr);
236+
ret tup(bcx, dst_move(llptr));
237+
}
238+
_ { ret tup(bcx, dest); }
239+
}
240+
}
241+
242+
fn mk_temp(&@block_ctxt cx, ty::t t) -> tup(@block_ctxt, dest) {
243+
auto bcx = cx;
244+
if ty::type_is_nil(bcx_tcx(bcx), t) { ret tup(bcx, dst_nil); }
245+
if trans::type_is_immediate(bcx_ccx(bcx), t) {
246+
ret tup(bcx, dst_imm(@mutable none));
247+
}
248+
249+
auto r = trans::alloc_ty(cx, t);
250+
bcx = r.bcx; auto llptr = r.val;
251+
ret tup(bcx, dst_copy(llptr));
252+
}
253+
224254

225255
// AST substructure translation, with destinations
226256

@@ -257,6 +287,20 @@ fn trans_lit(&@block_ctxt cx, &dest dest, &ast::lit lit) -> @block_ctxt {
257287
ret bcx;
258288
}
259289

290+
fn trans_binary(&@block_ctxt cx, &dest in_dest, ast::binop op,
291+
&@ast::expr lhs, &@ast::expr rhs) -> @block_ctxt {
292+
auto bcx = cx;
293+
auto r = spill_alias(bcx, in_dest, ty::expr_ty(bcx_tcx(bcx), lhs));
294+
bcx = r._0; auto dest = r._1;
295+
bcx = trans_expr(bcx, dest, lhs);
296+
297+
r = mk_temp(bcx, ty::expr_ty(bcx_tcx(bcx), rhs));
298+
bcx = r._0; auto rhs_tmp = r._1;
299+
bcx = trans_expr(bcx, rhs_tmp, rhs);
300+
301+
ret bcx; // TODO
302+
}
303+
260304
fn trans_log(&@block_ctxt cx, &span sp, int level, &@ast::expr expr)
261305
-> @block_ctxt {
262306
fn trans_log_level(&@local_ctxt lcx) -> ValueRef {
@@ -363,6 +407,9 @@ fn trans_expr(&@block_ctxt bcx, &dest dest, &@ast::expr expr) -> @block_ctxt {
363407
ast::expr_log(?level, ?operand) {
364408
ret trans_log(bcx, expr.span, level, operand);
365409
}
410+
ast::expr_binary(?op, ?lhs, ?rhs) {
411+
ret trans_binary(bcx, dest, op, lhs, rhs);
412+
}
366413
_ { fail "unhandled expr type in trans_expr"; }
367414
}
368415
}

0 commit comments

Comments
 (0)