diff options
| author | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-01-08 12:34:47 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-01-09 16:01:39 +0100 |
| commit | 8b1c270910fce13077864bf39d6e88971a6eb062 (patch) | |
| tree | 2a441b58d46905f680749c1c074e9b55a27f0d6e /lib/xixanta/src/mapping.rs | |
| parent | 4f5710aa516ab149d132cdb5863db08f08c10563 (diff) | |
| download | tools.nes-8b1c270910fce13077864bf39d6e88971a6eb062.tar.gz tools.nes-8b1c270910fce13077864bf39d6e88971a6eb062.zip | |
Implement the .include statement
This needed some heavy lifting when it comes to how files were located.
This means that statements like .include/.incbin now take into
consideration a new list made out of SourceInfo, which holds enough
information to translate from which file a node comes from. This has
also been added into errors, so they are more informative on what went
wrong.
In order to tests this, besides all the regular unit tests, a new e2e
test has been added.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'lib/xixanta/src/mapping.rs')
| -rw-r--r-- | lib/xixanta/src/mapping.rs | 57 |
1 files changed, 17 insertions, 40 deletions
diff --git a/lib/xixanta/src/mapping.rs b/lib/xixanta/src/mapping.rs index 12b64c8..f86b513 100644 --- a/lib/xixanta/src/mapping.rs +++ b/lib/xixanta/src/mapping.rs @@ -1,4 +1,3 @@ -use crate::errors::EvalError; use crate::object::Bundle; use toml::{Table, Value}; @@ -279,18 +278,14 @@ fn validate_configuration(mappings: &[Mapping]) -> Result<(), String> { /// Perform some sanity checks on the given `mappings`. Only call this function /// after all bundles have been produced. -pub fn validate(mappings: &[Mapping]) -> Result<(), EvalError> { +pub fn validate(mappings: &[Mapping]) -> Result<(), String> { // Guaranteed by `crate::mapping::assert` to be the header. let header: &Segment = mappings.first().unwrap().segments.first().unwrap(); // Header must have at least six bytes with proper information provided by // the programmer. if header.len() < 6 { - return Err(EvalError { - line: 0, - message: String::from("The header must contain at least 6 bytes"), - global: true, - }); + return Err(String::from("The header must contain at least 6 bytes")); } // Now check that the length of the evaluated data matches the criteria @@ -310,18 +305,16 @@ pub fn validate(mappings: &[Mapping]) -> Result<(), EvalError> { }); if header_prg_rom_size < prg_rom_len { - return Err(EvalError { - line: 0, - message: format!("PRG ROM size is expected to by {} bytes long, but a total of {} bytes were evaluated", header_prg_rom_size, prg_rom_len), - global: true, - }); + return Err(format!( + "PRG ROM size is expected to by {} bytes long, but a total of {} bytes were evaluated", + header_prg_rom_size, prg_rom_len + )); } if header_chr_rom_size < chr_rom_len { - return Err(EvalError { - line: 0, - message: format!("CHR ROM size is expected to by {} bytes long, but a total of {} bytes were evaluated", header_chr_rom_size, chr_rom_len), - global: true, - }); + return Err(format!( + "CHR ROM size is expected to by {} bytes long, but a total of {} bytes were evaluated", + header_chr_rom_size, chr_rom_len + )); } Ok(()) @@ -329,39 +322,23 @@ pub fn validate(mappings: &[Mapping]) -> Result<(), EvalError> { // Returns a tuple with the sizes for PRG and CHR ROM as described from the // computed header. This also does some sanity checks on the header. -fn parse_header(header: &Segment) -> Result<(usize, usize), EvalError> { +fn parse_header(header: &Segment) -> Result<(usize, usize), String> { let mut header_it = header.bundles.clone().into_iter(); // Validate the magic string: 'N', 'E', 'S', $1A if header_it.next().unwrap().bytes[0] != b'N' { - return Err(EvalError { - line: 0, - message: String::from("First byte of the header must be 'N'"), - global: true, - }); + return Err(String::from("First byte of the header must be 'N'")); } if header_it.next().unwrap().bytes[0] != b'E' { - return Err(EvalError { - line: 0, - message: String::from("Second byte of the header must be 'E'"), - global: true, - }); + return Err(String::from("Second byte of the header must be 'E'")); } if header_it.next().unwrap().bytes[0] != b'S' { - return Err(EvalError { - line: 0, - message: String::from("Third byte of the header must be 'S'"), - global: true, - }); + return Err(String::from("Third byte of the header must be 'S'")); } if header_it.next().unwrap().bytes[0] != 26 { - return Err(EvalError { - line: 0, - message: String::from( - "Fourth byte of the header must be the MS-DOS termination character", - ), - global: true, - }); + return Err(String::from( + "Fourth byte of the header must be the MS-DOS termination character", + )); } Ok(( |
