Start messing around with cranelift.

This commit is contained in:
2022-11-25 21:30:23 -08:00
parent a217e2633f
commit 22aa29cb92
12 changed files with 203 additions and 12 deletions

View File

@@ -21,6 +21,9 @@ pub enum Error {
#[error("Unbound variable '{0}'")]
UnboundVariable(Location, String),
#[error("Internal error: {0}")]
InternalError(Location, String),
}
fn locations_to_labels(start: &Location, end: &Location) -> Vec<Label<usize>> {
@@ -168,6 +171,17 @@ impl From<Error> for Diagnostic<usize> {
])
.with_message(format!("Unbound variable '{}'", name)),
},
Error::InternalError(location, string) => match location {
Location::Manufactured => {
Diagnostic::error().with_message(format!("Internal error: {}", string))
}
Location::InFile(file_id, offset) => Diagnostic::error()
.with_labels(vec![
Label::primary(*file_id, *offset..*offset).with_message("this is related")
])
.with_message(format!("Internal error: {}", string)),
}
}
}
}