Skip to content

Commit 6745050

Browse files
committed
---
yaml --- r: 811 b: refs/heads/master c: 3689439 h: refs/heads/master i: 809: 7736be0 807: d218154 v: v3
1 parent 19be7d7 commit 6745050

File tree

2 files changed

+59
-8
lines changed

2 files changed

+59
-8
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: 71b1f1d117e2444e4588c67c9aa2772e74ad5678
2+
refs/heads/master: 368943998de2dee5f47c8e05e2facb11dfd148b7

trunk/src/comp/middle/trans.rs

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ fn T_f64() -> TypeRef {
137137
ret llvm.LLVMDoubleType();
138138
}
139139

140+
fn T_bool() -> TypeRef {
141+
ret T_i1();
142+
}
143+
140144
fn T_int() -> TypeRef {
141145
// FIXME: switch on target type.
142146
ret T_i32();
@@ -228,7 +232,7 @@ fn T_taskptr() -> TypeRef {
228232
fn type_of(@trans_ctxt cx, @ast.ty t) -> TypeRef {
229233
alt (t.node) {
230234
case (ast.ty_nil) { ret T_nil(); }
231-
case (ast.ty_bool) { ret T_i1(); }
235+
case (ast.ty_bool) { ret T_bool(); }
232236
case (ast.ty_int) { ret T_int(); }
233237
case (ast.ty_uint) { ret T_int(); }
234238
case (ast.ty_machine(?tm)) {
@@ -291,9 +295,9 @@ fn C_nil() -> ValueRef {
291295

292296
fn C_bool(bool b) -> ValueRef {
293297
if (b) {
294-
ret C_integral(1, T_i1());
298+
ret C_integral(1, T_bool());
295299
} else {
296-
ret C_integral(0, T_i1());
300+
ret C_integral(0, T_bool());
297301
}
298302
}
299303

@@ -465,6 +469,54 @@ fn trans_unary(@block_ctxt cx, ast.unop op, &ast.expr e) -> result {
465469
fn trans_binary(@block_ctxt cx, ast.binop op,
466470
&ast.expr a, &ast.expr b) -> result {
467471

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+
468520
auto lhs = trans_expr(cx, a);
469521
auto sub = trans_expr(lhs.bcx, b);
470522

@@ -774,10 +826,9 @@ fn new_top_block_ctxt(@fn_ctxt fcx) -> @block_ctxt {
774826

775827
}
776828

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).
781832
fn new_empty_block_ctxt(@fn_ctxt fcx) -> @block_ctxt {
782833
fn terminate_no_op(@fn_ctxt cx, builder build) {
783834
}

0 commit comments

Comments
 (0)