stak_compiler/
error.rs

1use core::{
2    error,
3    fmt::{self, Display, Formatter},
4};
5use stak_r7rs::SmallError;
6
7/// A compile error.
8#[derive(Clone, Debug, Eq, PartialEq)]
9pub enum CompileError {
10    /// A run error.
11    Run(SmallError),
12    /// A user error.
13    User(String),
14    /// A virtual machine error.
15    Vm(stak_vm::Error),
16}
17
18impl error::Error for CompileError {}
19
20impl Display for CompileError {
21    fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
22        match self {
23            Self::Run(error) => write!(formatter, "{error}"),
24            Self::User(error) => write!(formatter, "{error}"),
25            Self::Vm(error) => write!(formatter, "{error}"),
26        }
27    }
28}
29
30impl From<SmallError> for CompileError {
31    fn from(error: SmallError) -> Self {
32        Self::Run(error)
33    }
34}
35
36impl From<stak_vm::Error> for CompileError {
37    fn from(error: stak_vm::Error) -> Self {
38        Self::Vm(error)
39    }
40}