Skip to content

Commit

Permalink
[bndbuild] Add snapsjot command to the list
Browse files Browse the repository at this point in the history
  • Loading branch information
Krusty/Benediction committed Nov 23, 2024
1 parent 3ce0b36 commit 2061512
Show file tree
Hide file tree
Showing 19 changed files with 610 additions and 472 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 27 additions & 20 deletions cpclib-asm/src/assembler/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,27 @@ impl<'a, 'b> From<(&'a str, &'b Env)> for Fname<'a, 'b> {
}
}


pub enum AnyFileNameOwned {
InImage { image: String, content: String },
Standard(String)
}

impl<'fname> From<&AnyFileName<'fname>> for AnyFileNameOwned {
impl<'fname> From<&AnyFileName<'fname>> for AnyFileNameOwned {
fn from(value: &AnyFileName) -> Self {
match value {
AnyFileName::InImage { image, content } => Self::new_in_image(*image, *content),
AnyFileName::Standard(content) => Self::new_standard(*content),
AnyFileName::Standard(content) => Self::new_standard(*content)
}
}
}

impl<'fname> From<&'fname AnyFileNameOwned> for AnyFileName<'fname> {
fn from(value: &'fname AnyFileNameOwned) -> Self {
match value {
AnyFileNameOwned::InImage { image, content: amsdos } => {
AnyFileNameOwned::InImage {
image,
content: amsdos
} => {
AnyFileName::InImage {
image: image.as_str(),
content: amsdos.as_str()
Expand All @@ -82,7 +84,6 @@ impl From<&str> for AnyFileNameOwned {
}
}


impl AnyFileNameOwned {
pub fn new_standard<S: Into<String>>(fname: S) -> Self {
Self::Standard(fname.into())
Expand All @@ -100,7 +101,6 @@ impl AnyFileNameOwned {
}
}


/// Helper to handler filenames that contains both a dsk name and a file
pub enum AnyFileName<'fname> {
InImage {
Expand All @@ -118,7 +118,10 @@ impl<'fname> AnyFileName<'fname> {
}

pub fn new_in_image(image: &'fname str, amsdos: &'fname str) -> Self {
Self::InImage { image, content: amsdos }
Self::InImage {
image,
content: amsdos
}
}

pub fn use_image(&self) -> bool {
Expand All @@ -128,32 +131,38 @@ impl<'fname> AnyFileName<'fname> {
}
}


pub fn image_filename(&self) -> Option<&str> {
match self {
AnyFileName::InImage { image, ..} => Some(image),
AnyFileName::Standard(_) => None,
AnyFileName::InImage { image, .. } => Some(image),
AnyFileName::Standard(_) => None
}
}

pub fn content_filename(&self) -> &str {
match self {
AnyFileName::InImage { image, content: amsdos } => amsdos,
AnyFileName::Standard(content) => content,
AnyFileName::InImage {
image,
content: amsdos
} => amsdos,
AnyFileName::Standard(content) => content
}
}

pub fn basm_fname(&self) -> Cow<str> {
match self {
AnyFileName::InImage { image, content } => Cow::Owned(format!("{}{}{}", image, Self::DSK_SEPARATOR, content)),
AnyFileName::Standard(content) => Cow::Borrowed(content),
AnyFileName::InImage { image, content } => {
Cow::Owned(format!("{}{}{}", image, Self::DSK_SEPARATOR, content))
},
AnyFileName::Standard(content) => Cow::Borrowed(content)
}
}


fn base_filename(&self) -> &str {
match self {
AnyFileName::InImage { image, content: amsdos } => image,
AnyFileName::InImage {
image,
content: amsdos
} => image,
AnyFileName::Standard(f) => f
}
}
Expand Down Expand Up @@ -216,7 +225,7 @@ impl<'fname> From<&'fname str> for AnyFileName<'fname> {
"Need to handle case where fname as several {}",
Self::DSK_SEPARATOR
)
},
}
}
}
}
Expand All @@ -228,9 +237,7 @@ pub fn get_filename_to_read<S: AsRef<str>>(
) -> Result<Utf8PathBuf, AssemblerError> {
let fname = fname.as_ref();

AnyFileName::from(fname)
.path_for_base_filename(options, env)

AnyFileName::from(fname).path_for_base_filename(options, env)
}

/// Load a file and remove header if any
Expand Down
15 changes: 5 additions & 10 deletions cpclib-asm/src/assembler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2043,9 +2043,7 @@ impl Env {
.int()? as u8;
}
if let Some(step) = step {
brk.step = Some(self
.resolve_expr_may_fail_in_first_pass(step)?
.int()? as _);
brk.step = Some(self.resolve_expr_may_fail_in_first_pass(step)?.int()? as _);
}
if let Some(condition) = condition {
let cond = self.resolve_expr_may_fail_in_first_pass(condition)?;
Expand Down Expand Up @@ -2907,16 +2905,13 @@ impl Env {

let amsdos_fname = self.build_fname(amsdos_fname)?;
let any_fname: AnyFileNameOwned = match dsk_fname {
Some(dsk_fname) => AnyFileNameOwned::new_in_image(
self.build_fname(dsk_fname)?, amsdos_fname
),
None => {
AnyFileNameOwned::from(amsdos_fname.as_str())
}
Some(dsk_fname) => {
AnyFileNameOwned::new_in_image(self.build_fname(dsk_fname)?, amsdos_fname)
},
None => AnyFileNameOwned::from(amsdos_fname.as_str())
};
let any_fname = any_fname.as_any_filename();


let (amsdos_fname, dsk_fname) = (any_fname.content_filename(), any_fname.image_filename());

let amsdos_fname = Utf8PathBuf::from(amsdos_fname);
Expand Down
3 changes: 2 additions & 1 deletion cpclib-asm/src/assembler/processed_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,8 @@ where
// Handle file loading
let fname = self.token.incbin_fname();
let fname = env.build_fname(fname)?;
let fname = get_filename_to_read(fname, options.parse_options(), Some(env))?;
let fname =
get_filename_to_read(fname, options.parse_options(), Some(env))?;

// get the data for the given file
let data = if !contents.contains_key(&fname) {
Expand Down
Loading

0 comments on commit 2061512

Please sign in to comment.