misc: apply clippy lints

This commit is contained in:
2025-06-19 15:51:23 +01:00
parent c1d72e8d4c
commit 81433dcbcd
17 changed files with 134 additions and 127 deletions
+29 -32
View File
@@ -6,7 +6,7 @@ use std::{
path::{Path, PathBuf},
};
use common::prelude::Instruction;
use common::prelude::*;
use crate::{
codegen::codegen,
@@ -38,7 +38,7 @@ pub fn assemble(src: &Path) -> Result<Vec<Instruction>, AssembleError> {
let instructions = codegen(nodes)?;
for inst in instructions.iter() {
println!("{}", inst);
println!("{inst}");
}
Ok(instructions)
@@ -87,7 +87,7 @@ fn prepare_dependency(
);
for n in nodes.iter() {
println!("{}", n);
println!("{n}");
}
program.add_module(nodes);
@@ -161,86 +161,83 @@ fn log(message: &str) {
// create a macro that lexes and parses the input string into Nodes
#[macro_export]
#[macro_use]
macro_rules! dsa {
// Version with formatting arguments
($hash:expr, $input:expr, $($args:expr),+) => {{
let input = format!($input, $($args),+);
let tokens = crate::lexer::lexer(input, $hash)?;
let parsed = crate::parser::Parser::parse_nodes(tokens)?;
let tokens = $crate::lexer::lexer(input, $hash)?;
let parsed = $crate::parser::Parser::parse_nodes(tokens)?;
parsed
}};
// Version without formatting
($hash:expr, $input:expr) => {{
let input = String::from($input);
let tokens = crate::lexer::lexer(input, $hash)?;
let parsed = crate::parser::Parser::parse_nodes(tokens)?;
let tokens = $crate::lexer::lexer(input, $hash)?;
let parsed = $crate::parser::Parser::parse_nodes(tokens)?;
parsed
}};
}
#[macro_export]
#[macro_use]
macro_rules! expect_token {
($token:expr, Symbol) => {
match $token {
Token::Symbol(value) => Ok(value.clone()),
other => Err(AssembleError::UnexpectedToken(
$crate::model::Token::Symbol(value) => Ok(value.clone()),
other => Err($crate::AssembleError::UnexpectedToken(
other.clone(),
TokenType::Symbol,
$crate::model::TokenType::Symbol,
)),
}
};
($token:expr, Register) => {
match $token {
Token::Register(value) => Ok(value.clone()),
other => Err(AssembleError::UnexpectedToken(
$crate::model::Token::Register(value) => Ok(value.clone()),
other => Err($crate::AssembleError::UnexpectedToken(
other.clone(),
TokenType::Register,
$crate::model::TokenType::Register,
)),
}
};
($token:expr, Immediate) => {
match $token {
Token::Immediate(value) => Ok(value.clone()),
other => Err(AssembleError::UnexpectedToken(
$crate::model::Token::Immediate(value) => Ok(value.clone()),
other => Err($crate::AssembleError::UnexpectedToken(
other.clone(),
TokenType::Immediate,
$crate::model::TokenType::Immediate,
)),
}
};
($token:expr, StringLit) => {
match $token {
Token::StringLit(value) => Ok(value.clone()),
other => Err(AssembleError::UnexpectedToken(
$crate::model::Token::StringLit(value) => Ok(value.clone()),
other => Err($crate::AssembleError::UnexpectedToken(
other.clone(),
TokenType::StringLit,
$crate::model::TokenType::StringLit,
)),
}
};
($token:expr, Opcode) => {
match $token {
Token::Opcode(value) => Ok(value.clone()),
other => Err(AssembleError::UnexpectedToken(
$crate::model::Token::Opcode(value) => Ok(value.clone()),
other => Err($crate::AssembleError::UnexpectedToken(
other.clone(),
TokenType::Opcode,
$crate::model::TokenType::Opcode,
)),
}
};
}
#[macro_export]
#[macro_use]
macro_rules! expect_type {
($token:expr, $($variant:ident),+) => {{
let token = $token;
match &token {
$(
Token::$variant(_) => Ok(token.clone()),
$crate::model::Token::$variant(_) => Ok(token.clone()),
)+
other => {
let expected_type = expect_type!(@get_first_type $($variant),+);
Err(AssembleError::UnexpectedToken(
Err($crate::AssembleError::UnexpectedToken(
other.clone().clone(),
expected_type,
))
@@ -248,9 +245,9 @@ macro_rules! expect_type {
}
}};
(@get_first_type Symbol $(, $rest:ident)*) => { TokenType::Symbol };
(@get_first_type Register $(, $rest:ident)*) => { TokenType::Register };
(@get_first_type Immediate $(, $rest:ident)*) => { TokenType::Immediate };
(@get_first_type StringLit $(, $rest:ident)*) => { TokenType::StringLit };
(@get_first_type Opcode $(, $rest:ident)*) => { TokenType::Opcode };
(@get_first_type Symbol $(, $rest:ident)*) => { $crate::model::TokenType::Symbol };
(@get_first_type Register $(, $rest:ident)*) => { $crate::model::TokenType::Register };
(@get_first_type Immediate $(, $rest:ident)*) => { $crate::model::TokenType::Immediate };
(@get_first_type StringLit $(, $rest:ident)*) => { $crate::model::TokenType::StringLit };
(@get_first_type Opcode $(, $rest:ident)*) => { $crate::model::TokenType::Opcode };
}