Function types
This commit is contained in:
@@ -200,10 +200,39 @@ impl GetMist for TypeExpr {
|
||||
Self::Dyn(ty) => {
|
||||
format!("dyn {}", ty.get_mist())
|
||||
}
|
||||
Self::Fn {
|
||||
kind,
|
||||
return_type,
|
||||
params,
|
||||
} => {
|
||||
format!(
|
||||
"{} {}({})",
|
||||
return_type.get_mist(),
|
||||
kind.get_mist(),
|
||||
params
|
||||
.iter()
|
||||
.map(TypeExpr::get_mist)
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl GetMist for FnKind {
|
||||
fn get_mist(&self) -> String {
|
||||
match self {
|
||||
Self::Fn => "fn",
|
||||
Self::UnsafeFn => "unsafe fn",
|
||||
Self::FnClosure => "Fn",
|
||||
Self::FnMut => "FnMut",
|
||||
Self::FnOnce => "FnOnce",
|
||||
}
|
||||
.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl GetMist for ExprPath {
|
||||
fn get_mist(&self) -> String {
|
||||
self.0
|
||||
|
||||
@@ -239,7 +239,6 @@ impl GetRust for TypeExpr {
|
||||
Self::UnsafePtr { mutable, ty } => {
|
||||
let mutable = if *mutable { "mut " } else { "const " };
|
||||
format!("*{mutable}{}", ty.get_rust())
|
||||
|
||||
}
|
||||
|
||||
Self::Ref {
|
||||
@@ -262,10 +261,40 @@ impl GetRust for TypeExpr {
|
||||
Self::Dyn(ty) => {
|
||||
format!("dyn {}", ty.get_rust())
|
||||
}
|
||||
|
||||
Self::Fn {
|
||||
kind,
|
||||
return_type,
|
||||
params,
|
||||
} => {
|
||||
format!(
|
||||
"{} -> {}({})",
|
||||
kind.get_rust(),
|
||||
return_type.get_rust(),
|
||||
params
|
||||
.iter()
|
||||
.map(TypeExpr::get_rust)
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl GetRust for FnKind {
|
||||
fn get_rust(&self) -> String {
|
||||
match self {
|
||||
Self::Fn => "fn",
|
||||
Self::UnsafeFn => "unsafe fn",
|
||||
Self::FnClosure => "Fn",
|
||||
Self::FnMut => "FnMut",
|
||||
Self::FnOnce => "FnOnce",
|
||||
}
|
||||
.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl GenRust for Pattern {
|
||||
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
|
||||
match self {
|
||||
|
||||
Reference in New Issue
Block a user