Skip to content

Commit 7e73864

Browse files
brsongraydon
authored andcommitted
---
yaml --- r: 1312 b: refs/heads/master c: 6b7cab3 h: refs/heads/master v: v3
1 parent b8502fb commit 7e73864

File tree

6 files changed

+32
-12
lines changed

6 files changed

+32
-12
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: 3cac20dae3272728282466467cb0193d7dbbf00c
2+
refs/heads/master: 6b7cab3602eae7893a4efcee760600ab69d75173

trunk/src/comp/front/ast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ tag stmt_ {
116116
stmt_ret(option.t[@expr]);
117117
stmt_log(@expr);
118118
stmt_check_expr(@expr);
119+
stmt_fail;
119120
stmt_expr(@expr);
120121
}
121122

trunk/src/comp/front/parser.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,11 @@ impure fn parse_stmt(parser p) -> @ast.stmt {
11581158
}
11591159
}
11601160

1161+
case (token.FAIL) {
1162+
p.bump();
1163+
ret @spanned(lo, p.get_span(), ast.stmt_fail);
1164+
}
1165+
11611166
case (token.RET) {
11621167
p.bump();
11631168
alt (p.peek()) {
@@ -1315,6 +1320,7 @@ fn stmt_ends_with_semi(@ast.stmt stmt) -> bool {
13151320
case (ast.stmt_ret(_)) { ret true; }
13161321
case (ast.stmt_log(_)) { ret true; }
13171322
case (ast.stmt_check_expr(_)) { ret true; }
1323+
case (ast.stmt_fail) { ret true; }
13181324
case (ast.stmt_expr(?e)) {
13191325
alt (e.node) {
13201326
case (ast.expr_vec(_,_)) { ret true; }

trunk/src/comp/middle/fold.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,10 @@ fn fold_stmt[ENV](&ENV env, ast_fold[ENV] fld, &@stmt s) -> @stmt {
615615
ret fld.fold_stmt_check_expr(env_, s.span, ee);
616616
}
617617

618+
case (ast.stmt_fail) {
619+
ret s;
620+
}
621+
618622
case (ast.stmt_expr(?e)) {
619623
auto ee = fold_expr(env_, fld, e);
620624
ret fld.fold_stmt_expr(env_, s.span, ee);

trunk/src/comp/middle/trans.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,11 +2251,7 @@ fn trans_index(@block_ctxt cx, &ast.span sp, @ast.expr base,
22512251
ix.bcx.build.CondBr(bounds_check, next_cx.llbb, fail_cx.llbb);
22522252

22532253
// fail: bad bounds check.
2254-
auto V_expr_str = p2i(C_cstr(cx.fcx.ccx, "out-of-bounds access"));
2255-
auto V_filename = p2i(C_cstr(cx.fcx.ccx, sp.filename));
2256-
auto V_line = sp.lo.line as int;
2257-
auto args = vec(V_expr_str, V_filename, C_int(V_line));
2258-
auto fail_res = trans_upcall(fail_cx, "upcall_fail", args);
2254+
auto fail_res = trans_fail(fail_cx, sp, "bounds check");
22592255
fail_res.bcx.build.Br(next_cx.llbb);
22602256

22612257
auto body = next_cx.build.GEP(v, vec(C_int(0), C_int(abi.vec_elt_data)));
@@ -2904,13 +2900,9 @@ fn trans_check_expr(@block_ctxt cx, @ast.expr e) -> result {
29042900
auto cond_res = trans_expr(cx, e);
29052901

29062902
// FIXME: need pretty-printer.
2907-
auto V_expr_str = p2i(C_cstr(cx.fcx.ccx, "<expr>"));
2908-
auto V_filename = p2i(C_cstr(cx.fcx.ccx, e.span.filename));
2909-
auto V_line = e.span.lo.line as int;
2910-
auto args = vec(V_expr_str, V_filename, C_int(V_line));
2911-
2903+
auto expr_str = "<expr>";
29122904
auto fail_cx = new_sub_block_ctxt(cx, "fail");
2913-
auto fail_res = trans_upcall(fail_cx, "upcall_fail", args);
2905+
auto fail_res = trans_fail(fail_cx, e.span, expr_str);
29142906

29152907
auto next_cx = new_sub_block_ctxt(cx, "next");
29162908
fail_res.bcx.build.Br(next_cx.llbb);
@@ -2920,6 +2912,15 @@ fn trans_check_expr(@block_ctxt cx, @ast.expr e) -> result {
29202912
ret res(next_cx, C_nil());
29212913
}
29222914

2915+
fn trans_fail(@block_ctxt cx, common.span sp, str fail_str) -> result {
2916+
auto V_fail_str = p2i(C_cstr(cx.fcx.ccx, fail_str));
2917+
auto V_filename = p2i(C_cstr(cx.fcx.ccx, sp.filename));
2918+
auto V_line = sp.lo.line as int;
2919+
auto args = vec(V_fail_str, V_filename, C_int(V_line));
2920+
2921+
ret trans_upcall(cx, "upcall_fail", args);
2922+
}
2923+
29232924
fn trans_ret(@block_ctxt cx, &option.t[@ast.expr] e) -> result {
29242925
auto bcx = cx;
29252926
auto val = C_nil();
@@ -3035,6 +3036,10 @@ fn trans_stmt(@block_ctxt cx, &ast.stmt s) -> result {
30353036
bcx = trans_check_expr(cx, a).bcx;
30363037
}
30373038

3039+
case (ast.stmt_fail) {
3040+
bcx = trans_fail(cx, s.span, "explicit failure").bcx;
3041+
}
3042+
30383043
case (ast.stmt_ret(?e)) {
30393044
bcx = trans_ret(cx, e).bcx;
30403045
}

trunk/src/comp/middle/typeck.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,6 +1682,10 @@ fn check_stmt(&@fn_ctxt fcx, &@ast.stmt stmt) -> @ast.stmt {
16821682
ast.stmt_check_expr(expr_t));
16831683
}
16841684

1685+
case (ast.stmt_fail) {
1686+
ret stmt;
1687+
}
1688+
16851689
case (ast.stmt_expr(?expr)) {
16861690
auto expr_t = check_expr(fcx, expr);
16871691
ret @fold.respan[ast.stmt_](stmt.span, ast.stmt_expr(expr_t));

0 commit comments

Comments
 (0)