#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum ErrorCode {
E0001, E0002, E0003, E0004, E0005,
E0050, E0051, E0052,
E0100, E0101, E0102, E0103,
E0200, E0201,
W0001, W0002, W0003, W0004, W0005, }
impl ErrorCode {
pub fn as_str(&self) -> &'static str {
match self {
ErrorCode::E0001 => "E0001",
ErrorCode::E0002 => "E0002",
ErrorCode::E0003 => "E0003",
ErrorCode::E0004 => "E0004",
ErrorCode::E0005 => "E0005",
ErrorCode::E0050 => "E0050",
ErrorCode::E0051 => "E0051",
ErrorCode::E0052 => "E0052",
ErrorCode::E0100 => "E0100",
ErrorCode::E0101 => "E0101",
ErrorCode::E0102 => "E0102",
ErrorCode::E0103 => "E0103",
ErrorCode::E0200 => "E0200",
ErrorCode::E0201 => "E0201",
ErrorCode::W0001 => "W0001",
ErrorCode::W0002 => "W0002",
ErrorCode::W0003 => "W0003",
ErrorCode::W0004 => "W0004",
ErrorCode::W0005 => "W0005",
}
}
pub fn description(&self) -> &'static str {
match self {
ErrorCode::E0001 => "variable used before declaration",
ErrorCode::E0002 => "cannot reassign to const variable",
ErrorCode::E0003 => "type mismatch",
ErrorCode::E0004 => "wrong number of arguments",
ErrorCode::E0005 => "duplicate declaration in scope",
ErrorCode::E0050 => "syntax error",
ErrorCode::E0051 => "unexpected token",
ErrorCode::E0052 => "unclosed token",
ErrorCode::E0100 => "register limit exceeded",
ErrorCode::E0101 => "constant pool limit exceeded",
ErrorCode::E0102 => "jump offset overflow",
ErrorCode::E0103 => "bytecode verification failed",
ErrorCode::E0200 => "runtime error",
ErrorCode::E0201 => "assertion failed",
ErrorCode::W0001 => "unused variable",
ErrorCode::W0002 => "unused parameter",
ErrorCode::W0003 => "variable shadows outer declaration",
ErrorCode::W0004 => "unreachable code",
ErrorCode::W0005 => "redundant operation",
}
}
}
impl std::fmt::Display for ErrorCode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.as_str())
}
}