Skip to content

Commit e02ced7

Browse files
committed
intrinsic test: fix formatting (a bit, at least)
1 parent d28b44b commit e02ced7

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

crates/intrinsic-test/src/common/gen_rust.rs

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,22 @@ use super::intrinsic_helpers::IntrinsicTypeDefinition;
1010
// The number of times each intrinsic will be called.
1111
pub(crate) const PASSES: u32 = 20;
1212

13+
macro_rules! concatln {
14+
($($lines:expr),* $(,)?) => {
15+
concat!($( $lines, "\n" ),*)
16+
};
17+
}
18+
1319
fn write_cargo_toml_header(w: &mut impl std::io::Write, name: &str) -> std::io::Result<()> {
1420
writeln!(
1521
w,
16-
concat!(
17-
"[package]\n",
18-
"name = \"{name}\"\n",
19-
"version = \"{version}\"\n",
20-
"authors = [{authors}]\n",
21-
"license = \"{license}\"\n",
22-
"edition = \"2018\"\n",
22+
concatln!(
23+
"[package]",
24+
"name = \"{name}\"",
25+
"version = \"{version}\"",
26+
"authors = [{authors}]",
27+
"license = \"{license}\"",
28+
"edition = \"2018\"",
2329
),
2430
name = name,
2531
version = env!("CARGO_PKG_VERSION"),
@@ -247,23 +253,23 @@ pub fn generate_rust_test_loop<T: IntrinsicTypeDefinition>(
247253
}
248254
}
249255

250-
let indentation2 = indentation.nested();
251-
let indentation3 = indentation2.nested();
252-
writeln!(
256+
write!(
253257
w,
254-
"\
255-
for (id, f) in specializations {{\n\
256-
for i in 0..{passes} {{\n\
257-
unsafe {{\n\
258-
{loaded_args}\
259-
let __return_value = f({args});\n\
260-
println!(\"Result {{id}}-{{}}: {{:?}}\", i + 1, {return_value});\n\
261-
}}\n\
262-
}}\n\
263-
}}",
264-
loaded_args = intrinsic.arguments.load_values_rust(indentation3),
258+
concatln!(
259+
" for (id, f) in specializations {{",
260+
" for i in 0..{passes} {{",
261+
" unsafe {{",
262+
"{loaded_args}",
263+
" let __return_value = f({args});",
264+
" println!(\"Result {{id}}-{{}}: {{:?}}\", i + 1, {return_value});",
265+
" }}",
266+
" }}",
267+
" }}",
268+
),
269+
loaded_args = intrinsic.arguments.load_values_rust(indentation.nest_by(4)),
265270
args = intrinsic.arguments.as_call_param_rust(),
266271
return_value = intrinsic.results.print_result_rust(),
272+
passes = passes,
267273
)
268274
}
269275

crates/intrinsic-test/src/common/indentation.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ impl Indentation {
1010
pub fn nested(self) -> Self {
1111
Self(self.0 + 1)
1212
}
13+
14+
pub fn nest_by(&self, additional_levels: u32) -> Self {
15+
Self(self.0 + additional_levels)
16+
}
1317
}
1418

1519
impl std::fmt::Display for Indentation {

0 commit comments

Comments
 (0)