macro_rules! impl_from {
($on:ty, $from:ty, $variant:ident) => {
impl From<$from> for $on {
fn from(value: $from) -> Self {
Self::$variant(value.into())
}
}
};
}
#[cfg(feature = "tracing")]
#[macro_use]
extern crate tracing;
#[cfg(not(feature = "tracing"))]
#[macro_use]
mod mock_tracing;
#[macro_use]
pub mod runtime;
pub mod compiler;
pub mod vm;
#[cfg(test)]
mod tests;
use compiler::syntax::Ranged;
pub use refuse;
use refuse::Trace;
use vm::ExecutionError;
pub trait ErrorKind {
fn kind(&self) -> &'static str;
}
#[derive(Debug, Clone, PartialEq)]
pub enum Error {
Compilation(Vec<Ranged<compiler::Error>>),
Execution(vm::ExecutionError),
}
impl From<Vec<Ranged<compiler::Error>>> for Error {
fn from(value: Vec<Ranged<compiler::Error>>) -> Self {
Self::Compilation(value)
}
}
impl From<vm::ExecutionError> for Error {
fn from(value: vm::ExecutionError) -> Self {
Self::Execution(value)
}
}
impl Trace for Error {
const MAY_CONTAIN_REFERENCES: bool = true;
fn trace(&self, tracer: &mut refuse::Tracer) {
if let Error::Execution(ExecutionError::Exception(exc)) = self {
exc.trace(tracer);
}
}
}