1use thiserror::Error;
2
3#[cfg(feature = "llvm")]
4use inkwell::error::Error as InkwellError;
5#[cfg(feature = "cranelift")]
6use cranelift_module::ModuleError;
7
8#[derive(Debug, Clone, PartialEq)]
10pub struct Location {
11 pub line: usize,
12 pub column: usize,
13 pub line_text: String,
14}
15
16impl Location {
17 pub fn caret(&self) -> String {
19 format!("{}^", " ".repeat(self.column))
20 }
21}
22
23#[derive(Error, Debug)]
25pub enum LasmError {
26 #[error("Parse error: {message}")]
28 Parse {
29 message: String,
30 location: Location,
31 },
32 #[error("Type error: {0}")]
34 Type(String),
35 #[error("Compile error: {message}")]
37 Compile {
38 message: String,
39 location: Option<Location>,
40 },
41 #[error("Runtime error: {0}")]
43 Runtime(String),
44 #[error("IO error: {0}")]
46 Io(#[from] std::io::Error),
47 #[cfg(feature = "llvm")]
49 #[error("LLVM error: {0}")]
50 LLVM(#[from] InkwellError),
51 #[cfg(feature = "cranelift")]
53 #[error("Module error: {0}")]
54 Module(#[from] ModuleError),
55}