pub mod eval;
#[cfg(test)]
pub mod monomorphic;
pub mod naive;
#[cfg(test)]
pub mod typed_eval;
use crate::{
map_layer::MapLayer,
recursive_tree::{arena_eval::ArenaIndex, stack_machine_eval::StackMarker, RecursiveTree},
};
#[derive(Debug, Clone, Copy)]
pub enum Expr<A> {
Add(A, A),
Sub(A, A),
Mul(A, A),
LiteralInt(i64),
}
impl<A, B> MapLayer<B> for Expr<A> {
type To = Expr<B>;
type Unwrapped = A;
#[inline(always)]
fn map_layer<F: FnMut(Self::Unwrapped) -> B>(self, mut f: F) -> Self::To {
match self {
Expr::Add(a, b) => Expr::Add(f(a), f(b)),
Expr::Sub(a, b) => Expr::Sub(f(a), f(b)),
Expr::Mul(a, b) => Expr::Mul(f(a), f(b)),
Expr::LiteralInt(x) => Expr::LiteralInt(x),
}
}
}
impl<'a, A: Copy, B: 'a> MapLayer<B> for &'a Expr<A> {
type To = Expr<B>;
type Unwrapped = A;
#[inline(always)]
fn map_layer<F: FnMut(Self::Unwrapped) -> B>(self, mut f: F) -> Self::To {
match self {
Expr::Add(a, b) => Expr::Add(f(*a), f(*b)),
Expr::Sub(a, b) => Expr::Sub(f(*a), f(*b)),
Expr::Mul(a, b) => Expr::Mul(f(*a), f(*b)),
Expr::LiteralInt(x) => Expr::LiteralInt(*x),
}
}
}
pub type DFSStackExpr = RecursiveTree<Expr<StackMarker>, StackMarker>;
pub type BlocAllocExpr = RecursiveTree<Expr<ArenaIndex>, ArenaIndex>;