diff --git a/codegen/src/expr.rs b/codegen/src/expr.rs index a0e2b10..ec21e89 100644 --- a/codegen/src/expr.rs +++ b/codegen/src/expr.rs @@ -68,6 +68,14 @@ impl GenRust for Literal { impl GenRust for Expression { fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) { + let ensure_semicolon = if ctx.expr_ensure_semicolon { + ctx.expr_ensure_semicolon = false; + + true + } else { + false + }; + match self { Expression::Path(path) => cg.add(&path.get_rust()), Expression::Literal(literal) => literal.gen_rust(ctx, cg), @@ -90,6 +98,11 @@ impl GenRust for Expression { rhs.gen_rust(ctx, cg); } } + + if ensure_semicolon { + ctx.expr_ensure_semicolon = true; + cg.add(";"); + } } } @@ -175,6 +188,8 @@ impl GenRust for Postfix { expr.gen_rust(ctx, cg); cg.add(","); } + + cg.add("}"); } Postfix::Index(idx) => { diff --git a/codegen/src/top_level.rs b/codegen/src/top_level.rs index 54bb444..af80bbc 100644 --- a/codegen/src/top_level.rs +++ b/codegen/src/top_level.rs @@ -92,7 +92,7 @@ impl GenRust for FunctionDecl { cg.add(&self.return_type.get_rust()); if let Some(body) = &self.body { - cg.add_indentedln("{\n"); + cg.add_indentedln(" {\n"); cg.indent += 1; body.gen_rust(ctx, cg); cg.indent -= 1; @@ -363,9 +363,6 @@ impl GenRust for TopLevelKind { (fields, &constructor.item).gen_rust(ctx, cg); - cg.indent -= 1; - cg.add_indentedln("}\n"); - for item in items.clone() { match item { ClassItem::ImplDecl(_) => {} diff --git a/mist-test/src/task.mist b/mist-test/src/task.mist index d902258..a90f9e3 100644 --- a/mist-test/src/task.mist +++ b/mist-test/src/task.mist @@ -12,9 +12,9 @@ pub struct Task { } pub Task create_task(str* name) { - return Task { + Task { name: name.to_string(), state: TaskState::Pending, executions: 0, - }; + } } \ No newline at end of file