Be more explicit about AST types (#921)

This was born out of wanting FunctionDeclaration to explicitly have a Block for a body, and became a bit more of specifying types around. Note this forces exec_program to generate a Block for print()'s body, which is probably more correct as now we can expect a standard FunctionDeclaration AST structure, even for the built-ins.

There is a syntactic change here: a continuation's body is now a Block, not just a Statement. I've added an example disallowed test case. I think this is more reasonable syntax.

Other than that, note that optional_else now generates a valid Block. This has me thinking about whether we can eliminate Sequence, but that seemed well out of scope for this.
This commit is contained in:
Jon Meow
2021-10-28 13:54:45 -07:00
committed by GitHub
parent dea277d8e1
commit bbd4940e6d
11 changed files with 143 additions and 122 deletions
@@ -45,9 +45,9 @@ static void ResolveControlFlow(
return;
case Statement::Kind::If: {
auto& if_stmt = cast<If>(*statement);
ResolveControlFlow(&if_stmt.then_statement(), function, loop);
if (if_stmt.else_statement().has_value()) {
ResolveControlFlow(*if_stmt.else_statement(), function, loop);
ResolveControlFlow(&if_stmt.then_block(), function, loop);
if (if_stmt.else_block().has_value()) {
ResolveControlFlow(*if_stmt.else_block(), function, loop);
}
return;
}
@@ -61,8 +61,8 @@ static void ResolveControlFlow(
}
case Statement::Kind::Block: {
auto& block = cast<Block>(*statement);
if (block.statement().has_value()) {
ResolveControlFlow(*block.statement(), function, loop);
if (block.sequence().has_value()) {
ResolveControlFlow(*block.sequence(), function, loop);
}
return;
}