aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/xixanta/src/assembler.rs42
-rw-r--r--lib/xixanta/src/cfg.rs26
-rw-r--r--lib/xixanta/src/mapping.rs8
-rw-r--r--lib/xixanta/src/node.rs2
-rw-r--r--lib/xixanta/src/object.rs8
-rw-r--r--lib/xixanta/src/parser.rs24
6 files changed, 46 insertions, 64 deletions
diff --git a/lib/xixanta/src/assembler.rs b/lib/xixanta/src/assembler.rs
index 66fe418..5b01db8 100644
--- a/lib/xixanta/src/assembler.rs
+++ b/lib/xixanta/src/assembler.rs
@@ -358,7 +358,7 @@ impl<'a> Assembler<'a> {
NodeType::Control(control_type) => {
if !self.context.is_global() && control_type.must_be_global() {
errors.push(Error {
- message: format!("{} must be on the global scope", control_type),
+ message: format!("{control_type} must be on the global scope"),
line: node.value.line,
global: false,
source: self.source_for(node),
@@ -715,7 +715,7 @@ impl<'a> Assembler<'a> {
let val = &arg.value.value[1..arg.value.value.len() - 1];
match t {
- EchoKind::Info => println!("info: {}", val),
+ EchoKind::Info => println!("info: {val}"),
EchoKind::Warning => self.warnings.push(Error {
global: false,
line: node.value.line,
@@ -1173,8 +1173,7 @@ impl<'a> Assembler<'a> {
if self.evaluate_variable(node).is_ok() {
return Err(Error {
message: format!(
- "you cannot use variables like '{}' in binary literals",
- string
+ "you cannot use variables like '{string}' in binary literals"
),
line: node.value.line,
source: self.source_for(node),
@@ -1182,7 +1181,7 @@ impl<'a> Assembler<'a> {
});
}
return Err(Error {
- message: format!("bad binary format for '{}'", string),
+ message: format!("bad binary format for '{string}'"),
line: node.value.line,
global: false,
source: self.source_for(node),
@@ -1234,9 +1233,8 @@ impl<'a> Assembler<'a> {
return Err(Error {
message: format!(
"variables must come from a constant expression, \
- you cannot use other variables such as '{}' \
- in variable definitions",
- string
+ you cannot use other variables such as '{string}' \
+ in variable definitions"
),
source: self.source_for(node),
line: node.value.line,
@@ -1425,8 +1423,7 @@ impl<'a> Assembler<'a> {
return Err(Error {
line: node.value.line,
message: format!(
- "path has to be written inside of double quotes ('{}' given instead)",
- value,
+ "path has to be written inside of double quotes ('{value}' given instead)",
),
source: self.source_for(node),
global: false,
@@ -1441,7 +1438,7 @@ impl<'a> Assembler<'a> {
if let Err(e) = std::env::set_current_dir(&source.directory) {
return Err(Error {
line: node.value.line,
- message: format!("could not move to the directory of '{}': {}", value, e),
+ message: format!("could not move to the directory of '{value}': {e}"),
source: self.source_for(node),
global: false,
});
@@ -1459,7 +1456,7 @@ impl<'a> Assembler<'a> {
global: false,
line: node.value.line,
source: self.source_for(node),
- message: format!("could not include binary data: {}", e),
+ message: format!("could not include binary data: {e}"),
})
}
};
@@ -1478,14 +1475,14 @@ impl<'a> Assembler<'a> {
global: false,
line: node.value.line,
source: self.source_for(node),
- message: format!("file '{}' is too big", path),
+ message: format!("file '{path}' is too big"),
});
} else if metadata.len() == 0 {
return Err(Error {
global: false,
line: node.value.line,
source: self.source_for(node),
- message: format!("trying to include an empty file ('{}')", path),
+ message: format!("trying to include an empty file ('{path}')"),
});
}
}
@@ -1494,7 +1491,7 @@ impl<'a> Assembler<'a> {
global: false,
line: node.value.line,
source: self.source_for(node),
- message: format!("could not include binary data: {}", e),
+ message: format!("could not include binary data: {e}"),
})
}
}
@@ -1540,10 +1537,7 @@ impl<'a> Assembler<'a> {
return Err(Error {
global: false,
line: node.value.line,
- message: format!(
- "first argument must be an integer, '{}' found instead",
- first
- ),
+ message: format!("first argument must be an integer, '{first}' found instead"),
source: self.source_for(node),
}
.into())
@@ -1842,8 +1836,7 @@ impl<'a> Assembler<'a> {
return Err(Error {
line: node.value.line,
message: format!(
- "declaration has to be written inside of double quotes ('{}' given instead)",
- val,
+ "declaration has to be written inside of double quotes ('{val}' given instead)",
),
source: self.source_for(node),
global: false,
@@ -1899,7 +1892,7 @@ impl<'a> Assembler<'a> {
if !found {
return Err(Error {
line: node.value.line,
- message: format!("unknown segment '{}'", name),
+ message: format!("unknown segment '{name}'"),
source: self.source_for(node),
global: false,
});
@@ -1941,8 +1934,7 @@ impl<'a> Assembler<'a> {
None => {
return Err(Error {
message: format!(
- "cannot use {} addressing mode for the instruction '{}'",
- mode, mnemonic
+ "cannot use {mode} addressing mode for the instruction '{mnemonic}'"
),
source: self.source_for(node),
line: node.value.line,
@@ -1952,7 +1944,7 @@ impl<'a> Assembler<'a> {
},
None => {
return Err(Error {
- message: format!("unknown instruction {}", mnemonic),
+ message: format!("unknown instruction {mnemonic}"),
line: node.value.line,
source: self.source_for(node),
global: false,
diff --git a/lib/xixanta/src/cfg.rs b/lib/xixanta/src/cfg.rs
index be3a9c1..9b0600a 100644
--- a/lib/xixanta/src/cfg.rs
+++ b/lib/xixanta/src/cfg.rs
@@ -30,20 +30,17 @@ fn fetch_line_values(line: &str, line_num: usize) -> Result<(String, String), St
let mut name_values = line.split(':');
let Some(name) = name_values.next() else {
return Err(format!(
- "line does not follow 'key: values' format (line {})",
- line_num
+ "line does not follow 'key: values' format (line {line_num})"
));
};
let Some(values_line) = name_values.next() else {
return Err(format!(
- "line does not follow 'key: values' format (line {})",
- line_num
+ "line does not follow 'key: values' format (line {line_num})"
));
};
if name_values.next().is_some() {
return Err(format!(
- "line does not follow 'key: values' format (line {})",
- line_num
+ "line does not follow 'key: values' format (line {line_num})"
));
}
@@ -65,13 +62,13 @@ fn get_hex_from(
if !string.starts_with('$') {
match symbols.get(string) {
Some(value) => return Ok(*value),
- None => return Err(format!("malformed hex value (line {})", line_num)),
+ None => return Err(format!("malformed hex value (line {line_num})")),
}
}
let val = &string[1..string.len()];
if val.is_empty() || val.len() > 4 {
- return Err(format!("malformed hex value (line {})", line_num));
+ return Err(format!("malformed hex value (line {line_num})"));
}
Ok(usize::from_str_radix(val, 16).unwrap())
@@ -112,7 +109,7 @@ fn fetch_memory_definition(line: &str, line_num: usize) -> Result<RawMapping, St
_ => {}
}
}
- None => return Err(format!("malformed key-value (line {})", line_num)),
+ None => return Err(format!("malformed key-value (line {line_num})")),
}
}
@@ -143,13 +140,12 @@ fn find_value(key: &str, values: &str, line_num: usize) -> Result<String, String
return Ok(val.to_string());
}
}
- None => return Err(format!("malformed key-value (line {})", line_num)),
+ None => return Err(format!("malformed key-value (line {line_num})")),
}
}
Err(format!(
- "could not find '{}' definition (line {})",
- key, line_num
+ "could not find '{key}' definition (line {line_num})"
))
}
@@ -299,7 +295,7 @@ pub fn parse_cfg_file(text: &str) -> Result<Vec<Mapping>, String> {
fn get_segments_from(value: &str, line: usize) -> Result<Vec<Segment>, String> {
if !value.starts_with('[') || !value.ends_with(']') {
- return Err(format!("should be enclosed inside of [] (line {})", line));
+ return Err(format!("should be enclosed inside of [] (line {line})"));
}
let mut res = vec![];
@@ -592,9 +588,7 @@ SEGMENTS {
&["HEADER"]
);
- for i in 1..=7 {
- let prg = &res[i];
-
+ for (i, prg) in res.iter().enumerate().take(7 + 1).skip(1) {
assert_eq!(prg.name, format!("PRG{}", i - 1));
assert_eq!(prg.start, 0x8000);
assert_eq!(prg.size, 0x4000);
diff --git a/lib/xixanta/src/mapping.rs b/lib/xixanta/src/mapping.rs
index 6a439d3..2270ad3 100644
--- a/lib/xixanta/src/mapping.rs
+++ b/lib/xixanta/src/mapping.rs
@@ -111,7 +111,7 @@ pub fn get_mapping_configuration(name: &str) -> Result<Vec<Mapping>, String> {
parse_cfg_file(contents.as_str())?
}
}
- Err(_) => return Err(format!("could not read '{}'", name)),
+ Err(_) => return Err(format!("could not read '{name}'")),
}
} else {
let text = match name.to_lowercase().as_str() {
@@ -190,14 +190,12 @@ pub fn validate(mappings: &[Mapping]) -> Result<(), String> {
if header_prg_rom_size < prg_rom_len {
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
+ "PRG ROM size is expected to by {header_prg_rom_size} bytes long, but a total of {prg_rom_len} bytes were evaluated"
));
}
if header_chr_rom_size < chr_rom_len {
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
+ "CHR ROM size is expected to by {header_chr_rom_size} bytes long, but a total of {chr_rom_len} bytes were evaluated"
));
}
diff --git a/lib/xixanta/src/node.rs b/lib/xixanta/src/node.rs
index 8273967..a09568c 100644
--- a/lib/xixanta/src/node.rs
+++ b/lib/xixanta/src/node.rs
@@ -308,7 +308,7 @@ impl fmt::Display for NodeType {
NodeType::Instruction => write!(f, "instruction"),
NodeType::Indirection => write!(f, "indirection"),
NodeType::Assignment => write!(f, "assignment"),
- NodeType::Control(control_type) => write!(f, "control function ({})", control_type),
+ NodeType::Control(control_type) => write!(f, "control function ({control_type})"),
NodeType::ControlBody => write!(f, "control function body"),
NodeType::Literal => write!(f, "literal"),
NodeType::Label => write!(f, "label"),
diff --git a/lib/xixanta/src/object.rs b/lib/xixanta/src/object.rs
index a92f9fb..db7c51e 100644
--- a/lib/xixanta/src/object.rs
+++ b/lib/xixanta/src/object.rs
@@ -232,7 +232,7 @@ impl Context {
}
}
},
- None => Err(format!("could not find scope '{}'", scope_name)),
+ None => Err(format!("could not find scope '{scope_name}'")),
}
}
@@ -253,7 +253,7 @@ impl Context {
// Avoid weird out of bound references for addresses.
if addr > u16::MAX as usize {
- return Err(format!("address {:x} is out of bounds", addr));
+ return Err(format!("address {addr:x} is out of bounds"));
}
let addr_bytes = (addr as u16).to_le_bytes();
@@ -472,7 +472,7 @@ impl Context {
// Returns a human-readable string representing the current context.
fn to_human(&self) -> String {
match self.stack.last() {
- Some(n) => format!("'{}'", n),
+ Some(n) => format!("'{n}'"),
None => "the global scope".to_string(),
}
}
@@ -487,7 +487,7 @@ impl Context {
// case.
"the current scope".to_string()
} else {
- format!("'{}'", name)
+ format!("'{name}'")
}
}
}
diff --git a/lib/xixanta/src/parser.rs b/lib/xixanta/src/parser.rs
index d6d8d6f..ba56f11 100644
--- a/lib/xixanta/src/parser.rs
+++ b/lib/xixanta/src/parser.rs
@@ -339,7 +339,7 @@ impl Parser {
line: self.line,
global: false,
source: self.sources[self.current_source].clone(),
- message: format!("{} relative label can only have '{}' characters", msg, next),
+ message: format!("{msg} relative label can only have '{next}' characters"),
});
}
self.next();
@@ -747,14 +747,14 @@ impl Parser {
Some(ec) => ec,
None => {
return Err(self
- .parser_error(format!("unexpected '{}'", real_type).as_str())
+ .parser_error(format!("unexpected '{real_type}'").as_str())
.into())
}
};
if *node_type != expected_close {
return Err(self
.parser_error(
- format!("expecting '{}', found '{}'", expected_close, node_type).as_str(),
+ format!("expecting '{expected_close}', found '{node_type}'").as_str(),
)
.into());
}
@@ -800,7 +800,7 @@ impl Parser {
line: node.value.line,
global: false,
source: current_source.clone(),
- message: format!("could not open source file '{}': {}", file_path, e),
+ message: format!("could not open source file '{file_path}': {e}"),
}
.into())
}
@@ -811,8 +811,7 @@ impl Parser {
global: false,
source: current_source.clone(),
message: format!(
- "could not find out the parent directory for file '{}'",
- file_path
+ "could not find out the parent directory for file '{file_path}'"
),
}
.into());
@@ -854,8 +853,7 @@ impl Parser {
global: false,
source: self.sources[self.current_source].clone(),
message: format!(
- "path has to be written inside of double quotes ('{}' given instead)",
- value,
+ "path has to be written inside of double quotes ('{value}' given instead)",
),
});
}
@@ -1366,7 +1364,7 @@ impl Parser {
},
'!' => match second {
'=' => Ok((Some(NodeType::Operation(OperationType::NotEqual)), 2)),
- _ => Err(self.parser_error(format!("unknown operator '!{}'", second).as_str())),
+ _ => Err(self.parser_error(format!("unknown operator '!{second}'").as_str())),
},
_ => Ok((None, 0)),
}
@@ -1538,7 +1536,7 @@ impl Parser {
Ok(PNode {
node_type: NodeType::Literal,
value: PString {
- value: format!("'{}'", ch),
+ value: format!("'{ch}'"),
line: self.line,
start: self.column - 3,
end: self.column,
@@ -2154,7 +2152,7 @@ mod tests {
#[test]
fn scoped_variable_literal_in_instruction() {
for var in vec!["Scope::Variable", "Scope::Inner::Variable"].into_iter() {
- let line = format!("lda #{}", var);
+ let line = format!("lda #{var}");
let mut parser = Parser::default();
assert!(parser.parse(line.as_bytes(), SourceInfo::default()).is_ok());
@@ -2167,7 +2165,7 @@ mod tests {
&node.left.clone().unwrap(),
NodeType::Literal,
line.as_str(),
- format!("#{}", var).as_str(),
+ format!("#{var}").as_str(),
);
}
}
@@ -2201,7 +2199,7 @@ mod tests {
#[test]
fn relative_labels() {
for label in vec![":+", ":++", ":+++ ", ":++++", ":-", ":--", ":---", ":----"].into_iter() {
- let line = format!("jmp {}", label);
+ let line = format!("jmp {label}");
let mut parser = Parser::default();
assert!(parser.parse(line.as_bytes(), SourceInfo::default()).is_ok());