Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Document the rest of the errors and warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
bellinitte committed Jun 13, 2021
1 parent 67a9d8c commit fcbd239
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 3 deletions.
98 changes: 98 additions & 0 deletions src/anomalies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,30 @@ pub enum Warning {
/// Span of the instruction mode character defined for the first time.
other_span: Range<usize>,
},
/// This warning gets reported when a macro is never used.
///
/// # Example
///
/// ```uxntal
/// %macro { #0001 }
/// ```
MacroUnused {
/// Name of the unused macro.
name: String,
/// Span of the macro definition.
span: Range<usize>,
},
/// This warning gets reported when a label is never used.
///
/// # Example
///
/// ```uxntal
/// @label
/// ```
LabelUnused {
/// Name of the unused label.
name: String,
/// Span of the label definition.
span: Range<usize>,
},
}
Expand Down Expand Up @@ -402,42 +420,122 @@ pub enum Error {
/// Span of the opening bracket with no matching closing bracket.
span: Range<usize>,
},
/// This error wraps an error that has been reported from a macro definition.
///
/// # Example
///
/// ```uxntal
/// %macro { #001 }
/// macro
/// ```
MacroError {
/// The error that has been reported from a macro definition.
original_error: Box<Error>,
/// Span of the macro invocation.
span: Range<usize>,
},
/// This error gets reported during an attempt to reference a sublabel, when
/// no previous label has been defined.
///
/// # Example
///
/// ```uxntal
/// .&sublabel
/// ```
SublabelReferencedWithoutScope {
/// Name of the sublabel.
name: String,
/// Span of the sublabel reference.
span: Range<usize>,
},
/// This error gets reported during an attempt to reference a label that
/// has not been defined.
///
/// # Example
///
/// ```uxntal
/// .label
/// ```
LabelUndefined {
/// Name of the label.
name: String,
/// Span of the label reference.
span: Range<usize>,
},
/// This error gets reported during an attempt to reference a non-zero-page label
/// after a literal zero-page address rune.
///
/// # Example
///
/// ```uxntal
/// |0100 @label
/// .label
/// ```
AddressNotZeroPage {
/// The actuall address that is not zero-page.
address: u16,
/// Name of the identifier that is referenced by the literal zero-page address.
identifier: String,
/// Span of the literal zero-page address.
span: Range<usize>,
},
/// This error gets reported during an attempt to reference a label that
/// is too far to be a relative address after a literal relative address rune.
///
/// # Example
///
/// ```uxntal
/// @label
/// |0100 ,label
/// ```
AddressTooFar {
/// The distance in bytes from the literal relative address and the label definition.
distance: usize,
/// Name of the identifier that is referenced by the literal relative address.
identifier: String,
/// Span of the literal relative address.
span: Range<usize>,
/// Span of the label definition that is referenced by the literal relative address.
other_span: Range<usize>,
},
/// This error gets reported when there are bytes in the zeroth page (first
/// 256 bytes) of the binary.
///
/// # Example
///
/// ```uxntal
/// #01 #02 ADD
/// ```
BytesInZerothPage {
/// Span of the tokens in the zeroth page.
span: Range<usize>,
},
/// This error gets reported during an attempt to do an absolute pad
/// to an address before the current address pointer.
///
/// # Example
///
/// ```uxntal
/// #01 #02 ADD
/// |0000 #02 #03 ADD
/// ```
PaddedBackwards {
/// The address at which the absolute pad is attempted.
previous_pointer: usize,
/// The address to which the absolute pad is attempted.
desired_pointer: usize,
/// Span of the absolute pad.
span: Range<usize>,
},
/// This error gets reported when the program size exceeds 65536 bytes.
///
/// # Example
///
/// ```uxntal
/// |ffff #01 #02 ADD
/// ```
ProgramTooLong {
/// Span of the tokens that exceed the maximum size.
span: Range<usize>,
},
}
4 changes: 2 additions & 2 deletions src/bin/ruxnasm/reporter/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ impl From<ruxnasm::Error> for FileDiagnostic {
span,
} => FileDiagnostic::error()
.with_message(format!(
"address {:#06x} of label {} is not zero-page",
"address {:#06x} of label `{}` is not zero-page",
address, identifier
))
.with_label(Label {
Expand All @@ -354,7 +354,7 @@ impl From<ruxnasm::Error> for FileDiagnostic {
other_span,
} => FileDiagnostic::error()
.with_message(format!(
"address of label {} is too far to be a relative address (distance {})",
"address of label `{}` is too far to be a relative address (distance {})",
identifier, distance
))
.with_label(Label {
Expand Down
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ pub(crate) use token::{Identifier, Token};
/// `Err((Vec<Error>, Vec<Warning>))`, which contains all [`Error`]s in the program, along with
/// any [`Warning`]s that may have also been generated. The `Vec` containing the errors is always
/// non-empty.
///
/// # Example
///
/// ```rust
/// let (binary, _) = ruxnasm::assemble("|0100 #02 #03 ADD").unwrap();
///
/// assert_eq!(binary, [0x01, 0x02, 0x01, 0x03, 0x18]);
/// ```
pub fn assemble(
source: impl AsRef<str>,
) -> Result<(Vec<u8>, Vec<Warning>), (Vec<Error>, Vec<Warning>)> {
Expand Down
2 changes: 1 addition & 1 deletion src/walker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ fn walk_rec(
previous_pointer: previous_address as usize,
desired_pointer: value as usize,
span: span.into(),
})
}),
}
}
Spanned {
Expand Down

0 comments on commit fcbd239

Please sign in to comment.