Skip to content

Commit 6828759

Browse files
committed
rustc: Stub binary operator translation
1 parent 437b776 commit 6828759

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

src/comp/middle/trans_dps.rs

+47
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)