aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml3
-rw-r--r--crates/nasm/Cargo.toml2
-rw-r--r--crates/nasm/src/main.rs5
-rw-r--r--crates/readrom/Cargo.toml1
-rw-r--r--crates/xa65/Cargo.toml2
-rw-r--r--lib/header/Cargo.toml1
-rw-r--r--lib/header/fuzz/Cargo.toml2
-rw-r--r--lib/xixanta/Cargo.toml1
-rw-r--r--lib/xixanta/fuzz/Cargo.toml2
-rw-r--r--lib/xixanta/src/assembler.rs172
-rw-r--r--lib/xixanta/src/cfg.rs13
-rw-r--r--lib/xixanta/src/parser.rs468
-rw-r--r--rustfmt.toml1
13 files changed, 384 insertions, 289 deletions
diff --git a/Cargo.toml b/Cargo.toml
index cf21b7b..a20253c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -3,8 +3,7 @@ members = ["lib/*", "crates/*"]
resolver = "2"
[workspace.package]
-rust-version = "1.82"
-edition = "2021"
+edition = "2024"
# Everything under crates/* is GPLv3+; everything under lib/* is under LGPLv3+.
license = "GPLv3+ AND LGPLv3+"
authors = ["Miquel Sabaté Solà <mikisabate@gmail.com>"]
diff --git a/crates/nasm/Cargo.toml b/crates/nasm/Cargo.toml
index f1294f7..b204a33 100644
--- a/crates/nasm/Cargo.toml
+++ b/crates/nasm/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "nasm"
version = "0.1.0"
-edition = "2021"
+edition = "2024"
authors = ["Miquel Sabaté Solà <mikisabate@gmail.com>"]
[dependencies]
diff --git a/crates/nasm/src/main.rs b/crates/nasm/src/main.rs
index 9f44620..4ec4f59 100644
--- a/crates/nasm/src/main.rs
+++ b/crates/nasm/src/main.rs
@@ -207,11 +207,10 @@ fn find_git_directory(source: &SourceInfo) -> PathBuf {
fn get_directory_from_source(source: &SourceInfo) -> PathBuf {
let dir = find_git_directory(source).join(".nasm");
- if !dir.exists() {
- if let Err(e) = create_dir(&dir) {
+ if !dir.exists()
+ && let Err(e) = create_dir(&dir) {
die(e.to_string());
}
- }
dir
}
diff --git a/crates/readrom/Cargo.toml b/crates/readrom/Cargo.toml
index 326ed92..ff2f04b 100644
--- a/crates/readrom/Cargo.toml
+++ b/crates/readrom/Cargo.toml
@@ -1,7 +1,6 @@
[package]
name = "readrom"
version = "1.0.0"
-rust-version.workspace = true
edition.workspace = true
license.workspace = true
authors.workspace = true
diff --git a/crates/xa65/Cargo.toml b/crates/xa65/Cargo.toml
index 1a2c52c..8ca15cc 100644
--- a/crates/xa65/Cargo.toml
+++ b/crates/xa65/Cargo.toml
@@ -1,5 +1,5 @@
[package]
name = "xa65"
version = "0.1.0"
-edition = "2021"
+edition = "2024"
authors = ["Miquel Sabaté Solà <mikisabate@gmail.com>"]
diff --git a/lib/header/Cargo.toml b/lib/header/Cargo.toml
index 56eb36c..8e88856 100644
--- a/lib/header/Cargo.toml
+++ b/lib/header/Cargo.toml
@@ -1,7 +1,6 @@
[package]
name = "header"
version = "0.1.0"
-rust-version.workspace = true
edition.workspace = true
license.workspace = true
authors.workspace = true
diff --git a/lib/header/fuzz/Cargo.toml b/lib/header/fuzz/Cargo.toml
index 9ea48be..ea78c24 100644
--- a/lib/header/fuzz/Cargo.toml
+++ b/lib/header/fuzz/Cargo.toml
@@ -2,7 +2,7 @@
name = "header-fuzz"
version = "0.0.0"
publish = false
-edition = "2021"
+edition = "2024"
[workspace]
members = []
diff --git a/lib/xixanta/Cargo.toml b/lib/xixanta/Cargo.toml
index 7989ffc..d994b6b 100644
--- a/lib/xixanta/Cargo.toml
+++ b/lib/xixanta/Cargo.toml
@@ -6,4 +6,3 @@ description = "TBD"
authors.workspace = true
edition.workspace = true
license.workspace = true
-rust-version.workspace = true
diff --git a/lib/xixanta/fuzz/Cargo.toml b/lib/xixanta/fuzz/Cargo.toml
index 49764ed..0e52091 100644
--- a/lib/xixanta/fuzz/Cargo.toml
+++ b/lib/xixanta/fuzz/Cargo.toml
@@ -2,7 +2,7 @@
name = "xixanta-fuzz"
version = "0.0.0"
publish = false
-edition = "2021"
+edition = "2024"
[workspace]
members = []
diff --git a/lib/xixanta/src/assembler.rs b/lib/xixanta/src/assembler.rs
index dac298a..5b72fb5 100644
--- a/lib/xixanta/src/assembler.rs
+++ b/lib/xixanta/src/assembler.rs
@@ -1,12 +1,12 @@
-use crate::mapping::{get_mapping_configuration, Mapping};
+use crate::SourceInfo;
+use crate::mapping::{Mapping, SectionType, get_mapping_configuration};
use crate::node::{
- is_asan_friendly_name, CommentType, ControlType, EchoKind, NodeType, OperationType, PNode,
- PString,
+ CommentType, ControlType, EchoKind, NodeType, OperationType, PNode, PString,
+ is_asan_friendly_name,
};
-use crate::object::{Bundle, Context, Object, ObjectType, GLOBAL_CONTEXT};
+use crate::object::{Bundle, Context, GLOBAL_CONTEXT, Object, ObjectType};
use crate::opcodes::{AddressingMode, INSTRUCTIONS};
use crate::parser::Parser;
-use crate::SourceInfo;
use crate::{Error, ExpandedFrom};
use std::cmp::Ordering;
use std::collections::HashMap;
@@ -618,10 +618,11 @@ impl<'a> Assembler<'a> {
// Check that the given name makes sense if the
// address sanitizer is enabled and the assigned
// value is known.
- if self.asan_enabled && value.resolved {
- if let Err(err) = self.asan_check_variable_name(node, &value) {
- errors.push(err);
- }
+ if self.asan_enabled
+ && value.resolved
+ && let Err(err) = self.asan_check_variable_name(node, &value)
+ {
+ errors.push(err);
}
if let Err(err) = self.context.set_variable(
@@ -855,16 +856,16 @@ impl<'a> Assembler<'a> {
accessed: 0,
};
- if !node.value.is_empty() {
- if let Err(message) = self.context.set_variable(&node.value, &object, true) {
- return Err(Error {
- message,
- line: node.value.line,
- global: false,
- expanded_from: self.macro_context.clone(),
- source: self.source_for(node),
- });
- }
+ if !node.value.is_empty()
+ && let Err(message) = self.context.set_variable(&node.value, &object, true)
+ {
+ return Err(Error {
+ message,
+ line: node.value.line,
+ global: false,
+ expanded_from: self.macro_context.clone(),
+ source: self.source_for(node),
+ });
}
self.context.add_label(&object);
@@ -1507,10 +1508,10 @@ impl<'a> Assembler<'a> {
// If the macro had not been referenced yet, remove it from the vector
// of pending macros.
- if !self.allow_unused {
- if let Some(pos) = self.macro_names.iter().position(|x| x == &node.value.value) {
- self.macro_names.swap_remove(pos);
- }
+ if !self.allow_unused
+ && let Some(pos) = self.macro_names.iter().position(|x| x == &node.value.value)
+ {
+ self.macro_names.swap_remove(pos);
}
// Detect missmatches between the number of arguments provided and the
@@ -1994,7 +1995,7 @@ impl<'a> Assembler<'a> {
source: self.source_for(node),
expanded_from: self.macro_context.clone(),
global: false,
- })
+ });
}
Ordering::Greater => {
return Err(Error {
@@ -2003,7 +2004,7 @@ impl<'a> Assembler<'a> {
source: self.source_for(node),
expanded_from: self.macro_context.clone(),
global: false,
- })
+ });
}
_ => {}
}
@@ -2322,7 +2323,7 @@ impl<'a> Assembler<'a> {
source: self.source_for(node),
expanded_from: self.macro_context.clone(),
message: format!("could not include binary data: {e}"),
- })
+ });
}
};
@@ -2360,7 +2361,7 @@ impl<'a> Assembler<'a> {
source: self.source_for(node),
expanded_from: self.macro_context.clone(),
message: format!("could not include binary data: {e}"),
- })
+ });
}
}
@@ -2412,7 +2413,7 @@ impl<'a> Assembler<'a> {
expanded_from: self.macro_context.clone(),
source: self.source_for(node),
}
- .into())
+ .into());
}
};
@@ -2433,8 +2434,8 @@ impl<'a> Assembler<'a> {
for i in 0..repeats {
// If an index was given, set it now as a .repeat variable with the
// loop index.
- if args.len() == 2 {
- if let Err(e) = self.context.set_variable(
+ if args.len() == 2
+ && let Err(e) = self.context.set_variable(
&args.last().unwrap().value,
&Object {
bundle: Bundle::fill(i as u8),
@@ -2447,16 +2448,16 @@ impl<'a> Assembler<'a> {
accessed: 0,
},
true,
- ) {
- return Err(Error {
- line: node.value.line,
- message: e,
- source: self.source_for(node),
- expanded_from: self.macro_context.clone(),
- global: false,
- }
- .into());
+ )
+ {
+ return Err(Error {
+ line: node.value.line,
+ message: e,
+ source: self.source_for(node),
+ expanded_from: self.macro_context.clone(),
+ global: false,
}
+ .into());
}
// And push all the bundles from the inner code.
@@ -2696,7 +2697,7 @@ impl<'a> Assembler<'a> {
source: self.source_for(node),
expanded_from: self.macro_context.clone(),
global: false,
- })
+ });
}
2 => {
bundle.size = 2;
@@ -2728,7 +2729,7 @@ impl<'a> Assembler<'a> {
source: self.source_for(node),
expanded_from: self.macro_context.clone(),
global: false,
- })
+ });
}
}
@@ -2904,7 +2905,7 @@ impl<'a> Assembler<'a> {
// Overwrite the variable with this new value. This way the
// next time this is found we don't have to evaluate it
- // again. If the variable could not be set, then it's not
+ // again. If the variable could not be set, then it's not
// that big of a deal at this stage.
value.bundle = bundle.clone();
let _ = self.context.set_variable(&node.value, &value, true);
@@ -3105,16 +3106,16 @@ impl<'a> Assembler<'a> {
// Ensure that the literal mode for the left arm ensures an address
// instead of some bogus number.
- if let Some(lm) = &self.literal_mode {
- if *lm != LiteralMode::Hexadecimal {
- return Err(Error {
- message: "indexed addressing only works with addresses".to_string(),
- line: node.value.line,
- source: self.source_for(node),
- global: false,
- expanded_from: self.macro_context.clone(),
- });
- }
+ if let Some(lm) = &self.literal_mode
+ && *lm != LiteralMode::Hexadecimal
+ {
+ return Err(Error {
+ message: "indexed addressing only works with addresses".to_string(),
+ line: node.value.line,
+ source: self.source_for(node),
+ global: false,
+ expanded_from: self.macro_context.clone(),
+ });
}
// Check the right arm to know the index being used.
@@ -3136,13 +3137,12 @@ impl<'a> Assembler<'a> {
// indexing is, then convert this instruction to absolute
// indexing.
let mnemonic = node.value.value.to_lowercase();
- if let Some(entries) = INSTRUCTIONS.get(&mnemonic) {
- if entries.get(&AddressingMode::ZeropageIndexedX).is_none()
- && entries.get(&AddressingMode::IndexedX).is_some()
- {
- val.size = 2;
- return Ok((AddressingMode::IndexedX, val));
- }
+ if let Some(entries) = INSTRUCTIONS.get(&mnemonic)
+ && entries.get(&AddressingMode::ZeropageIndexedX).is_none()
+ && entries.get(&AddressingMode::IndexedX).is_some()
+ {
+ val.size = 2;
+ return Ok((AddressingMode::IndexedX, val));
}
// Re-inforce the optimization when val.size == 2 by forcing
@@ -3160,13 +3160,12 @@ impl<'a> Assembler<'a> {
if val.size == 1 || (val.resolved && val.bytes[1] == 0x00) {
// Similar to the case on "x" indexing.
let mnemonic = node.value.value.to_lowercase();
- if let Some(entries) = INSTRUCTIONS.get(&mnemonic) {
- if entries.get(&AddressingMode::ZeropageIndexedY).is_none()
- && entries.get(&AddressingMode::IndexedY).is_some()
- {
- val.size = 2;
- return Ok((AddressingMode::IndexedY, val));
- }
+ if let Some(entries) = INSTRUCTIONS.get(&mnemonic)
+ && entries.get(&AddressingMode::ZeropageIndexedY).is_none()
+ && entries.get(&AddressingMode::IndexedY).is_some()
+ {
+ val.size = 2;
+ return Ok((AddressingMode::IndexedY, val));
}
val.size = 1;
@@ -3268,13 +3267,13 @@ impl<'a> Assembler<'a> {
// If it's referencing an actual address, then let it be
// (e.g. 'lda palettes, x'; where 'palettes' is a legitimate
// name even if not 'is_asan_friendly_name').
- if let Ok(var) = self.context.get_variable(&node.value, &self.mappings) {
- if matches!(
+ if let Ok(var) = self.context.get_variable(&node.value, &self.mappings)
+ && matches!(
var.object_type,
ObjectType::Address | ObjectType::Argument(_) | ObjectType::Proc
- ) {
- return Ok(());
- }
+ )
+ {
+ return Ok(());
}
// Everything has been exhausted, this is actually not a
@@ -3302,21 +3301,21 @@ impl<'a> Assembler<'a> {
} else {
// If everything failed but because it was an address
// (e.g. 'lda palettes + 1, x'), then return early.
- if let Ok(var) = self.context.get_variable(left_name, &self.mappings) {
- if matches!(
+ if let Ok(var) = self.context.get_variable(left_name, &self.mappings)
+ && matches!(
var.object_type,
ObjectType::Address | ObjectType::Argument(_) | ObjectType::Proc
- ) {
- return Ok(());
- }
+ )
+ {
+ return Ok(());
}
- if let Ok(var) = self.context.get_variable(right_name, &self.mappings) {
- if matches!(
+ if let Ok(var) = self.context.get_variable(right_name, &self.mappings)
+ && matches!(
var.object_type,
ObjectType::Address | ObjectType::Argument(_) | ObjectType::Proc
- ) {
- return Ok(());
- }
+ )
+ {
+ return Ok(());
}
self.warnings.push(Error {
@@ -3505,7 +3504,7 @@ impl<'a> Assembler<'a> {
#[cfg(test)]
mod tests {
use super::*;
- use crate::mapping::{get_mapping_configuration, SectionType, Segment};
+ use crate::mapping::{SectionType, Segment, get_mapping_configuration};
fn one_two() -> Vec<Mapping> {
vec![
@@ -3694,10 +3693,11 @@ mod tests {
fn parse_decimal() {
assert_error("adc #222256", 1, false, "decimal value is too big");
assert_error(
- "adc #2A",
- 1, false,
- "'A' is not a decimal value and could not find variable '2A' in the global scope either",
- );
+ "adc #2A",
+ 1,
+ false,
+ "'A' is not a decimal value and could not find variable '2A' in the global scope either",
+ );
assert_instruction("adc #1", &[0x69, 0x01]);
assert_instruction("adc #.hibyte(61953)", &[0x69, 0xF2]);
}
diff --git a/lib/xixanta/src/cfg.rs b/lib/xixanta/src/cfg.rs
index 57781f2..52e075e 100644
--- a/lib/xixanta/src/cfg.rs
+++ b/lib/xixanta/src/cfg.rs
@@ -104,10 +104,9 @@ fn fetch_memory_definition(line: &str, line_num: usize) -> Result<RawMapping, St
match key.trim() {
"file" => res.ignore = val != "%O",
- "fill"
- if res.fill.is_none() => {
- res.fill = Some(String::from(""));
- }
+ "fill" if res.fill.is_none() => {
+ res.fill = Some(String::from(""));
+ }
"fillval" => res.fill = Some(val.to_string()),
"start" => res.start = val.to_string(),
"size" => res.size = val.to_string(),
@@ -199,7 +198,7 @@ pub fn parse_cfg_file(text: &str) -> Result<Vec<Mapping>, String> {
return Err(format!(
"line does not end with a semicolon (line {})",
idx + 1
- ))
+ ));
}
};
@@ -240,7 +239,7 @@ pub fn parse_cfg_file(text: &str) -> Result<Vec<Mapping>, String> {
return Err(format!(
"section must end with an opening bracket (line {})",
idx + 1
- ))
+ ));
}
};
}
@@ -333,7 +332,7 @@ pub fn parse_nasm_cfg_file(text: &str) -> Result<Vec<Mapping>, String> {
return Err(format!(
"line does not end with a semicolon (line {})",
idx + 1
- ))
+ ));
}
};
diff --git a/lib/xixanta/src/parser.rs b/lib/xixanta/src/parser.rs
index a149e16..e004fd9 100644
--- a/lib/xixanta/src/parser.rs
+++ b/lib/xixanta/src/parser.rs
@@ -637,7 +637,9 @@ impl Parser {
global: false,
source: self.sources[self.current_source].clone(),
expanded_from: vec![],
- message: format!("{msg} relative label can only have '{next}' characters"),
+ message: format!(
+ "{msg} relative label can only have '{next}' characters"
+ ),
});
}
self.next();
@@ -1065,7 +1067,7 @@ impl Parser {
None => {
return Err(self
.parser_error(format!("unexpected '{real_type}'").as_str())
- .into())
+ .into());
}
};
if *node_type != expected_close {
@@ -1128,7 +1130,7 @@ impl Parser {
expanded_from: vec![],
message: format!("could not open source file '{file_path}': {e}"),
}
- .into())
+ .into());
}
};
let Some(parent) = path.parent() else {
@@ -1605,16 +1607,16 @@ impl Parser {
// Literal symbols come with a single character, or with two only on
// '#$' or '#%'. Other variations are illegal and should be avoided
// to prevent crashes.
- if let Some(next) = line.chars().nth(1) {
- if next == '#' || (first != '#' && (next == '$' || next == '%')) {
- return Err(Error {
- line: self.line,
- global: false,
- source: self.sources[self.current_source].clone(),
- expanded_from: vec![],
- message: "bad literal syntax".to_string(),
- });
- }
+ if let Some(next) = line.chars().nth(1)
+ && (next == '#' || (first != '#' && (next == '$' || next == '%')))
+ {
+ return Err(Error {
+ line: self.line,
+ global: false,
+ source: self.sources[self.current_source].clone(),
+ expanded_from: vec![],
+ message: "bad literal syntax".to_string(),
+ });
}
self.parse_literal(line, first, level)
@@ -1775,12 +1777,12 @@ impl Parser {
} else {
self.parse_arguments(line, level)?
};
- if let Some(args_required) = control.required_args {
- if args.len() < args_required.0 || args.len() > args_required.1 {
- return Err(self.parser_error(
- format!("wrong number of arguments for function '{}'", id.value).as_str(),
- ));
- }
+ if let Some(args_required) = control.required_args
+ && (args.len() < args_required.0 || args.len() > args_required.1)
+ {
+ return Err(self.parser_error(
+ format!("wrong number of arguments for function '{}'", id.value).as_str(),
+ ));
}
Ok(PNode {
@@ -1826,16 +1828,16 @@ impl Parser {
// this stance, and through fuzzy testing I realized that not doing this
// could result in general bad behavior.
let inner = line.get(1..).unwrap_or("");
- if let Some(c) = inner.chars().nth(0) {
- if c.is_whitespace() {
- return Err(Error {
- line: self.line,
- global: false,
- source: self.sources[self.current_source].clone(),
- expanded_from: vec![],
- message: "numeric literals cannot have white spaces".to_string(),
- });
- }
+ if let Some(c) = inner.chars().nth(0)
+ && c.is_whitespace()
+ {
+ return Err(Error {
+ line: self.line,
+ global: false,
+ source: self.sources[self.current_source].clone(),
+ expanded_from: vec![],
+ message: "numeric literals cannot have white spaces".to_string(),
+ });
}
// Preserve the initial column value and advance it to skip the 'symbol'
@@ -1979,9 +1981,11 @@ mod tests {
use crate::node::ControlType;
fn assert_one_valid(parser: &mut Parser, line: &str) {
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
assert!(parser.nodes.len() == 1);
}
@@ -2006,9 +2010,11 @@ mod tests {
#[test]
fn spaced_line() {
let mut parser = Parser::default();
- assert!(parser
- .parse(" ".as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(" ".as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
assert_eq!(parser.nodes.last().unwrap().len(), 0);
}
@@ -2016,9 +2022,11 @@ mod tests {
fn just_a_comment_line() {
for line in vec![";; This is a comment", " ;; Comment"].into_iter() {
let mut parser = Parser::default();
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
assert_eq!(parser.nodes.last().unwrap().len(), 0);
}
}
@@ -2037,9 +2045,11 @@ mod tests {
assert_eq!(nodes.first().unwrap().value.end, 0);
parser = Parser::default();
- assert!(parser
- .parse(" :".as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(" :".as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
nodes = parser.nodes.last().unwrap();
assert_eq!(nodes.len(), 1);
@@ -2051,9 +2061,11 @@ mod tests {
#[test]
fn named_label() {
let mut parser = Parser::default();
- assert!(parser
- .parse("label:".as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse("label:".as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let mut nodes = parser.nodes.last().unwrap();
assert_eq!(nodes.len(), 1);
@@ -2062,9 +2074,11 @@ mod tests {
assert_eq!(nodes.first().unwrap().value.end, 5);
parser = Parser::default();
- assert!(parser
- .parse(" label:".as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(" label:".as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
nodes = parser.nodes.last().unwrap();
assert_eq!(nodes.len(), 1);
@@ -2078,9 +2092,11 @@ mod tests {
let line = "label: dex";
let mut parser = Parser::default();
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let nodes = parser.nodes();
assert_eq!(nodes.len(), 2);
@@ -2099,9 +2115,11 @@ mod tests {
let line = ".L1: dex";
let mut parser = Parser::default();
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let nodes = parser.nodes();
assert_eq!(nodes.len(), 2);
@@ -2128,9 +2146,11 @@ mod tests {
.into_iter()
{
let mut parser = Parser::default();
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let nodes = parser.nodes();
@@ -2150,9 +2170,11 @@ mod tests {
fn parse_compound_literal() {
let line = "lda #$20";
let mut parser = Parser::default();
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let nodes = parser.nodes();
@@ -2180,9 +2202,11 @@ mod tests {
fn parse_variable_in_literal() {
let line = "lda #Variable";
let mut parser = Parser::default();
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let nodes = parser.nodes();
@@ -2204,9 +2228,11 @@ mod tests {
fn parse_paren_expression() {
let line = "ldx #(Variable)";
let mut parser = Parser::default();
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let instr = parser.nodes.last().unwrap().last().unwrap();
assert_eq!(instr.node_type, NodeType::Instruction);
@@ -2274,9 +2300,11 @@ mod tests {
let mut parser = Parser::default();
let line = ".asciiz \"=a: b, c; d\" ; Comment";
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let stmt = parser.nodes.last().unwrap().last().unwrap();
let inner = stmt.args.as_ref().unwrap().first().unwrap();
@@ -2332,9 +2360,11 @@ mod tests {
.into_iter()
{
let mut parser = Parser::default();
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let node = parser.nodes.last().unwrap().last().unwrap();
assert_node(node, NodeType::Instruction, line, "dex");
@@ -2420,9 +2450,11 @@ mod tests {
.into_iter()
{
let mut parser = Parser::default();
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let node = parser.nodes.last().unwrap().last().unwrap();
assert_node(node, NodeType::Instruction, line, "inc");
@@ -2449,9 +2481,11 @@ mod tests {
.into_iter()
{
let mut parser = Parser::default();
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let node = parser.nodes.last().unwrap().last().unwrap();
assert_node(node, NodeType::Instruction, line, "lda");
@@ -2476,9 +2510,11 @@ mod tests {
.into_iter()
{
let mut parser = Parser::default();
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let node = parser.nodes.last().unwrap().last().unwrap();
assert_node(node, NodeType::Instruction, line, "lda");
@@ -2505,9 +2541,11 @@ mod tests {
fn indirect_addressing_y() {
for line in vec!["lda ($20), y"].into_iter() {
let mut parser = Parser::default();
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let node = parser.nodes.last().unwrap().last().unwrap();
assert_node(node, NodeType::Instruction, line, "lda");
@@ -2526,9 +2564,11 @@ mod tests {
fn variable_in_instruction() {
let line = "lda Variable, x";
let mut parser = Parser::default();
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let node = parser.nodes.last().unwrap().last().unwrap();
assert_node(node, NodeType::Instruction, line, "lda");
@@ -2547,9 +2587,11 @@ mod tests {
fn variable_literal_in_instruction() {
let line = "lda #Variable, x";
let mut parser = Parser::default();
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let node = parser.nodes.last().unwrap().last().unwrap();
assert_node(node, NodeType::Instruction, line, "lda");
@@ -2569,9 +2611,11 @@ mod tests {
for var in vec!["Scope::Variable", "Scope::Inner::Variable"].into_iter() {
let line = format!("lda #{var}");
let mut parser = Parser::default();
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let node = parser.nodes.last().unwrap().last().unwrap();
assert_node(node, NodeType::Instruction, line.as_str(), "lda");
@@ -2618,9 +2662,11 @@ mod tests {
for label in vec![":+", ":++", ":+++ ", ":++++", ":-", ":--", ":---", ":----"].into_iter() {
let line = format!("jmp {label}");
let mut parser = Parser::default();
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let node = parser.nodes.last().unwrap().last().unwrap();
assert_node(node, NodeType::Instruction, line.as_str(), "jmp");
@@ -2725,9 +2771,11 @@ mod tests {
fn constant_expression_test() {
let line = "ldx #(4 * NUM_SPRITES)";
let mut parser = Parser::default();
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let node = parser.nodes.last().unwrap().last().unwrap();
assert_node(node, NodeType::Instruction, line, "ldx");
@@ -2752,9 +2800,11 @@ mod tests {
fn nested_expression_test() {
let line = "lda #$80 >> ((BCD_BITS - 1) & 3)";
let mut parser = Parser::default();
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let instr = parser.nodes.last().unwrap().last().unwrap();
assert_node(instr, NodeType::Instruction, line, "lda");
@@ -2792,9 +2842,11 @@ mod tests {
fn parens_to_desambiguate() {
let line = ".byte ($01 << 4) | ($01 << 2) | ($01 << 1)";
let mut parser = Parser::default();
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let node = parser.nodes.last().unwrap().last().unwrap();
assert_node(node, NodeType::Control(ControlType::Byte), line, ".byte");
@@ -2834,9 +2886,11 @@ mod tests {
fn parens_to_desambiguate2() {
let line = ".byte ($01 << 4) | ($01 << 2) | ($01 << 1), $02";
let mut parser = Parser::default();
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let node = parser.nodes.last().unwrap().last().unwrap();
assert_node(node, NodeType::Control(ControlType::Byte), line, ".byte");
@@ -2859,9 +2913,11 @@ mod tests {
fn unary_operator_test() {
let line = "ldx #<NUM_SPRITES";
let mut parser = Parser::default();
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let node = parser.nodes.last().unwrap().last().unwrap();
assert_node(node, NodeType::Instruction, line, "ldx");
@@ -2888,9 +2944,11 @@ mod tests {
fn parse_control_no_args() {
for line in vec![".byte", " .byte", " label: .byte ; Comment"].into_iter() {
let mut parser = Parser::default();
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let node = parser.nodes.last().unwrap().last().unwrap();
assert_node(node, NodeType::Control(ControlType::Byte), line, ".byte");
@@ -2912,9 +2970,11 @@ mod tests {
.into_iter()
{
let mut parser = Parser::default();
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let node = parser.nodes.last().unwrap().last().unwrap();
assert_node(
@@ -2944,9 +3004,11 @@ mod tests {
.into_iter()
{
let mut parser = Parser::default();
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let node = parser.nodes.last().unwrap().last().unwrap();
assert_node(node, NodeType::Control(ControlType::Byte), line, ".byte");
@@ -2964,9 +3026,11 @@ mod tests {
fn parse_byte_with_character_literals() {
let line = ".byte 'N', 'E', 'S', $1A";
let mut parser = Parser::default();
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let args = parser
.nodes
@@ -3018,9 +3082,11 @@ mod tests {
let real = String::from(line) + "\n.endscope";
let mut parser = Parser::default();
- assert!(parser
- .parse(real.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(real.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let nodes = parser.nodes();
let node = &nodes[nodes.len() - 2];
@@ -3054,9 +3120,11 @@ mod tests {
let real = String::from(line) + "\n.endmacro";
let mut parser = Parser::default();
- assert!(parser
- .parse(real.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(real.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let nodes = parser.nodes();
let node = &nodes[nodes.len() - 2];
@@ -3093,9 +3161,11 @@ mod tests {
let real = String::from(line) + "\n.endmacro";
let mut parser = Parser::default();
- assert!(parser
- .parse(real.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(real.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let nodes = parser.nodes();
let node = &nodes[nodes.len() - 2];
@@ -3171,9 +3241,11 @@ nop
inc $20
.endmacro"#;
let mut parser = Parser::default();
- assert!(parser
- .parse(code.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(code.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let nodes = parser.nodes();
assert_eq!(nodes.len(), 2); // .macro and .endmacro
@@ -3221,9 +3293,11 @@ inc $20
fn parse_control_in_instructions() {
for line in vec!["lda #.hibyte($2010)", " label: lda #.hibyte $2010 "].into_iter() {
let mut parser = Parser::default();
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let node = parser.nodes.last().unwrap().last().unwrap();
assert_node(node, NodeType::Instruction, line, "lda");
@@ -3260,9 +3334,11 @@ inc $20
.into_iter()
{
let mut parser = Parser::default();
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let node = parser.nodes.last().unwrap().last().unwrap();
assert_node(node, NodeType::Instruction, line, "lda");
@@ -3306,9 +3382,11 @@ inc $20
.into_iter()
{
let mut parser = Parser::default();
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let node = parser.nodes.last().unwrap().last().unwrap();
assert_node(node, NodeType::Instruction, line, "lda");
@@ -3353,9 +3431,11 @@ inc $20
.into_iter()
{
let mut parser = Parser::default();
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let node = parser.nodes.last().unwrap().last().unwrap();
assert_node(node, NodeType::Assignment, line, "lala");
@@ -3411,9 +3491,11 @@ inc $20
parser = Parser::default();
let mut line = ".repeat 2\n.endrepeat";
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let mut control = parser.nodes.last().unwrap().first().unwrap();
assert_node(
control,
@@ -3421,13 +3503,15 @@ inc $20
line,
".repeat",
);
- assert!(control
- .left
- .as_ref()
- .unwrap()
- .value
- .value
- .starts_with(".repeat-"));
+ assert!(
+ control
+ .left
+ .as_ref()
+ .unwrap()
+ .value
+ .value
+ .starts_with(".repeat-")
+ );
assert!(control.right.is_some());
let mut args = control.args.clone().unwrap();
@@ -3439,9 +3523,11 @@ inc $20
parser = Parser::default();
line = ".repeat 2, I\n.endrepeat";
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
control = parser.nodes.last().unwrap().first().unwrap();
assert_node(
control,
@@ -3449,13 +3535,15 @@ inc $20
line,
".repeat",
);
- assert!(control
- .left
- .as_ref()
- .unwrap()
- .value
- .value
- .starts_with(".repeat-"));
+ assert!(
+ control
+ .left
+ .as_ref()
+ .unwrap()
+ .value
+ .value
+ .starts_with(".repeat-")
+ );
assert!(control.right.is_some());
args = control.args.clone().unwrap();
@@ -3494,9 +3582,11 @@ inc $20
.into_iter()
{
let mut parser = Parser::default();
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let node = parser.nodes.last().unwrap().last().unwrap();
assert_node(node, NodeType::Call, line, "MACRO_CALL");
@@ -3518,9 +3608,11 @@ inc $20
.into_iter()
{
let mut parser = Parser::default();
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let node = parser.nodes.last().unwrap().last().unwrap();
assert_node(node, NodeType::Call, line, "MACRO_CALL");
@@ -3541,9 +3633,11 @@ inc $20
.into_iter()
{
let mut parser = Parser::default();
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let node = parser.nodes.last().unwrap().last().unwrap();
assert_node(node, NodeType::Call, line, "MACRO_CALL");
@@ -3567,9 +3661,11 @@ inc $20
.into_iter()
{
let mut parser = Parser::default();
- assert!(parser
- .parse(line.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(line.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let node = parser.nodes.last().unwrap().last().unwrap();
assert_node(node, NodeType::Call, line, "MACRO_CALL");
@@ -3593,9 +3689,11 @@ VAR2 = $02 ;; asan:reserve $03
VAR3 = $200 ;; asan:reserve $100
"#;
let mut parser = Parser::default();
- assert!(parser
- .parse(code.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(code.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let nodes = parser.nodes();
assert_eq!(nodes.len(), 6);
@@ -3667,9 +3765,11 @@ VAR3 = $200 ;; asan:reserve $100
;; asan:stack $100-$1FF
"#;
let mut parser = Parser::default();
- assert!(parser
- .parse(code.as_bytes(), &SourceInfo::default())
- .is_ok());
+ assert!(
+ parser
+ .parse(code.as_bytes(), &SourceInfo::default())
+ .is_ok()
+ );
let nodes = parser.nodes();
assert_eq!(nodes.len(), 3);
diff --git a/rustfmt.toml b/rustfmt.toml
new file mode 100644
index 0000000..0fb71e6
--- /dev/null
+++ b/rustfmt.toml
@@ -0,0 +1 @@
+edition = "2024" \ No newline at end of file