#![coverage(off)]

use crate::{compile::syntax::ParseError, vm::value::IdentifierValue};

#[derive(Debug, PartialEq, thiserror::Error)]
pub enum CompileError {
    #[error("parse error: {0:?}")]
    Parse(Vec<ParseError>),
    #[error("block has too many local variables")]
    TooManyLocals,
    #[error("module has too many constants")]
    TooManyConstants,
    #[error("function call has too many arguments")]
    TooManyArgumentsInCall,
    #[error("(break) used outside of a loop")]
    BreakOutsideOfLoop,
    #[error("(continue) used outside of a loop")]
    ContinueOutsideOfLoop,
    #[error("cannot emit branch instruction from {0} to {1}")]
    CannotEmitBranch(usize, usize),
    #[error("undefined local value reference: {0}")]
    UndefinedLocalReference(IdentifierValue),
}

impl From<Vec<ParseError>> for CompileError {
    fn from(value: Vec<ParseError>) -> Self {
        Self::Parse(value)
    }
}
