Extremely broken hacked-up incorrect attempt at 'ret'.
This commit is contained in:
@@ -705,6 +705,22 @@ io fn parse_stmt(parser p) -> @ast.stmt {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case (token.RET) {
|
||||||
|
p.bump();
|
||||||
|
alt (p.peek()) {
|
||||||
|
case (token.SEMI) {
|
||||||
|
p.bump();
|
||||||
|
ret @spanned(lo, p.get_span(),
|
||||||
|
ast.stmt_ret(none[@ast.expr]));
|
||||||
|
}
|
||||||
|
case (_) {
|
||||||
|
auto e = parse_expr(p);
|
||||||
|
expect(p, token.SEMI);
|
||||||
|
ret @spanned(lo, e.span,
|
||||||
|
ast.stmt_ret(some[@ast.expr](e)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
case (token.LET) {
|
case (token.LET) {
|
||||||
auto decl = parse_let(p);
|
auto decl = parse_let(p);
|
||||||
|
|||||||
@@ -811,6 +811,22 @@ fn trans_check_expr(@block_ctxt cx, &ast.expr e) -> result {
|
|||||||
ret res(next_cx, C_nil());
|
ret res(next_cx, C_nil());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn trans_ret(@block_ctxt cx, &option[@ast.expr] e) -> result {
|
||||||
|
auto r = res(cx, C_nil());
|
||||||
|
alt (e) {
|
||||||
|
case (some[@ast.expr](?x)) {
|
||||||
|
r = trans_expr(cx, *x);
|
||||||
|
r.bcx.build.Store(r.val, cx.fcx.lloutptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// FIXME: if we actually ret here, the block structure falls apart;
|
||||||
|
// need to do something more-clever with terminators and block cleanup.
|
||||||
|
// Mean time 'ret' means 'copy result to output slot and keep going'.
|
||||||
|
|
||||||
|
// r.val = r.bcx.build.RetVoid();
|
||||||
|
ret r;
|
||||||
|
}
|
||||||
|
|
||||||
fn trans_stmt(@block_ctxt cx, &ast.stmt s) -> result {
|
fn trans_stmt(@block_ctxt cx, &ast.stmt s) -> result {
|
||||||
auto sub = res(cx, C_nil());
|
auto sub = res(cx, C_nil());
|
||||||
alt (s.node) {
|
alt (s.node) {
|
||||||
@@ -822,6 +838,10 @@ fn trans_stmt(@block_ctxt cx, &ast.stmt s) -> result {
|
|||||||
sub.bcx = trans_check_expr(cx, *a).bcx;
|
sub.bcx = trans_check_expr(cx, *a).bcx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case (ast.stmt_ret(?e)) {
|
||||||
|
sub.bcx = trans_ret(cx, e).bcx;
|
||||||
|
}
|
||||||
|
|
||||||
case (ast.stmt_expr(?e)) {
|
case (ast.stmt_expr(?e)) {
|
||||||
sub.bcx = trans_expr(cx, *e).bcx;
|
sub.bcx = trans_expr(cx, *e).bcx;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user