@@ -221,6 +221,36 @@ fn malloc(&@block_ctxt bcx, ValueRef lldest, heap heap,
221
221
ret bcx;
222
222
}
223
223
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
+
224
254
225
255
// AST substructure translation, with destinations
226
256
@@ -257,6 +287,20 @@ fn trans_lit(&@block_ctxt cx, &dest dest, &ast::lit lit) -> @block_ctxt {
257
287
ret bcx;
258
288
}
259
289
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
+
260
304
fn trans_log ( & @block_ctxt cx , & span sp, int level , & @ast:: expr expr)
261
305
-> @block_ctxt {
262
306
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 {
363
407
ast:: expr_log ( ?level, ?operand) {
364
408
ret trans_log ( bcx, expr. span , level, operand) ;
365
409
}
410
+ ast:: expr_binary ( ?op, ?lhs, ?rhs) {
411
+ ret trans_binary ( bcx, dest, op, lhs, rhs) ;
412
+ }
366
413
_ { fail "unhandled expr type in trans_expr" ; }
367
414
}
368
415
}
0 commit comments