use std::fmt;
#[derive(Debug, PartialEq)]
pub enum DefineFunctionError {
NameInUse,
FunctionLimitReached,
}
impl fmt::Display for DefineFunctionError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
DefineFunctionError::NameInUse => write!(f, "Function name is already in use"),
DefineFunctionError::FunctionLimitReached => write!(
f,
"The maximum number of functions have already been defined"
),
}
}
}
impl std::error::Error for DefineFunctionError {}
#[derive(Debug, PartialEq)]
pub enum RunError {
Scan,
ResolveFunctions,
Parse,
Compile,
Runtime,
}
impl fmt::Display for RunError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use RunError::*;
match self {
Scan => write!(f, "Could not scan code"),
ResolveFunctions => write!(f, "Could not resolve functions"),
Parse => write!(f, "Could not parse into tokens"),
Compile => write!(f, "Could not compile tokens into bytecode"),
Runtime => write!(f, "Could not execute bytecode"),
}
}
}
impl std::error::Error for RunError {}
#[derive(Debug, PartialEq)]
pub enum CallFunctionError {
ArityMismatch,
Runtime,
NotFound,
}
impl fmt::Display for CallFunctionError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use CallFunctionError::*;
match self {
ArityMismatch => write!(f, "Provided the wrong number of arguments"),
Runtime => write!(f, "Could not execute bytecode"),
NotFound => write!(f, "Could not find function by name"),
}
}
}
impl std::error::Error for CallFunctionError {}