提交 378c0087 编写于 作者: B Brian Anderson 提交者: Graydon Hoare

Parse 'be' statement. Pass tailcall tests. No actual tailcalls yet.

上级 c0f997be
...@@ -517,6 +517,9 @@ TEST_XFAILS_RUSTC := $(filter-out \ ...@@ -517,6 +517,9 @@ TEST_XFAILS_RUSTC := $(filter-out \
simple-obj.rs \ simple-obj.rs \
stateful-obj.rs \ stateful-obj.rs \
str-idx.rs \ str-idx.rs \
tail-call-arg-leak.rs \
tail-cps.rs \
tail-direct.rs \
type-in-nested-module.rs \ type-in-nested-module.rs \
type-param.rs \ type-param.rs \
tup.rs \ tup.rs \
......
...@@ -116,6 +116,7 @@ ...@@ -116,6 +116,7 @@
tag stmt_ { tag stmt_ {
stmt_decl(@decl); stmt_decl(@decl);
stmt_ret(option.t[@expr]); stmt_ret(option.t[@expr]);
stmt_be(@expr);
stmt_log(@expr); stmt_log(@expr);
stmt_check_expr(@expr); stmt_check_expr(@expr);
stmt_fail; stmt_fail;
......
...@@ -1200,6 +1200,12 @@ fn is_ident(token.token t) -> bool { ...@@ -1200,6 +1200,12 @@ fn is_ident(token.token t) -> bool {
} }
} }
case (token.BE) {
p.bump();
auto e = parse_expr(p);
ret @spanned(lo, e.span, ast.stmt_be(e));
}
case (token.LET) { case (token.LET) {
auto decl = parse_let(p); auto decl = parse_let(p);
auto hi = p.get_span(); auto hi = p.get_span();
...@@ -1340,6 +1346,7 @@ fn stmt_ends_with_semi(@ast.stmt stmt) -> bool { ...@@ -1340,6 +1346,7 @@ fn stmt_ends_with_semi(@ast.stmt stmt) -> bool {
} }
} }
case (ast.stmt_ret(_)) { ret true; } case (ast.stmt_ret(_)) { ret true; }
case (ast.stmt_be(_)) { ret true; }
case (ast.stmt_log(_)) { ret true; } case (ast.stmt_log(_)) { ret true; }
case (ast.stmt_check_expr(_)) { ret true; } case (ast.stmt_check_expr(_)) { ret true; }
case (ast.stmt_fail) { ret true; } case (ast.stmt_fail) { ret true; }
......
...@@ -176,6 +176,9 @@ ...@@ -176,6 +176,9 @@
(fn(&ENV e, &span sp, (fn(&ENV e, &span sp,
&option.t[@expr] rv) -> @stmt) fold_stmt_ret, &option.t[@expr] rv) -> @stmt) fold_stmt_ret,
(fn(&ENV e, &span sp,
@expr e) -> @stmt) fold_stmt_be,
(fn(&ENV e, &span sp, (fn(&ENV e, &span sp,
@expr e) -> @stmt) fold_stmt_log, @expr e) -> @stmt) fold_stmt_log,
...@@ -636,6 +639,11 @@ fn fold_stmt[ENV](&ENV env, ast_fold[ENV] fld, &@stmt s) -> @stmt { ...@@ -636,6 +639,11 @@ fn fold_stmt[ENV](&ENV env, ast_fold[ENV] fld, &@stmt s) -> @stmt {
ret fld.fold_stmt_ret(env_, s.span, oee); ret fld.fold_stmt_ret(env_, s.span, oee);
} }
case (ast.stmt_be(?e)) {
auto ee = fold_expr(env_, fld, e);
ret fld.fold_stmt_be(env_, s.span, ee);
}
case (ast.stmt_log(?e)) { case (ast.stmt_log(?e)) {
auto ee = fold_expr(env_, fld, e); auto ee = fold_expr(env_, fld, e);
ret fld.fold_stmt_log(env_, s.span, ee); ret fld.fold_stmt_log(env_, s.span, ee);
...@@ -1136,6 +1144,10 @@ fn identity_fold_stmt_ret[ENV](&ENV env, &span sp, ...@@ -1136,6 +1144,10 @@ fn identity_fold_stmt_ret[ENV](&ENV env, &span sp,
ret @respan(sp, ast.stmt_ret(rv)); ret @respan(sp, ast.stmt_ret(rv));
} }
fn identity_fold_stmt_be[ENV](&ENV env, &span sp, @expr x) -> @stmt {
ret @respan(sp, ast.stmt_be(x));
}
fn identity_fold_stmt_log[ENV](&ENV e, &span sp, @expr x) -> @stmt { fn identity_fold_stmt_log[ENV](&ENV e, &span sp, @expr x) -> @stmt {
ret @respan(sp, ast.stmt_log(x)); ret @respan(sp, ast.stmt_log(x));
} }
...@@ -1366,6 +1378,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] { ...@@ -1366,6 +1378,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
fold_stmt_decl = bind identity_fold_stmt_decl[ENV](_,_,_), fold_stmt_decl = bind identity_fold_stmt_decl[ENV](_,_,_),
fold_stmt_ret = bind identity_fold_stmt_ret[ENV](_,_,_), fold_stmt_ret = bind identity_fold_stmt_ret[ENV](_,_,_),
fold_stmt_be = bind identity_fold_stmt_be[ENV](_,_,_),
fold_stmt_log = bind identity_fold_stmt_log[ENV](_,_,_), fold_stmt_log = bind identity_fold_stmt_log[ENV](_,_,_),
fold_stmt_check_expr fold_stmt_check_expr
= bind identity_fold_stmt_check_expr[ENV](_,_,_), = bind identity_fold_stmt_check_expr[ENV](_,_,_),
......
...@@ -3128,6 +3128,11 @@ fn trans_ret(@block_ctxt cx, &option.t[@ast.expr] e) -> result { ...@@ -3128,6 +3128,11 @@ fn trans_ret(@block_ctxt cx, &option.t[@ast.expr] e) -> result {
ret res(bcx, C_nil()); ret res(bcx, C_nil());
} }
fn trans_be(@block_ctxt cx, @ast.expr e) -> result {
// FIXME: So this isn't actually a tail call
ret trans_ret(cx, some(e));
}
fn init_local(@block_ctxt cx, @ast.local local) -> result { fn init_local(@block_ctxt cx, @ast.local local) -> result {
// Make a note to drop this slot on the way out. // Make a note to drop this slot on the way out.
...@@ -3178,6 +3183,10 @@ fn trans_stmt(@block_ctxt cx, &ast.stmt s) -> result { ...@@ -3178,6 +3183,10 @@ fn trans_stmt(@block_ctxt cx, &ast.stmt s) -> result {
bcx = trans_ret(cx, e).bcx; bcx = trans_ret(cx, e).bcx;
} }
case (ast.stmt_be(?e)) {
bcx = trans_be(cx, e).bcx;
}
case (ast.stmt_expr(?e)) { case (ast.stmt_expr(?e)) {
bcx = trans_expr(cx, e).bcx; bcx = trans_expr(cx, e).bcx;
} }
......
...@@ -1719,6 +1719,21 @@ fn check_stmt(&@fn_ctxt fcx, &@ast.stmt stmt) -> @ast.stmt { ...@@ -1719,6 +1719,21 @@ fn check_stmt(&@fn_ctxt fcx, &@ast.stmt stmt) -> @ast.stmt {
} }
} }
case (ast.stmt_be(?expr)) {
alt (expr.node) {
case (ast.expr_call(_, _, _)) {
auto expr_0 = check_expr(fcx, expr);
auto expr_1 = demand_expr(fcx, fcx.ret_ty, expr_0);
ret @fold.respan[ast.stmt_](stmt.span,
ast.stmt_be(expr_1));
}
case (_) {
fcx.ccx.sess.err("Non-call expression in tail call");
fail;
}
}
}
case (ast.stmt_log(?expr)) { case (ast.stmt_log(?expr)) {
auto expr_t = check_expr(fcx, expr); auto expr_t = check_expr(fcx, expr);
ret @fold.respan[ast.stmt_](stmt.span, ast.stmt_log(expr_t)); ret @fold.respan[ast.stmt_](stmt.span, ast.stmt_log(expr_t));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册