Cleanup for 'be' statement and comments about future typestate

This commit is contained in:
Brian Anderson 2011-02-09 22:36:37 -05:00 committed by Graydon Hoare
parent 6461cf30de
commit f17a3421e0
6 changed files with 30 additions and 16 deletions

View File

@ -315,6 +315,17 @@ fn index_native_item(native_mod_index index, @native_item it) {
}
}
fn is_call_expr(@expr e) -> bool {
alt (e.node) {
case (expr_call(_, _, _)) {
ret true;
}
case (_) {
ret false;
}
}
}
//
// Local Variables:
// mode: rust

View File

@ -1203,7 +1203,13 @@ impure fn parse_stmt(parser p) -> @ast.stmt {
case (token.BE) {
p.bump();
auto e = parse_expr(p);
ret @spanned(lo, e.span, ast.stmt_be(e));
// FIXME: Is this the right place for this check?
if /*check*/ (ast.is_call_expr(e)) {
ret @spanned(lo, e.span, ast.stmt_be(e));
}
else {
p.err("Non-call expression in tail call");
}
}
case (token.LET) {

View File

@ -3129,7 +3129,10 @@ fn trans_ret(@block_ctxt cx, &option.t[@ast.expr] e) -> result {
}
fn trans_be(@block_ctxt cx, @ast.expr e) -> result {
// FIXME: So this isn't actually a tail call
// FIXME: This should be a typestate precondition
check ast.is_call_expr(e);
// FIXME: Turn this into a real tail call once
// calling convention issues are settled
ret trans_ret(cx, some(e));
}

View File

@ -1720,18 +1720,12 @@ 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;
}
}
/* FIXME: prove instead of check */
check ast.is_call_expr(expr);
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 (ast.stmt_log(?expr)) {

View File

@ -7,4 +7,4 @@ fn f() -> int {
fn main() {
auto y = f();
}
}

View File

@ -10,4 +10,4 @@ fn g() -> uint {
fn main() {
auto y = f();
}
}