First commit
CI / fmt (push) Has been cancelled
CI / clippy (push) Has been cancelled
CI / doc (push) Has been cancelled
CI / test macos-latest (push) Has been cancelled
CI / test windows-latest (push) Has been cancelled

This commit is contained in:
2026-08-08 11:02:48 +02:00
committed by surv
commit 86c507df21
17 changed files with 1059 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
use std::ops::{Add, Mul, Neg, Not, Sub};
use crate::binary_repr::BinaryRepr;
pub enum BinOp {
Plus,
Sub,
Mul,
Div,
}
pub enum UnaryOp {
Not,
Neg,
}
pub enum Expr {
Constant(BinaryRepr),
BinaryOp(Box<Self>, BinOp, Box<Self>),
UnaryOp(UnaryOp, Box<Self>),
Group(Box<Self>),
}
impl Expr {
pub fn into_binary_repr(self) -> BinaryRepr {
match self {
Self::Constant(binary_repr) => binary_repr,
Self::BinaryOp(expr, bin_op, expr1) => {
(match bin_op {
BinOp::Plus => <BinaryRepr as Add>::add,
BinOp::Sub => <BinaryRepr as Sub>::sub,
BinOp::Mul => <BinaryRepr as Mul>::mul,
BinOp::Div => todo!(),
})(expr.into_binary_repr(), expr1.into_binary_repr())
}
Self::UnaryOp(unary_op, expr) => (match unary_op {
UnaryOp::Neg => <BinaryRepr as Neg>::neg,
UnaryOp::Not => <BinaryRepr as Not>::not,
})(expr.into_binary_repr()),
Self::Group(group) => group.into_binary_repr(),
}
}
}