diff options
Diffstat (limited to 'src/comp/middle')
| -rw-r--r-- | src/comp/middle/trans.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index cc1af53f..b80ddbea 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -811,6 +811,22 @@ fn trans_check_expr(@block_ctxt cx, &ast.expr e) -> result { 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 { auto sub = res(cx, C_nil()); 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; } + case (ast.stmt_ret(?e)) { + sub.bcx = trans_ret(cx, e).bcx; + } + case (ast.stmt_expr(?e)) { sub.bcx = trans_expr(cx, *e).bcx; } |