plotnik_compiler/compile/
error.rs

1//! Compilation error types and results.
2
3use indexmap::IndexMap;
4
5use crate::analyze::type_check::DefId;
6use crate::bytecode::{InstructionIR, Label};
7
8/// Error during compilation.
9#[derive(Clone, Debug)]
10pub enum CompileError {
11    /// Definition not found in symbol table.
12    DefinitionNotFound(String),
13    /// Expression body missing.
14    MissingBody(String),
15}
16
17impl std::fmt::Display for CompileError {
18    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19        match self {
20            Self::DefinitionNotFound(name) => write!(f, "definition not found: {name}"),
21            Self::MissingBody(name) => write!(f, "missing body for definition: {name}"),
22        }
23    }
24}
25
26impl std::error::Error for CompileError {}
27
28/// Result of compilation.
29#[derive(Clone, Debug)]
30pub struct CompileResult {
31    /// All generated instructions.
32    pub instructions: Vec<InstructionIR>,
33    /// Entry labels for each definition (in definition order).
34    pub def_entries: IndexMap<DefId, Label>,
35    /// Entry label for the universal preamble.
36    /// The preamble wraps any entrypoint: Obj -> Trampoline -> EndObj -> Return
37    pub preamble_entry: Label,
38}