assembler: we failing DSA with this one

This commit is contained in:
2025-06-25 14:31:53 +01:00
parent 9232f2ccab
commit 20a7d42adb
14 changed files with 508 additions and 38 deletions
+44 -10
View File
@@ -3,7 +3,7 @@
use std::fmt::{Debug, Display};
use crate::source::source_info::SourceInfo;
use crate::source::{source_info::SourceInfo, tokeniser::error::TokeniserError};
/// An error that may occur during the assembly of a set of source files.
#[derive(Debug)]
@@ -13,26 +13,38 @@ pub struct AssembleError {
source_info: Option<SourceInfo>,
/// The type of assembly error that occurred.
kind: AssembleErrorKind,
/// The formatter to handle printing the error.
formatter: Box<dyn ErrorFormatter>,
}
impl AssembleError {
pub fn new_source_error(source_info: SourceInfo, kind: AssembleErrorKind) -> Self {
#[must_use]
pub const fn new_source_error(
source_info: SourceInfo,
kind: AssembleErrorKind,
) -> Self {
Self {
source_info: Some(source_info),
kind,
formatter,
}
}
pub fn new_other_error(kind: AssembleErrorKind) {}
#[must_use]
pub const fn new_other_error(kind: AssembleErrorKind) -> Self {
Self {
source_info: None,
kind,
}
}
}
impl Display for AssembleError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.formatter
.write(f, self.source_info.as_ref(), &self.kind)
if let Some(info) = &self.source_info {
write!(f, "at {info}")?;
}
write!(f, "{}", self.kind)?;
Ok(())
}
}
@@ -42,7 +54,29 @@ impl std::error::Error for AssembleError {}
/// Different types of errors that may occur when assembling a set of input source files.
#[non_exhaustive]
#[derive(Debug)]
pub enum AssembleErrorKind {}
pub enum AssembleErrorKind {
/// Usually unexpected I/O errors. Not normally recoverable.
IO(std::io::Error),
/// Errors emitted from the [`Tokeniser`].
Tokenise(TokeniserError),
}
impl Display for AssembleErrorKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Tokenise(why) => write!(f, "tokeniser error: {why}"),
_ => write!(
f,
"unhandled error type in Display implementation! See error.rs!"
),
}
}
}
impl From<std::io::Error> for AssembleErrorKind {
fn from(err: std::io::Error) -> Self {
Self::IO(err)
}
}
pub mod conversions;
pub mod formatters;