Files
binocle/src/expr.rs
T
surv 86c507df21
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
First commit
2026-08-08 11:02:48 +02:00

44 lines
1.1 KiB
Rust

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(),
}
}
}