Fixed constructor args #60
This commit is contained in:
@@ -38,7 +38,11 @@ impl GenRust for Literal {
|
||||
Self::Tuple(values) => {
|
||||
cg.add("(");
|
||||
|
||||
for val in values {
|
||||
for (i, val) in values.iter().enumerate() {
|
||||
if i > 0 {
|
||||
cg.add(", ");
|
||||
}
|
||||
|
||||
val.gen_rust(ctx, cg);
|
||||
}
|
||||
|
||||
|
||||
@@ -196,12 +196,21 @@ impl GenRust for (&Vec<Spanned<FieldDeclStmt>>, &Spanned<ClassConstructor>) {
|
||||
|
||||
cg.add_indented(&format!("this.constructor("));
|
||||
|
||||
for (i, param) in self.1.item.params.0.iter().enumerate() {
|
||||
for (i, param) in self
|
||||
.1
|
||||
.item
|
||||
.params
|
||||
.0
|
||||
.iter()
|
||||
.map(|v| expr_pattern(&v.name))
|
||||
.enumerate()
|
||||
{
|
||||
if i > 0 {
|
||||
cg.add(", ");
|
||||
}
|
||||
|
||||
param.name.gen_rust(ctx, cg);
|
||||
ctx.expr_ensure_semicolon = false;
|
||||
param.gen_rust(ctx, cg);
|
||||
}
|
||||
|
||||
cg.addln(");");
|
||||
@@ -237,6 +246,24 @@ impl GenRust for (&Vec<Spanned<FieldDeclStmt>>, &Spanned<ClassConstructor>) {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expr_pattern(pat: &Pattern) -> Expression {
|
||||
match pat {
|
||||
Pattern::Literal(v) => Expression::Literal(v.clone()),
|
||||
Pattern::Path(_, v) => Expression::Path(v.clone().into()),
|
||||
Pattern::Tuple(items) => Expression::Literal(Literal::Tuple(
|
||||
items.iter().map(|v| expr_pattern(&v)).collect(),
|
||||
)),
|
||||
Pattern::NamedTuple(path, items) => Expression::Fix {
|
||||
initial: Box::new(Expression::Path(path.clone().into())),
|
||||
prefixes: Vec::new(),
|
||||
postfixes: vec![Postfix::Call(
|
||||
items.iter().map(|v| expr_pattern(&v)).collect(),
|
||||
)],
|
||||
},
|
||||
Pattern::Struct(_, _) => unimplemented!(),
|
||||
}
|
||||
}
|
||||
|
||||
impl GenRust for TopLevelKind {
|
||||
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
|
||||
match self {
|
||||
|
||||
@@ -100,3 +100,17 @@ impl Expression {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Path> for ExprPath {
|
||||
fn from(path: Path) -> Self {
|
||||
Self(
|
||||
path.0
|
||||
.into_iter()
|
||||
.map(|v| ExprPathSegment {
|
||||
ident: v,
|
||||
generics: None,
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user