Add support for return; (#678)

This creates a ReturnExpression. A separate change should enforce that an implicit return of `()` is only allowed in functions that have an implicit return type of `()`, and I think the structure taken here should ease that.
This commit is contained in:
Jon Meow
2021-08-02 16:30:08 -07:00
committed by GitHub
parent b1993a6cd0
commit 6ae9cc3cf8
16 changed files with 114 additions and 33 deletions
@@ -1093,8 +1093,9 @@ void StepStmt() {
Stack<Scope*> scopes;
scopes.Push(scope);
Stack<Action*> todo;
todo.Push(Action::MakeStatementAction(Statement::MakeReturn(
stmt->line_num, Expression::MakeTupleLiteral(stmt->line_num, {}))));
todo.Push(Action::MakeStatementAction(
Statement::MakeReturn(stmt->line_num, nullptr,
/*is_omitted_exp=*/true)));
todo.Push(Action::MakeStatementAction(stmt->GetContinuation().body));
Frame* continuation_frame =
global_arena->New<Frame>("__continuation", scopes, todo);