cl-ast: Remove Param, replace with flat Pattern
This commit is contained in:
@@ -145,17 +145,10 @@ pub enum ModuleKind {
|
||||
pub struct Function {
|
||||
pub name: Sym,
|
||||
pub sign: TyFn,
|
||||
pub bind: Vec<Param>,
|
||||
pub bind: Vec<Pattern>,
|
||||
pub body: Option<Expr>,
|
||||
}
|
||||
|
||||
/// A single parameter for a [Function]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct Param {
|
||||
pub mutability: Mutability,
|
||||
pub bind: Pattern,
|
||||
}
|
||||
|
||||
/// A user-defined product type
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct Struct {
|
||||
|
||||
@@ -192,13 +192,6 @@ mod display {
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Param {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let Self { mutability, bind } = self;
|
||||
write!(f, "{mutability}{bind}")
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Struct {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let Self { name, kind } = self;
|
||||
|
||||
@@ -106,14 +106,10 @@ pub trait Fold {
|
||||
Function {
|
||||
name: self.fold_sym(name),
|
||||
sign: self.fold_ty_fn(sign),
|
||||
bind: bind.into_iter().map(|p| self.fold_param(p)).collect(),
|
||||
bind: bind.into_iter().map(|p| self.fold_pattern(p)).collect(),
|
||||
body: body.map(|b| self.fold_expr(b)),
|
||||
}
|
||||
}
|
||||
fn fold_param(&mut self, p: Param) -> Param {
|
||||
let Param { mutability, bind } = p;
|
||||
Param { mutability: self.fold_mutability(mutability), bind: self.fold_pattern(bind) }
|
||||
}
|
||||
fn fold_struct(&mut self, s: Struct) -> Struct {
|
||||
let Struct { name, kind } = s;
|
||||
Struct { name: self.fold_sym(name), kind: self.fold_struct_kind(kind) }
|
||||
|
||||
@@ -83,16 +83,11 @@ pub trait Visit<'a>: Sized {
|
||||
let Function { name, sign, bind, body } = f;
|
||||
self.visit_sym(name);
|
||||
self.visit_ty_fn(sign);
|
||||
bind.iter().for_each(|p| self.visit_param(p));
|
||||
bind.iter().for_each(|p| self.visit_pattern(p));
|
||||
if let Some(b) = body {
|
||||
self.visit_expr(b)
|
||||
}
|
||||
}
|
||||
fn visit_param(&mut self, p: &'a Param) {
|
||||
let Param { mutability, bind } = p;
|
||||
self.visit_mutability(mutability);
|
||||
self.visit_pattern(bind);
|
||||
}
|
||||
fn visit_struct(&mut self, s: &'a Struct) {
|
||||
let Struct { name, kind } = s;
|
||||
self.visit_sym(name);
|
||||
|
||||
Reference in New Issue
Block a user