seqc/codegen/
error.rs

1//! Code generation error types.
2
3/// Error type for code generation operations.
4///
5/// This allows proper error propagation using `?` for both logical errors
6/// (invalid programs, missing definitions) and formatting errors (write failures).
7#[derive(Debug)]
8pub enum CodeGenError {
9    /// A logical error in code generation (e.g., missing word definition)
10    Logic(String),
11    /// A formatting error when writing IR
12    Format(std::fmt::Error),
13}
14
15impl std::fmt::Display for CodeGenError {
16    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
17        match self {
18            CodeGenError::Logic(s) => write!(f, "{}", s),
19            CodeGenError::Format(e) => write!(f, "IR generation error: {}", e),
20        }
21    }
22}
23
24impl std::error::Error for CodeGenError {}
25
26impl From<String> for CodeGenError {
27    fn from(s: String) -> Self {
28        CodeGenError::Logic(s)
29    }
30}
31
32impl From<std::fmt::Error> for CodeGenError {
33    fn from(e: std::fmt::Error) -> Self {
34        CodeGenError::Format(e)
35    }
36}