Top level as statement #103

This commit is contained in:
2026-07-02 06:25:44 +02:00
parent 9021da224e
commit 68cf239f92
7 changed files with 21 additions and 2 deletions
+1
View File
@@ -33,6 +33,7 @@ impl GenMist for Statement {
cg.add("unsafe ");
block.gen_mist(ctx, cg);
}
Statement::TopLevel(tl) => tl.gen_mist(ctx, cg),
Statement::Block(block) => block.gen_mist(ctx, cg),
Statement::VarDecl(VarDeclStmt { decl, init }) => {
if decl.type_.is_some() {
+3 -2
View File
@@ -31,13 +31,14 @@ impl GenRust for Block {
impl GenRust for Statement {
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
match self {
Statement::TopLevel(tl) => tl.gen_rust(ctx, cg),
Statement::Block(block) => block.gen_rust(ctx, cg),
Statement::UnsafeBlock(block) => {
cg.add("unsafe ");
block.gen_rust(ctx, cg);
}
Statement::Block(block) => block.gen_rust(ctx, cg),
Statement::VarDecl(VarDeclStmt { decl, init }) => {
cg.add("let ");
decl.gen_rust(ctx, cg);
+12
View File
@@ -119,3 +119,15 @@ impl From<Path> for ExprPath {
)
}
}
impl Expression {
pub fn is_semicolon_required(&self) -> bool {
match self {
Self::Statement(v) => match &**v {
Statement::TopLevel(_) => false,
_ => true,
},
_ => true,
}
}
}
+1
View File
@@ -12,6 +12,7 @@ pub struct Block {
pub enum Statement {
UnsafeBlock(Block),
Block(Block),
TopLevel(Box<TopLevel>),
If {
initial: StatementBranch,
else_if: Vec<StatementBranch>,
+2
View File
@@ -24,6 +24,7 @@ keyword = {
| "class"
| "trait"
| "impl"
| "use"
| "pub"
| "mut"
| "let"
@@ -389,6 +390,7 @@ statement_list = {
statement = _{
control_flow
| (expr ~ semicolon)
| top_level
}
// ------------------------------------------------------
+1
View File
@@ -129,6 +129,7 @@ impl GetMutability for Block {
impl GetMutability for Statement {
fn get_mutability(&self) -> Vec<Identifier> {
match self {
Statement::TopLevel(_) => Vec::new(),
Statement::Block(body) | Statement::UnsafeBlock(body) => body.get_mutability(),
Statement::If {
initial,
+1
View File
@@ -1,5 +1,6 @@
void main()
{
use std::fmt;
println!("running common tests...");
common::test_package();
common::expr_test::run_tests();