From 8b1c270910fce13077864bf39d6e88971a6eb062 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Wed, 8 Jan 2025 12:34:47 +0100 Subject: Implement the .include statement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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à --- crates/nasm/src/main.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'crates') diff --git a/crates/nasm/src/main.rs b/crates/nasm/src/main.rs index 225a865..561e305 100644 --- a/crates/nasm/src/main.rs +++ b/crates/nasm/src/main.rs @@ -4,6 +4,7 @@ use std::fs::File; use std::io::{self, Read, Write}; use std::path::Path; use xixanta::assembler::assemble; +use xixanta::SourceInfo; /// Assembler for the 6502 microprocessor that targets the NES/Famicom. #[derive(ClapParser, Debug)] @@ -40,7 +41,7 @@ fn main() -> Result<()> { // Select the input stream and the current working directory. let input: Box; - let working_directory = match &args.file { + let source_info = match &args.file { Some(file) => { let path = Path::new(file); if !path.is_file() { @@ -48,13 +49,22 @@ fn main() -> Result<()> { } input = Box::new(File::open(file)?); - path.parent() - .with_context(|| String::from("Failed to find directory for given file"))? + SourceInfo { + working_directory: path + .parent() + .with_context(|| String::from("Failed to find directory for given file"))? + .to_path_buf(), + name: path.file_name().unwrap().to_str().unwrap().to_string(), + } } None => { input = Box::new(std::io::stdin()); - &std::env::current_dir() - .with_context(|| String::from("Could not fetch current directory"))? + SourceInfo { + working_directory: std::env::current_dir() + .with_context(|| String::from("Could not fetch current directory"))? + .to_path_buf(), + name: "".to_string(), + } } }; @@ -82,7 +92,7 @@ fn main() -> Result<()> { // And assemble. let mut error_count = 0; - let res = assemble(input, config.as_str(), working_directory.to_path_buf()); + let res = assemble(input, config.as_str(), source_info); // Print warnings and errors first, while also computing the amount of them // that exists. -- cgit v1.2.3