todo: arbitrary ir

This commit is contained in:
2023-12-03 17:32:37 -08:00
parent 93cac44a99
commit 2c2268925a
16 changed files with 298 additions and 163 deletions

View File

@@ -33,13 +33,12 @@
//! because the implementation of some parts of these primitives is really
//! awful to look at.
//!
mod env;
//mod env;
mod primop;
mod primtype;
mod value;
use cranelift_module::ModuleError;
pub use env::{EvalEnvironment, LookupError};
pub use primop::PrimOpError;
pub use primtype::PrimitiveType;
pub use value::Value;
@@ -56,11 +55,9 @@ use self::primtype::UnknownPrimType;
/// of converting those errors to strings and then seeing if they're the
/// same.
#[derive(Debug, thiserror::Error)]
pub enum EvalError {
pub enum EvalError<IR> {
#[error(transparent)]
Lookup(#[from] LookupError),
#[error(transparent)]
PrimOp(#[from] PrimOpError),
PrimOp(#[from] PrimOpError<IR>),
#[error(transparent)]
Backend(#[from] BackendError),
#[error("IO error: {0}")]
@@ -77,16 +74,17 @@ pub enum EvalError {
CastToFunction(String),
#[error(transparent)]
UnknownPrimType(#[from] UnknownPrimType),
#[error("Variable lookup failed for {1} at {0:?}")]
LookupFailed(crate::syntax::Location, String),
}
impl PartialEq<EvalError> for EvalError {
fn eq(&self, other: &Self) -> bool {
impl<IR1: Clone, IR2: Clone> PartialEq<EvalError<IR1>> for EvalError<IR2> {
fn eq(&self, other: &EvalError<IR1>) -> bool {
match self {
EvalError::Lookup(a) => match other {
EvalError::Lookup(b) => a == b,
EvalError::LookupFailed(a, b) => match other {
EvalError::LookupFailed(x, y) => a == x && b == y,
_ => false,
},
EvalError::PrimOp(a) => match other {
EvalError::PrimOp(b) => a == b,
_ => false,