Skip to content

Commit fa041d2

Browse files
author
Krusty/Benediction
committed
[copilot edited] Make basm compilable with rust release instead of rust nightly
1 parent 0f8800e commit fa041d2

8 files changed

Lines changed: 141 additions & 145 deletions

File tree

cpclib-asm/src/assembler/mod.rs

Lines changed: 62 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -735,11 +735,7 @@ impl Env {
735735
Err(e) => {
736736
match &*e {
737737
// the parser consider file.ext to be a label ... because it could ! So if it is not the case we need to fallback
738-
AssemblerError::UnknownSymbol { symbol, .. }
739-
| AssemblerError::RelocatedError {
740-
error: box AssemblerError::UnknownSymbol { symbol, .. },
741-
..
742-
} => {
738+
AssemblerError::UnknownSymbol { symbol, .. } => {
743739
let exp_str = exp.to_string();
744740
// Case-insensitive comparison since symbol names may be normalized (uppercased)
745741
if exp_str.eq_ignore_ascii_case(symbol.as_str()) {
@@ -749,6 +745,21 @@ impl Env {
749745
Err(e)
750746
}
751747
},
748+
AssemblerError::RelocatedError { error, .. } => {
749+
if let AssemblerError::UnknownSymbol { symbol, .. } = error.as_ref() {
750+
let exp_str = exp.to_string();
751+
// Case-insensitive comparison since symbol names may be normalized (uppercased)
752+
if exp_str.eq_ignore_ascii_case(symbol.as_str()) {
753+
Ok(exp_str.into())
754+
}
755+
else {
756+
Err(e)
757+
}
758+
}
759+
else {
760+
Err(e)
761+
}
762+
},
752763
_ => Err(e)
753764
}
754765
}
@@ -1399,11 +1410,14 @@ impl Env {
13991410
(_, Ok(_)) => {
14001411
// nothing to do
14011412
},
1402-
(
1403-
Some(box AssemblerError::MultipleErrors { errors: e1 }),
1404-
Err(box AssemblerError::MultipleErrors { errors: mut e2 })
1405-
) => {
1406-
e1.append(&mut e2);
1413+
(Some(existing), Err(new_err)) => match (existing.as_mut(), *new_err) {
1414+
(
1415+
AssemblerError::MultipleErrors { errors: e1 },
1416+
AssemblerError::MultipleErrors { errors: mut e2 }
1417+
) => {
1418+
e1.append(&mut e2);
1419+
},
1420+
_ => unimplemented!()
14071421
},
14081422
(None, Err(l_errors)) => {
14091423
assert_failures = Some(l_errors);
@@ -1460,11 +1474,14 @@ impl Env {
14601474
(_, Ok(_)) => {
14611475
// nothing to do
14621476
},
1463-
(
1464-
Some(box AssemblerError::MultipleErrors { errors: e1 }),
1465-
Err(box AssemblerError::MultipleErrors { errors: mut e2 })
1466-
) => {
1467-
e1.append(&mut e2);
1477+
(Some(existing), Err(new_err)) => match (existing.as_mut(), *new_err) {
1478+
(
1479+
AssemblerError::MultipleErrors { errors: e1 },
1480+
AssemblerError::MultipleErrors { errors: mut e2 }
1481+
) => {
1482+
e1.append(&mut e2);
1483+
},
1484+
_ => unreachable!()
14681485
},
14691486
(None, Err(l_errors)) => {
14701487
print_errors = Some(l_errors);
@@ -2523,13 +2540,10 @@ impl Env {
25232540
};
25242541

25252542
// Try to fallback on a macro call - parser is not that much great
2526-
if let Err(box AssemblerError::AlreadyDefinedSymbol {
2527-
symbol: _,
2528-
kind,
2529-
here: _
2530-
}) = &res
2531-
{
2532-
if kind == "macro" || kind == "struct" {
2543+
if let Err(err) = &res {
2544+
if let AssemblerError::AlreadyDefinedSymbol { kind, .. } = err.as_ref()
2545+
&& (kind == "macro" || kind == "struct")
2546+
{
25332547
let message = AssemblerError::AssemblingError {
25342548
msg:
25352549
"Use (void) for macros or structs with no parameters to disambiguate them with labels"
@@ -2548,15 +2562,11 @@ impl Env {
25482562
&macro_token,
25492563
std::sync::Arc::new(std::sync::RwLock::new(self))
25502564
)?;
2551-
processed_token.visited(self)
2552-
}
2553-
else {
2554-
res
2565+
return processed_token.visited(self);
25552566
}
25562567
}
2557-
else {
2558-
res
2559-
}
2568+
2569+
res
25602570
}
25612571

25622572
fn visit_noexport<S: AsRef<str> + Display>(
@@ -3508,11 +3518,13 @@ impl Env {
35083518
// Handle errors: some errors (like unknown symbols) can be deferred to next pass
35093519
if let Err(e) = assembly_result {
35103520
// Check if this is a recoverable error that might be resolved in a later pass
3511-
let is_recoverable = matches!(
3512-
&*e,
3513-
AssemblerError::UnknownSymbol { .. }
3514-
| AssemblerError::RelocatedError { error: box AssemblerError::UnknownSymbol { .. }, .. }
3515-
);
3521+
let is_recoverable = match e.as_ref() {
3522+
AssemblerError::UnknownSymbol { .. } => true,
3523+
AssemblerError::RelocatedError { error, .. } => {
3524+
matches!(error.as_ref(), AssemblerError::UnknownSymbol { .. })
3525+
},
3526+
_ => false
3527+
};
35163528

35173529
// In first pass or if error is recoverable, defer it and request additional pass
35183530
if crunched_env.pass.is_first_pass() || is_recoverable {
@@ -4788,15 +4800,20 @@ impl Env {
47884800

47894801
(
47904802
AssemblerError::RelocatedWarning {
4791-
warning: box AssemblerWarning::OverrideMemory(prev_addr, prev_size),
4803+
warning: prev_warning,
47924804
span: prev_span
47934805
},
47944806
AssemblerError::RelocatedWarning {
4795-
warning: box AssemblerWarning::OverrideMemory(curr_addr, curr_size),
4807+
warning: curr_warning,
47964808
span: curr_span
47974809
}
47984810
) => {
4799-
if (prev_addr.offset_in_cpc() + *prev_size as u32 == curr_addr.offset_in_cpc())
4811+
if let (
4812+
AssemblerWarning::OverrideMemory(prev_addr, prev_size),
4813+
AssemblerWarning::OverrideMemory(curr_addr, curr_size)
4814+
) = (prev_warning.as_ref(), curr_warning.as_ref())
4815+
&& (prev_addr.offset_in_cpc() + *prev_size as u32
4816+
== curr_addr.offset_in_cpc())
48004817
&& std::ptr::eq(
48014818
prev_span.complete_source().as_ptr(),
48024819
curr_span.complete_source().as_ptr()
@@ -4837,13 +4854,15 @@ impl Env {
48374854

48384855
if let Some(new_size) = new_size {
48394856
if let Some(new_span) = new_span {
4840-
if let AssemblerError::RelocatedWarning {
4841-
warning: box AssemblerWarning::OverrideMemory(_prev_addr, prev_size),
4842-
span
4843-
} = &mut *self.warnings[previous_warning_idx]
4857+
if let AssemblerError::RelocatedWarning { warning, span } =
4858+
&mut *self.warnings[previous_warning_idx]
48444859
{
4845-
*prev_size = new_size;
4846-
*span = new_span;
4860+
if let AssemblerWarning::OverrideMemory(_prev_addr, prev_size) =
4861+
warning.as_mut()
4862+
{
4863+
*prev_size = new_size;
4864+
*span = new_span;
4865+
}
48474866
}
48484867
}
48494868
else if let AssemblerWarning::OverrideMemory(_prev_addr, prev_size) =

cpclib-asm/src/assembler/processed_token.rs

Lines changed: 64 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::borrow::{Borrow, Cow};
22
use std::cell::OnceCell;
3+
use std::collections::btree_map::Entry;
34
use std::collections::{BTreeMap, HashMap};
45
use std::fmt::{Debug, Formatter};
56
use std::ops::Deref;
@@ -154,42 +155,38 @@ impl IncludeState {
154155
let env_guard = env.read().unwrap();
155156
env_guard.options().clone()
156157
};
157-
let state: &mut IncludeStateInner = if !self.0.contains_key(fname) {
158-
let content = read_source(fname.clone(), options.parse_options())?;
158+
let state: &mut IncludeStateInner = match self.0.entry(fname.clone()) {
159+
Entry::Occupied(entry) => entry.into_mut(),
160+
Entry::Vacant(entry) => {
161+
let content = read_source(fname.clone(), options.parse_options())?;
159162

160-
if options.show_progress() {
161-
Progress::progress().add_parse(progress::normalize(fname));
162-
}
163+
if options.show_progress() {
164+
Progress::progress().add_parse(progress::normalize(fname));
165+
}
163166

164-
let builder = options
165-
.clone()
166-
.context_builder()
167-
.set_current_filename(fname.clone());
167+
let builder = options
168+
.clone()
169+
.context_builder()
170+
.set_current_filename(fname.clone());
168171

169-
let listing = parse_z80_with_context_builder(content, builder)?;
172+
let listing = parse_z80_with_context_builder(content, builder)?;
170173

171-
// Remove the progression
172-
if options.show_progress() {
173-
Progress::progress().remove_parse(progress::normalize(fname));
174-
}
174+
// Remove the progression
175+
if options.show_progress() {
176+
Progress::progress().remove_parse(progress::normalize(fname));
177+
}
175178

176-
let include_state = IncludeStateInnerTryBuilder {
177-
listing,
178-
processed_tokens_builder: |listing: &LocatedListing| {
179-
// Minimize lock scope: clone Arc, do not hold lock across call
180-
build_processed_tokens_list(listing.as_slice(), env.clone())
179+
let include_state = IncludeStateInnerTryBuilder {
180+
listing,
181+
processed_tokens_builder: |listing: &LocatedListing| {
182+
// Minimize lock scope: clone Arc, do not hold lock across call
183+
build_processed_tokens_list(listing.as_slice(), env.clone())
184+
}
181185
}
182-
}
183-
.try_build()?;
186+
.try_build()?;
184187

185-
self.0
186-
.try_insert(fname.clone(), include_state)
187-
.expect("BUG: fname should not already be in include map")
188-
}
189-
else {
190-
self.0
191-
.get_mut(fname)
192-
.expect("BUG: fname should exist in include map")
188+
entry.insert(include_state)
189+
}
193190
};
194191

195192
// handle the listing
@@ -1172,49 +1169,46 @@ where
11721169
}
11731170

11741171
// get the data for the given file
1175-
let data = if !contents.contains_key(&fname) {
1176-
// need to load the file
1177-
1178-
let (data, header) =
1179-
load_file(fname.as_path(), env.options().parse_options())?;
1180-
1181-
if let Some(header) = header {
1182-
let ams_fname = header
1183-
.amsdos_filename()
1184-
.map(|ams_fname| ams_fname.filename_with_user())
1185-
.unwrap_or_else(|_| "<WRONG FILENAME>".to_owned());
1186-
let txt = match header.file_type() {
1187-
Ok(AmsdosFileType::Binary) => {
1188-
format! {"{to_print_fname}|{ams_fname} BINARY L:0x{:x} X:0x{:x}", header.loading_address(), header.execution_address()}
1189-
},
1190-
Ok(AmsdosFileType::Protected) => {
1191-
format! {"{to_print_fname}|{ams_fname} PROTECTED L:0x{:x} X:0x{:x}", header.loading_address(), header.execution_address()}
1192-
},
1193-
Ok(AmsdosFileType::Basic) => format!("{ams_fname} BASIC"),
1194-
Err(_) => format!("{ams_fname} <WRONG FILETYPE>")
1195-
};
1196-
1197-
let warning = AssemblerWarning::AssemblingError {
1198-
msg: format!("Header has been removed for {txt}")
1199-
};
1200-
let warning = if let Some(span) = possible_span {
1201-
warning.locate_warning(span.clone())
1172+
let data = match contents.entry(fname.clone()) {
1173+
Entry::Occupied(entry) => entry.into_mut(),
1174+
Entry::Vacant(entry) => {
1175+
// need to load the file
1176+
let (data, header) =
1177+
load_file(fname.as_path(), env.options().parse_options())?;
1178+
1179+
if let Some(header) = header {
1180+
let ams_fname = header
1181+
.amsdos_filename()
1182+
.map(|ams_fname| ams_fname.filename_with_user())
1183+
.unwrap_or_else(|_| "<WRONG FILENAME>".to_owned());
1184+
let txt = match header.file_type() {
1185+
Ok(AmsdosFileType::Binary) => {
1186+
format! {"{to_print_fname}|{ams_fname} BINARY L:0x{:x} X:0x{:x}", header.loading_address(), header.execution_address()}
1187+
},
1188+
Ok(AmsdosFileType::Protected) => {
1189+
format! {"{to_print_fname}|{ams_fname} PROTECTED L:0x{:x} X:0x{:x}", header.loading_address(), header.execution_address()}
1190+
},
1191+
Ok(AmsdosFileType::Basic) => {
1192+
format!("{ams_fname} BASIC")
1193+
},
1194+
Err(_) => format!("{ams_fname} <WRONG FILETYPE>")
1195+
};
1196+
1197+
let warning = AssemblerWarning::AssemblingError {
1198+
msg: format!("Header has been removed for {txt}")
1199+
};
1200+
let warning = if let Some(span) = possible_span {
1201+
warning.locate_warning(span.clone())
1202+
}
1203+
else {
1204+
warning
1205+
};
1206+
1207+
env.add_warning(Box::new(warning))
12021208
}
1203-
else {
1204-
warning
1205-
};
12061209

1207-
env.add_warning(Box::new(warning))
1210+
entry.insert(data.into())
12081211
}
1209-
1210-
contents
1211-
.try_insert(fname.clone(), data.into())
1212-
.expect("BUG: fname should not already be in incbin contents")
1213-
}
1214-
else {
1215-
contents
1216-
.get(&fname)
1217-
.expect("BUG: fname should exist in incbin contents")
12181212
};
12191213

12201214
let mut data = data.as_slice();
@@ -1450,7 +1444,7 @@ where
14501444
Ok(())
14511445
},
14521446

1453-
Some(ProcessedTokenState::Warning(box token)) => {
1447+
Some(ProcessedTokenState::Warning(token)) => {
14541448
let warning = AssemblerError::RelocatedWarning {
14551449
warning: Box::new(AssemblerError::AssemblingError {
14561450
msg: self.token.warning_message().to_owned()

cpclib-asm/src/lib.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
#![deny(deprecated)]
2-
#![feature(specialization)]
3-
#![feature(exact_size_is_empty)]
4-
#![feature(box_patterns)]
5-
#![feature(box_into_inner)]
62
#![recursion_limit = "256"]
7-
#![feature(map_try_insert)]
8-
#![feature(get_mut_unchecked)]
9-
#![feature(stmt_expr_attributes)]
10-
#![feature(write_all_vectored)]
11-
#![feature(string_from_utf8_lossy_owned)]
12-
#![feature(guard_patterns)]
133

144
/// Implementation of various behavior for the tokens of cpclib_tokens
155
pub mod implementation;

cpclib-asm/src/parser/expression.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ where
484484
<R as IntoIterator>::IntoIter: ExactSizeIterator
485485
{
486486
let remainder = remainder.into_iter();
487-
if remainder.is_empty() {
487+
if remainder.len() == 0 {
488488
initial
489489
}
490490
else {

0 commit comments

Comments
 (0)