// rasm-core/src/isa/err.rs
//
//! Модель ошибки для этого модуля.
use std::fmt::Display;

/// Виды ошибок.
#[derive(Debug, Clone)]
pub enum ISAErrorKind {
    /// Неизвестная мнемоника
    UnknownMnemonic(String),

    /// Неизвестный регистр
    UnknownRegister(String),

    /// Неизвестный тип данных
    UnknownDataType(String),

    /// Неизвестная директива
    UnknownDirective(String),
}

impl Display for ISAErrorKind {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match &self {
            Self::UnknownMnemonic(maybe_the_problem) => {
                write!(f, "unknown mnemonic: '{maybe_the_problem}'")
            }
            Self::UnknownRegister(the_problem) => write!(f, "unknown register: '{the_problem}'"),
            Self::UnknownDataType(unknown) => write!(f, "unknown data type: '{unknown}'"),
            Self::UnknownDirective(unknown) => write!(f, "unknown directive: '{unknown}'"),
        }
    }
}

#[derive(Debug)]
pub struct ISAError {
    pub kind: ISAErrorKind,
}

impl ISAError {
    pub fn new(kind: ISAErrorKind) -> Self {
        Self { kind }
    }
}

impl Display for ISAError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.kind)
    }
}
