cl-ast: Add inline closure expressions
This commit is contained in:
@@ -51,6 +51,7 @@ impl_from! {
|
||||
}
|
||||
impl From for ExprKind {
|
||||
Let => ExprKind::Let,
|
||||
Closure => ExprKind::Closure,
|
||||
Quote => ExprKind::Quote,
|
||||
Match => ExprKind::Match,
|
||||
Assign => ExprKind::Assign,
|
||||
|
||||
@@ -402,6 +402,7 @@ impl Display for ExprKind {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
ExprKind::Empty => "()".fmt(f),
|
||||
ExprKind::Closure(v) => v.fmt(f),
|
||||
ExprKind::Quote(v) => v.fmt(f),
|
||||
ExprKind::Let(v) => v.fmt(f),
|
||||
ExprKind::Match(v) => v.fmt(f),
|
||||
@@ -431,6 +432,17 @@ impl Display for ExprKind {
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Closure {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let Self { arg, body } = self;
|
||||
match arg.as_ref() {
|
||||
Pattern::Tuple(args) => separate(args, ", ")(f.delimit_with("|", "|")),
|
||||
_ => arg.fmt(f),
|
||||
}?;
|
||||
write!(f, " {body}")
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Quote {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let Self { quote } = self;
|
||||
|
||||
@@ -283,6 +283,7 @@ impl WeightOf for ExprKind {
|
||||
fn weight_of(&self) -> usize {
|
||||
match self {
|
||||
ExprKind::Empty => size_of_val(self),
|
||||
ExprKind::Closure(v) => v.weight_of(),
|
||||
ExprKind::Quote(v) => v.weight_of(),
|
||||
ExprKind::Let(v) => v.weight_of(),
|
||||
ExprKind::Match(v) => v.weight_of(),
|
||||
@@ -312,6 +313,13 @@ impl WeightOf for ExprKind {
|
||||
}
|
||||
}
|
||||
|
||||
impl WeightOf for Closure {
|
||||
fn weight_of(&self) -> usize {
|
||||
let Self { arg, body } = self;
|
||||
arg.weight_of() + body.weight_of()
|
||||
}
|
||||
}
|
||||
|
||||
impl WeightOf for Quote {
|
||||
fn weight_of(&self) -> usize {
|
||||
let Self { quote } = self;
|
||||
|
||||
Reference in New Issue
Block a user