@@ -137,6 +137,10 @@ fn T_f64() -> TypeRef {
137
137
ret llvm. LLVMDoubleType ( ) ;
138
138
}
139
139
140
+ fn T_bool ( ) -> TypeRef {
141
+ ret T_i1 ( ) ;
142
+ }
143
+
140
144
fn T_int ( ) -> TypeRef {
141
145
// FIXME: switch on target type.
142
146
ret T_i32 ( ) ;
@@ -228,7 +232,7 @@ fn T_taskptr() -> TypeRef {
228
232
fn type_of ( @trans_ctxt cx , @ast. ty t ) -> TypeRef {
229
233
alt ( t. node ) {
230
234
case ( ast. ty_nil ) { ret T_nil ( ) ; }
231
- case ( ast. ty_bool ) { ret T_i1 ( ) ; }
235
+ case ( ast. ty_bool ) { ret T_bool ( ) ; }
232
236
case ( ast. ty_int ) { ret T_int ( ) ; }
233
237
case ( ast. ty_uint ) { ret T_int ( ) ; }
234
238
case ( ast. ty_machine ( ?tm) ) {
@@ -291,9 +295,9 @@ fn C_nil() -> ValueRef {
291
295
292
296
fn C_bool ( bool b) -> ValueRef {
293
297
if ( b) {
294
- ret C_integral ( 1 , T_i1 ( ) ) ;
298
+ ret C_integral ( 1 , T_bool ( ) ) ;
295
299
} else {
296
- ret C_integral ( 0 , T_i1 ( ) ) ;
300
+ ret C_integral ( 0 , T_bool ( ) ) ;
297
301
}
298
302
}
299
303
@@ -465,6 +469,54 @@ fn trans_unary(@block_ctxt cx, ast.unop op, &ast.expr e) -> result {
465
469
fn trans_binary ( @block_ctxt cx , ast. binop op ,
466
470
& ast . expr a, & ast . expr b) -> result {
467
471
472
+ // First couple cases are lazy:
473
+
474
+ alt ( op) {
475
+ case ( ast. and ) {
476
+ // Lazy-eval and
477
+ auto lhs_res = trans_expr ( cx, a) ;
478
+
479
+ auto rhs_cx = new_empty_block_ctxt ( cx. fcx ) ;
480
+ auto rhs_res = trans_expr ( rhs_cx, b) ;
481
+
482
+ auto next_cx = new_extension_block_ctxt ( cx) ;
483
+ rhs_res. bcx . build . Br ( next_cx. llbb ) ;
484
+
485
+ lhs_res. bcx . build . CondBr ( lhs_res. val ,
486
+ rhs_cx. llbb ,
487
+ next_cx. llbb ) ;
488
+ auto phi = next_cx. build . Phi ( T_bool ( ) ,
489
+ vec ( lhs_res. val ,
490
+ rhs_res. val ) ,
491
+ vec ( lhs_res. bcx . llbb ,
492
+ rhs_res. bcx . llbb ) ) ;
493
+ ret res( next_cx, phi) ;
494
+ }
495
+
496
+ case ( ast. or ) {
497
+ // Lazy-eval or
498
+ auto lhs_res = trans_expr ( cx, a) ;
499
+
500
+ auto rhs_cx = new_empty_block_ctxt ( cx. fcx ) ;
501
+ auto rhs_res = trans_expr ( rhs_cx, b) ;
502
+
503
+ auto next_cx = new_extension_block_ctxt ( cx) ;
504
+ rhs_res. bcx . build . Br ( next_cx. llbb ) ;
505
+
506
+ lhs_res. bcx . build . CondBr ( lhs_res. val ,
507
+ next_cx. llbb ,
508
+ rhs_cx. llbb ) ;
509
+ auto phi = next_cx. build . Phi ( T_bool ( ) ,
510
+ vec ( lhs_res. val ,
511
+ rhs_res. val ) ,
512
+ vec ( lhs_res. bcx . llbb ,
513
+ rhs_res. bcx . llbb ) ) ;
514
+ ret res( next_cx, phi) ;
515
+ }
516
+ }
517
+
518
+ // Remaining cases are eager:
519
+
468
520
auto lhs = trans_expr ( cx, a) ;
469
521
auto sub = trans_expr ( lhs. bcx , b) ;
470
522
@@ -774,10 +826,9 @@ fn new_top_block_ctxt(@fn_ctxt fcx) -> @block_ctxt {
774
826
775
827
}
776
828
777
- // Use this when you are making a block_ctxt to replace the
778
- // current one, i.e. when chaining together sequences of stmts
779
- // or making sub-blocks you will branch back out of and wish to
780
- // "carry on" in the parent block's context.
829
+ // Use this when you are making a block_ctxt that starts with a fresh
830
+ // terminator and empty cleanups (no locals, no implicit return when
831
+ // falling off the end).
781
832
fn new_empty_block_ctxt ( @fn_ctxt fcx ) -> @block_ctxt {
782
833
fn terminate_no_op ( @fn_ctxt cx , builder build) {
783
834
}
0 commit comments