1use thiserror::Error;
2use cranelift_module::ModuleError;
3
4#[derive(Debug, Clone, PartialEq)]
5pub struct Location {
6 pub line: usize,
7 pub column: usize,
8 pub line_text: String,
9}
10
11impl Location {
12 pub fn caret(&self) -> String {
13 format!("{}^", " ".repeat(self.column))
14 }
15}
16
17#[derive(Error, Debug)]
18pub enum LasmError {
19 #[error("Parse error: {message}")]
20 Parse {
21 message: String,
22 location: Location,
23 },
24 #[error("Type error: {0}")]
25 Type(String),
26 #[error("Compile error: {message}")]
27 Compile {
28 message: String,
29 location: Option<Location>,
30 },
31 #[error("Runtime error: {0}")]
32 Runtime(String),
33 #[error("IO error: {0}")]
34 Io(#[from] std::io::Error),
35 #[error("Cranelift error: {0}")]
36 Cranelift(String),
37 #[error("Module error: {0}")]
38 Module(#[from] ModuleError),
39}
40