assembler: apply clippy lints

This commit is contained in:
2025-06-25 14:33:48 +01:00
parent 20a7d42adb
commit 11a57eab51
6 changed files with 43 additions and 25 deletions
+7 -1
View File
@@ -11,8 +11,14 @@ pub struct AssemblerContext {
pub module_registry: RwLock<ModuleRegistry>,
}
impl Default for AssemblerContext {
fn default() -> Self {
Self::new()
}
}
impl AssemblerContext {
pub fn new() -> Self {
#[must_use] pub fn new() -> Self {
Self {
symbol_table: RwLock::new(SymbolTable::new()),
module_registry: RwLock::new(ModuleRegistry::new()),
+6 -7
View File
@@ -15,22 +15,21 @@ use crate::model::module_registry::ModuleRegistry;
pub struct ModuleId(Uuid);
impl ModuleId {
pub fn from_module(module: Module) -> Self {
#[must_use]
pub const fn from_module(module: &Module) -> Self {
module.id
}
/// Convenience method to get the [`Module`] from a [`ModuleId`].
#[must_use]
pub fn to_module<'m>(&self, registry: &'m ModuleRegistry) -> Option<&'m Module> {
registry.get(self)
}
/// Convenience method to get the [`Module`] name from a [`ModuleId`].
pub fn to_module_name<'m>(self, registry: &'m ModuleRegistry) -> Option<&'m str> {
if let Some(module) = self.to_module(&registry) {
Some(module.name.as_str())
} else {
None
}
#[must_use]
pub fn to_module_name(self, registry: &ModuleRegistry) -> Option<&str> {
self.to_module(registry).map(|module| module.name.as_str())
}
}
+8 -2
View File
@@ -10,15 +10,21 @@ pub struct ModuleRegistry {
modules: HashMap<ModuleId, Module>,
}
impl Default for ModuleRegistry {
fn default() -> Self {
Self::new()
}
}
impl ModuleRegistry {
pub fn new() -> Self {
#[must_use] pub fn new() -> Self {
Self {
modules: HashMap::new(),
}
}
/// Gets a [`Module`] by ID.
pub fn get(&self, module_id: &ModuleId) -> Option<&Module> {
#[must_use] pub fn get(&self, module_id: &ModuleId) -> Option<&Module> {
self.modules.get(module_id)
}
+17 -10
View File
@@ -16,23 +16,28 @@ impl From<Symbol> for SymbolId {
}
}
impl Default for SymbolId {
fn default() -> Self {
Self::new()
}
}
impl SymbolId {
#[must_use]
pub fn new() -> Self {
Self(Uuid::new_v4())
}
/// Convenience method to get the [`Module`] from a [`ModuleId`].
#[must_use]
pub fn to_module<'s>(&self, registry: &'s SymbolTable) -> Option<&'s Symbol> {
registry.get(self)
}
/// Convenience method to get the [`Module`] name from a [`ModuleId`].
pub fn to_module_name<'m>(self, registry: &'m SymbolTable) -> Option<&'m str> {
if let Some(module) = self.to_module(&registry) {
Some(module.name.as_str())
} else {
None
}
#[must_use]
pub fn to_module_name(self, registry: &SymbolTable) -> Option<&str> {
self.to_module(registry).map(|module| module.name.as_str())
}
}
@@ -82,6 +87,7 @@ pub struct Symbol {
}
impl Symbol {
#[must_use]
pub fn new(
name: String,
module_id: ModuleId,
@@ -123,6 +129,7 @@ impl Symbol {
}
/// Returns whether a [`Symbol`] depends on `symbol_id`.
#[must_use]
pub fn depends_on(&self, symbol_id: &SymbolId) -> bool {
self.dependencies.contains(symbol_id)
}
@@ -140,14 +147,14 @@ impl Symbol {
#[derive(Debug, Copy, Clone)]
/// The visibility of the symbol in different object files.
pub enum Visibility {
/// STB_PUBLIC under the ELF spec. Visible in all other object files. Shall be used
/// `STB_PUBLIC` under the ELF spec. Visible in all other object files. Shall be used
/// for labels. Remember labels are namespaced in different files so they won't clash
/// with one another.
Public,
/// Only visible within this object file. STB_LOCAL under ELF spec. Shall be used for
/// data definitions unless they are marked public.
/// Only visible within this object file. `STB_LOCAL` under ELF spec. Shall be used
/// for data definitions unless they are marked public.
Local,
/// STB_WEAK under the ELF spec. Potentially unused.
/// `STB_WEAK` under the ELF spec. Potentially unused.
Weak,
}
+4 -4
View File
@@ -63,19 +63,19 @@ impl SymbolTable {
}
/// Gets the [`Symbol`] by its [`SymbolId`].
pub fn get(&self, id: &SymbolId) -> Option<&Symbol> {
#[must_use] pub fn get(&self, id: &SymbolId) -> Option<&Symbol> {
self.symbols.get(id)
}
/// Gets the [`Symbol`] by its name.
pub fn get_by_name(&self, name: &str) -> Option<&Symbol> {
#[must_use] pub fn get_by_name(&self, name: &str) -> Option<&Symbol> {
self.name_to_id
.get(name)
.and_then(|id| self.symbols.get(id))
}
/// Gets all [`Symbol`]s in a module.
pub fn get_module_symbols(&self, module_id: &ModuleId) -> Vec<&Symbol> {
#[must_use] pub fn get_module_symbols(&self, module_id: &ModuleId) -> Vec<&Symbol> {
self.module_symbols
.get(module_id)
.map(|ids| ids.iter().filter_map(|id| self.symbols.get(id)).collect())
@@ -83,7 +83,7 @@ impl SymbolTable {
}
/// Gets all the public symbols.
pub fn get_public_symbols(&self) -> Vec<&Symbol> {
#[must_use] pub fn get_public_symbols(&self) -> Vec<&Symbol> {
self.symbols
.values()
.filter(|sym| matches!(sym.visibility, Visibility::Public))
+1 -1
View File
@@ -16,7 +16,7 @@ use crate::emulator::{
ui::interface::Component,
};
use assembler::prelude::*;
// use assembler::prelude::*;
#[derive(Default)]
pub struct Editor {