Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust constr enum #1941

Merged
merged 20 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 32 additions & 12 deletions ast/src/analyzed/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ fn format_outer_function(e: &Expression, f: &mut Formatter<'_>) -> Result {
}
}

impl<Expr: Display> Display for SelectedExpressions<Expr> {
impl<T: Display> Display for SelectedExpressions<T> {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
write!(
f,
Expand All @@ -318,24 +318,44 @@ impl<Expr: Display> Display for SelectedExpressions<Expr> {
}
}

impl<T: Display> Display for Identity<SelectedExpressions<AlgebraicExpression<T>>> {
impl<T: Display> Display for PolynomialIdentity<T> {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
match self.kind {
IdentityKind::Polynomial => {
let (left, right) = self.as_polynomial_identity();
let right = right
.as_ref()
.map(|r| r.to_string())
.unwrap_or_else(|| "0".into());
match &self.expression {
AlgebraicExpression::BinaryOperation(AlgebraicBinaryOperation {
left,
op: AlgebraicBinaryOperator::Sub,
right,
}) => {
write!(f, "{left} = {right};")
}
IdentityKind::Plookup => write!(f, "{} in {};", self.left, self.right),
IdentityKind::Permutation => write!(f, "{} is {};", self.left, self.right),
IdentityKind::Connect => write!(f, "{} connect {};", self.left, self.right),
e => write!(f, "{e} = 0;"),
}
}
}

impl<T: Display> Display for LookupIdentity<T> {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
write!(f, "{} in {};", self.left, self.right)
}
}

impl<T: Display> Display for PermutationIdentity<T> {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
write!(f, "{} is {};", self.left, self.right)
}
}

impl<T: Display> Display for ConnectIdentity<T> {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
write!(
f,
"[{}] connect [{}];",
self.left.iter().format(", "),
self.right.iter().format(", ")
)
}
}

impl Display for Reference {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Expand Down
Loading