Working constructor and statements

This commit is contained in:
2026-05-21 14:19:32 +02:00
parent f2257a4e81
commit 80ff10503a
3 changed files with 18 additions and 9 deletions
+2 -1
View File
@@ -87,6 +87,7 @@ impl GenRust for Expression {
} => {
cg.add(&prefixes.get_rust());
initial.gen_rust(ctx, cg);
cg.add(&Some(prefixes).get_rust());
for postfix in postfixes {
postfix.gen_rust(ctx, cg);
}
@@ -126,7 +127,7 @@ impl GetRust for Vec<Prefix> {
}
}
impl GetRust for Option<Vec<Prefix>> {
impl GetRust for Option<&Vec<Prefix>> {
fn get_rust(&self) -> String {
if let Some(prefixes) = self {
prefixes
+1 -1
View File
@@ -7,6 +7,7 @@ use crate::{GenRust, GetRust, RustCodegen};
impl GenRust for Block {
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
for stmt in &self.0 {
ctx.expr_ensure_semicolon = true;
cg.add_indented("");
stmt.gen_rust(ctx, cg);
}
@@ -14,7 +15,6 @@ impl GenRust for Block {
if let Some(soft_return) = &self.1 {
ctx.expr_ensure_semicolon = false;
soft_return.gen_rust(ctx, cg);
ctx.expr_ensure_semicolon = true;
}
}
}
+15 -7
View File
@@ -197,7 +197,7 @@ impl GenRust for (&Vec<Spanned<FieldDeclStmt>>, &ClassConstructor) {
}
}
cg.add_indentedln(&format!("this.construct_class("));
cg.add_indentedln(&format!("this.constructor("));
for (i, param) in self.1.params.0.iter().enumerate() {
if i > 0 {
@@ -207,22 +207,30 @@ impl GenRust for (&Vec<Spanned<FieldDeclStmt>>, &ClassConstructor) {
param.name.gen_rust(ctx, cg);
}
cg.add(")");
cg.add(");");
cg.add_indentedln("this");
cg.indent -= 1;
cg.add_indentedln("}\n");
let mut constructor_params = vec![VarDecl {
mutable: false,
name: Pattern::Id(Identifier(String::from("self"))),
type_: Some(TypeExpr(
TypeExprKind::Path(Path(vec![Identifier(String::from("Self"))])),
vec![TypePostfix::RefMut],
)),
}];
constructor_params.append(&mut self.1.params.0.clone());
FunctionDecl {
visibility: self.1.visibility.clone(),
name: Identifier(String::from("constructor")),
generics: self.1.generics.clone(),
params: self.1.params.clone(),
return_type: TypeExpr(
TypeExprKind::Path(Path(vec![Identifier(String::from("Self"))])),
Vec::new(),
),
params: ParamList(constructor_params),
return_type: TypeExpr::no_px(TypeExprKind::Tuple(Vec::new())),
body: Some(self.1.body.clone()),
}
.gen_rust(ctx, cg);