fixed some clippy errors
This commit is contained in:
Vendored
+1
-1
@@ -2,4 +2,4 @@
|
||||
"rust-analyzer.check.command": "clippy",
|
||||
"editor.formatOnSave": true,
|
||||
"rust-analyzer.cargo.features": "all"
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
use common::{
|
||||
args, instructions,
|
||||
args,
|
||||
prelude::{ITypeArgs, Instruction, Interrupt, RTypeArgs, Register},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
AssembleError, expect_token, expect_type,
|
||||
model::{Node, Opcode, Token, TokenType},
|
||||
AssembleError, Token, TokenType, expect_token,
|
||||
model::{Node, Opcode},
|
||||
};
|
||||
|
||||
pub fn codegen(nodes: Vec<Node>) -> Result<Vec<Instruction>, AssembleError> {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use common::prelude::Register;
|
||||
|
||||
use crate::{
|
||||
AssembleError, dsa, expect_token, expect_type,
|
||||
AssembleError, expect_token, expect_type,
|
||||
model::{Node, Opcode, Token, TokenType},
|
||||
node,
|
||||
};
|
||||
@@ -13,7 +13,7 @@ pub fn expand_pseudo_ops(
|
||||
let mut result = Vec::<Node>::with_capacity(nodes.len());
|
||||
|
||||
for node in nodes.iter_mut() {
|
||||
if let Err(_) = try_expand(node.clone(), &mut result, module) {
|
||||
if try_expand(node.clone(), &mut result, module).is_err() {
|
||||
result.push(node.clone());
|
||||
}
|
||||
}
|
||||
@@ -22,9 +22,9 @@ pub fn expand_pseudo_ops(
|
||||
}
|
||||
|
||||
fn try_expand(
|
||||
mut node: Node,
|
||||
node: Node,
|
||||
result: &mut Vec<Node>,
|
||||
module: u64,
|
||||
_module: u64,
|
||||
) -> Result<(), AssembleError> {
|
||||
match node.opcode() {
|
||||
Opcode::Push => expand_push(node.clone(), result)?,
|
||||
|
||||
+3
-33
@@ -1,9 +1,9 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use common::prelude::{Instruction, Register};
|
||||
use common::prelude::Register;
|
||||
|
||||
use crate::model::{Module, Node, Opcode, Symbol, Token, TokenType};
|
||||
use crate::{AssembleError, dsa, expect_token, expect_type, node, quick_hash};
|
||||
use crate::model::{Node, Opcode, Token, TokenType};
|
||||
use crate::{AssembleError, expect_token, expect_type, node};
|
||||
|
||||
pub struct Parser {
|
||||
tokens: Vec<Token>,
|
||||
@@ -302,34 +302,4 @@ impl Parser {
|
||||
Ok(self.tokens.last().unwrap().clone())
|
||||
}
|
||||
}
|
||||
|
||||
fn expect(&mut self, type_: TokenType) -> Result<Token, AssembleError> {
|
||||
let tok = self.next()?;
|
||||
|
||||
if TokenType::from_token(&tok) == type_ {
|
||||
Ok(tok)
|
||||
} else {
|
||||
Err(AssembleError::UnexpectedToken(tok, type_))
|
||||
}
|
||||
}
|
||||
|
||||
fn expect_any(&mut self, types: &[TokenType]) -> Result<Token, AssembleError> {
|
||||
let tok = self.next()?;
|
||||
|
||||
if types.contains(&TokenType::from_token(&tok)) {
|
||||
Ok(tok)
|
||||
} else {
|
||||
Err(AssembleError::UnexpectedToken(tok, types[0]))
|
||||
}
|
||||
}
|
||||
|
||||
fn maybe_expect(&mut self, types: &[TokenType]) -> Option<Token> {
|
||||
let tok = self.peek_next().ok()?;
|
||||
|
||||
if types.contains(&TokenType::from_token(&tok)) {
|
||||
Some(tok.clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ use crate::{
|
||||
};
|
||||
|
||||
pub fn resolve_symbols(nodes: &mut Vec<Node>) -> Result<(), AssembleError> {
|
||||
let symbol_table = generate_symbol_table(&nodes)?;
|
||||
let symbol_table = generate_symbol_table(nodes)?;
|
||||
|
||||
for node in nodes.iter_mut() {
|
||||
match node.opcode() {
|
||||
|
||||
@@ -414,8 +414,8 @@ impl std::fmt::Display for Instruction {
|
||||
|
||||
Self::Increment(a) | Self::Decrement(a) => write!(f, " {}", a.sr1),
|
||||
Self::Interrupt(a) => write!(f, " {}", a.as_u8()),
|
||||
Self::Data(a) => write!(f, " {}", a),
|
||||
Self::Segment(x) => write!(f, " [SEGMENT {}]", x),
|
||||
Self::Data(a) => write!(f, " {a}"),
|
||||
Self::Segment(x) => write!(f, " [SEGMENT {x}]"),
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
@@ -469,7 +469,7 @@ impl TryFrom<u32> for Instruction {
|
||||
0x24 => Ok(Self::Halt),
|
||||
0x25 => Ok(Self::AddImmediate(ITypeArgs::try_from(data)?)),
|
||||
0x26 => Ok(Self::SubImmediate(ITypeArgs::try_from(data)?)),
|
||||
0x3F => Ok(Self::Segment(data as u8 as u32)),
|
||||
0x3F => Ok(Self::Segment(u32::from(data as u8))),
|
||||
_ => Err(InstructionDecodeError::InvalidOpcode(opcode)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ impl Encode for Instruction {
|
||||
Self::Segment(segment) => {
|
||||
let opcode = u32::from(self.opcode());
|
||||
let segment = segment as u8;
|
||||
(opcode << 26) | (segment as u32)
|
||||
(opcode << 26) | u32::from(segment)
|
||||
}
|
||||
]
|
||||
)
|
||||
|
||||
@@ -5,7 +5,7 @@ fn test_encode_nop() {
|
||||
let no_reg = Register::NoReg as u32;
|
||||
let no_op = u32::from(Instruction::Nop.opcode());
|
||||
|
||||
let expected = no_op << 26 | no_reg << 21 | no_reg << 16 | no_reg << 11;
|
||||
let expected = (no_op << 26) | (no_reg << 21) | (no_reg << 16) | (no_reg << 11);
|
||||
let got = Instruction::Nop.encode();
|
||||
|
||||
assert_eq!(expected, got);
|
||||
@@ -25,7 +25,7 @@ fn test_encode_mov() {
|
||||
));
|
||||
let mov = u32::from(instruction.opcode());
|
||||
|
||||
let expected = mov << 26 | rg0 << 21 | no_reg << 16 | rg1 << 11;
|
||||
let expected = (mov << 26) | (rg0 << 21) | (no_reg << 16) | (rg1 << 11);
|
||||
let got = instruction.encode();
|
||||
|
||||
assert_eq!(expected, got);
|
||||
@@ -44,7 +44,7 @@ fn test_encode_load_byte() {
|
||||
));
|
||||
let load_byte = u32::from(instruction.opcode());
|
||||
|
||||
let expected = load_byte << 26 | rg0 << 21 | rg1 << 16 | u32::from(immediate);
|
||||
let expected = (load_byte << 26) | (rg0 << 21) | (rg1 << 16) | u32::from(immediate);
|
||||
let got = instruction.encode();
|
||||
|
||||
assert_eq!(expected, got);
|
||||
@@ -65,8 +65,11 @@ fn test_encode_shift_left_shamt() {
|
||||
));
|
||||
let shift_left = u32::from(instruction.opcode());
|
||||
|
||||
let expected =
|
||||
shift_left << 26 | rg0 << 21 | no_reg << 16 | no_reg << 11 | u32::from(shift_amount) << 6;
|
||||
let expected = (shift_left << 26)
|
||||
| (rg0 << 21)
|
||||
| (no_reg << 16)
|
||||
| (no_reg << 11)
|
||||
| (u32::from(shift_amount) << 6);
|
||||
|
||||
let got = instruction.encode();
|
||||
|
||||
@@ -87,7 +90,7 @@ fn test_encode_shift_left_reg() {
|
||||
));
|
||||
let shift_left = u32::from(instruction.opcode());
|
||||
|
||||
let expected = shift_left << 26 | rg0 << 21 | rg1 << 16 | no_reg << 11;
|
||||
let expected = (shift_left << 26) | (rg0 << 21) | (rg1 << 16) | (no_reg << 11);
|
||||
|
||||
let got = instruction.encode();
|
||||
|
||||
|
||||
@@ -246,7 +246,7 @@ impl CodeEditor {
|
||||
text: &mut dyn egui::TextBuffer,
|
||||
) -> TextEditOutput {
|
||||
let mut text_edit_output: Option<TextEditOutput> = None;
|
||||
let mut code_editor = |ui: &mut egui::Ui| {
|
||||
let code_editor = |ui: &mut egui::Ui| {
|
||||
ui.horizontal_top(|h| {
|
||||
self.theme.modify_style(h, self.fontsize);
|
||||
if self.numlines {
|
||||
|
||||
Reference in New Issue
Block a user