aboutsummaryrefslogtreecommitdiff
path: root/src/comp/middle/trans.rs
diff options
context:
space:
mode:
authorGraydon Hoare <[email protected]>2010-11-03 11:05:15 -0700
committerGraydon Hoare <[email protected]>2010-11-03 11:05:15 -0700
commite5fdd7b63a7365df015c9d08111a8f635b25e058 (patch)
treedaa0b7450779173d9eceed343e038424799b645d /src/comp/middle/trans.rs
parentTeach rustc lexer about changes to stratum, opacity and effect keywords. (diff)
downloadrust-e5fdd7b63a7365df015c9d08111a8f635b25e058.tar.xz
rust-e5fdd7b63a7365df015c9d08111a8f635b25e058.zip
Support while and do-while loops in rustc.
Diffstat (limited to 'src/comp/middle/trans.rs')
-rw-r--r--src/comp/middle/trans.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index 9fefcf55..c5374212 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -653,6 +653,38 @@ impure fn trans_if(@block_ctxt cx, &ast.expr cond,
ret res(next_cx, phi);
}
+impure fn trans_while(@block_ctxt cx, &ast.expr cond,
+ &ast.block body) -> result {
+
+ auto cond_cx = new_empty_block_ctxt(cx.fcx);
+ auto body_cx = new_empty_block_ctxt(cx.fcx);
+ auto next_cx = new_extension_block_ctxt(cx);
+
+ cx.build.Br(cond_cx.llbb);
+ auto cond_res = trans_expr(cond_cx, cond);
+ cond_cx.build.CondBr(cond_res.val,
+ body_cx.llbb,
+ next_cx.llbb);
+ auto body_res = trans_block(body_cx, body);
+ body_cx.build.Br(cond_cx.llbb);
+ ret res(next_cx, C_nil());
+}
+
+impure fn trans_do_while(@block_ctxt cx, &ast.block body,
+ &ast.expr cond) -> result {
+
+ auto body_cx = new_empty_block_ctxt(cx.fcx);
+ auto next_cx = new_extension_block_ctxt(cx);
+
+ cx.build.Br(body_cx.llbb);
+ auto body_res = trans_block(body_cx, body);
+ auto cond_res = trans_expr(body_cx, cond);
+ body_cx.build.CondBr(cond_res.val,
+ body_cx.llbb,
+ next_cx.llbb);
+ ret res(next_cx, body_res.val);
+}
+
// The additional bool returned indicates whether it's a local
// (that is represented as an alloca, hence needs a 'load' to be
// used as an rval).
@@ -723,6 +755,10 @@ impure fn trans_expr(@block_ctxt cx, &ast.expr e) -> result {
ret trans_if(cx, *cond, thn, els);
}
+ case (ast.expr_while(?cond, ?body, _)) {
+ ret trans_while(cx, *cond, body);
+ }
+
case (ast.expr_block(?blk, _)) {
auto sub_cx = new_empty_block_ctxt(cx.fcx);
auto next_cx = new_extension_block_ctxt(cx);