Skip to content

Commit

Permalink
Apply cargo fmt & fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Krusty/Benediction committed Jan 7, 2024
1 parent ea83d2a commit efbb7b5
Show file tree
Hide file tree
Showing 13 changed files with 432 additions and 210 deletions.
10 changes: 3 additions & 7 deletions cpclib-asm/src/assembler/delayed_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,13 @@ impl BreakpointCommand {
}

pub fn winape(&self) -> WinapeBreakPoint {
WinapeBreakPoint::new(
self.address,
self.page
)
WinapeBreakPoint::new(self.address, self.page)
}


pub fn ace(&self) -> AceBreakPoint {
let brk = AceBreakPoint::new_execution(
self.address,
AceBrkRuntimeMode::Break,
self.address,
AceBrkRuntimeMode::Break,
cpclib_sna::AceMemMapType::Undefined
);
brk
Expand Down
43 changes: 32 additions & 11 deletions cpclib-asm/src/assembler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -954,11 +954,14 @@ impl Env {

// Add the symbols in the snapshot
fn handle_sna_symbols(&mut self) -> Result<(), AssemblerError> {
if ! self.options().assemble_options().get_flag(crate::AssemblingOptionFlags::SnaSymb) {
if !self
.options()
.assemble_options()
.get_flag(crate::AssemblingOptionFlags::SnaSymb)
{
return Ok(());
}


let ace_chunk = self.symbols_output.build_ace_snapshot_chunk(self.symbols());
self.sna.add_chunk(ace_chunk);

Expand All @@ -969,15 +972,26 @@ impl Env {
/// as they are stored inside a chunk of the snapshot:
/// If one day another export is coded, we could export the others too.
fn handle_breakpoints(&mut self) -> Result<(), AssemblerError> {
let mut winape_chunk = if self.options().assemble_options().get_flag(crate::AssemblingOptionFlags::SnaBrks) {
let mut winape_chunk = if self
.options()
.assemble_options()
.get_flag(crate::AssemblingOptionFlags::SnaBrks)
{
Some(WinapeBreakPointChunk::empty())
} else {
}
else {
None
};
let mut ace_chunk = if self.options().assemble_options().get_flag(crate::AssemblingOptionFlags::SnaBrkc) {
let mut ace_chunk = if self
.options()
.assemble_options()
.get_flag(crate::AssemblingOptionFlags::SnaBrkc)
{
Some(AceBreakPointChunk::empty())
}
else {None};
else {
None
};

let pages_mmr = MMR_PAGES_SELECTION;
for (activepage, _page) in pages_mmr[0..self.pages_info_sna.len()].iter().enumerate() {
Expand All @@ -990,17 +1004,24 @@ impl Env {
};
eprint!("{}", info);

winape_chunk.as_mut().map(|chunk| chunk.add_breakpoint(brk.winape()));
ace_chunk.as_mut().map(|chunk| chunk.add_breakpoint(brk.ace()));
winape_chunk
.as_mut()
.map(|chunk| chunk.add_breakpoint(brk.winape()));
ace_chunk
.as_mut()
.map(|chunk| chunk.add_breakpoint(brk.ace()));
}
}


if let Some(chunk) = winape_chunk && chunk.nb_breakpoints() > 0 {
if let Some(chunk) = winape_chunk
&& chunk.nb_breakpoints() > 0
{
self.sna.add_chunk(chunk);
}

if let Some(chunk) = ace_chunk && chunk.nb_breakpoints() > 0 {
if let Some(chunk) = ace_chunk
&& chunk.nb_breakpoints() > 0
{
self.sna.add_chunk(chunk);
}

Expand Down
10 changes: 7 additions & 3 deletions cpclib-asm/src/assembler/symbols_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::io::Write;
use std::str::FromStr;

use cpclib_common::itertools::Itertools;
use cpclib_sna::{AceSymbolChunk, AceSymbol, AceSymbolType};
use cpclib_sna::{AceSymbol, AceSymbolChunk, AceSymbolType};
use cpclib_tokens::symbols::{Symbol, SymbolsTableTrait, Value};
use cpclib_tokens::ExprResult;

Expand Down Expand Up @@ -136,12 +136,16 @@ impl SymbolOutputGenerator {
// TODO properly create the value by specifying a correct mem map type and symb type
// store if we have a representation
if let Some(v) = v {
let symb = AceSymbol::new(&k, v, cpclib_sna::AceMemMapType::Undefined, AceSymbolType::Absolute);
let symb = AceSymbol::new(
&k,
v,
cpclib_sna::AceMemMapType::Undefined,
AceSymbolType::Absolute
);
symbols.push(symb);
}
}


let mut chunk = AceSymbolChunk::empty();
chunk.add_symbols(symbols.into_iter());
chunk
Expand Down
11 changes: 6 additions & 5 deletions cpclib-asm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ use std::sync::{Arc, RwLock};

use cpclib_disc::amsdos::*;
use cpclib_sna::Snapshot;
use enumflags2::{bitflags, make_bitflags, BitFlags};
use preamble::function::FunctionBuilder;
use preamble::processed_token::ProcessedToken;
use preamble::*;

use self::listing_output::ListingOutput;
use enumflags2::{bitflags, make_bitflags, BitFlags};

#[bitflags]
#[repr(u8)]
Expand All @@ -59,7 +59,6 @@ pub enum AssemblingOptionFlags {
SnaBrkc
}


impl AssemblingOptionFlags {
pub fn from_chunk(chunk: &str) -> Option<Self> {
match chunk {
Expand All @@ -74,21 +73,23 @@ impl AssemblingOptionFlags {
/// Configuration of the assembler. By default the assembler is case sensitive and has no symbol
#[derive(Debug, Clone)]
pub struct AssemblingOptions {

flags: BitFlags<AssemblingOptionFlags>,

/// Contains some symbols that could be used during assembling
symbols: cpclib_tokens::symbols::SymbolsTable,
output_builder: Option<Arc<RwLock<ListingOutput>>>,
/// The snapshot may be prefiled with a dedicated snapshot
snapshot_model: Option<Snapshot>,
amsdos_behavior: AmsdosAddBehavior,
amsdos_behavior: AmsdosAddBehavior
}

impl Default for AssemblingOptions {
fn default() -> Self {
Self {
flags: AssemblingOptionFlags::CaseSensitive | AssemblingOptionFlags::SnaBrkc | AssemblingOptionFlags::SnaBrks | AssemblingOptionFlags::SnaSymb,
flags: AssemblingOptionFlags::CaseSensitive
| AssemblingOptionFlags::SnaBrkc
| AssemblingOptionFlags::SnaBrks
| AssemblingOptionFlags::SnaSymb,
symbols: cpclib_tokens::symbols::SymbolsTable::default(),
output_builder: None,
snapshot_model: None,
Expand Down
6 changes: 3 additions & 3 deletions cpclib-basm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ use std::str::FromStr;
use cpclib_asm::assembler::file::get_filename;
use cpclib_asm::preamble::file::read_source;
use cpclib_asm::preamble::symbols_output::SymbolOutputFormat;
use cpclib_asm::{preamble::*, AssemblingOptionFlags};
use cpclib_asm::preamble::*;
use cpclib_asm::progress::{normalize, Progress};
use cpclib_asm::AssemblingOptionFlags;
use cpclib_common::clap::builder::{PossibleValue, PossibleValuesParser};
use cpclib_common::clap::{Arg, ArgAction, ArgGroup, ArgMatches, Command, ValueHint};
use cpclib_common::itertools::Itertools;
Expand Down Expand Up @@ -196,7 +197,7 @@ pub fn assemble<'arg>(
let _show_progress = matches.get_flag("PROGRESS");

let mut assemble_options = AssemblingOptions::default();

assemble_options.set_case_sensitive(!matches.get_flag("CASE_INSENSITIVE"));

if matches.get_flag("OVERRIDE") {
Expand All @@ -217,7 +218,6 @@ pub fn assemble<'arg>(
}
}


// TODO add symbols if any
if let Some(files) = matches.get_many::<String>("LOAD_SYMBOLS") {
for path in files {
Expand Down
2 changes: 1 addition & 1 deletion cpclib-disc/src/amsdos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::convert::{TryFrom, TryInto};
use std::fs::File;
use std::io::Read;
use std::iter::Iterator;
use std::path::{Path};
use std::path::Path;

use arrayref::array_ref;
use cpclib_common::bitfield::Bit;
Expand Down
2 changes: 0 additions & 2 deletions cpclib-disc/src/disc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::path::Path;



use crate::amsdos::{
AmsdosAddBehavior, AmsdosError, AmsdosFile, AmsdosFileName, AmsdosManagerMut,
AmsdosManagerNonMut
Expand Down
Loading

0 comments on commit efbb7b5

Please sign in to comment.