Skip to content

Instantly share code, notes, and snippets.

@iczero
Last active September 10, 2023 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iczero/19e978f252dc73041f51c296c6b8d8b6 to your computer and use it in GitHub Desktop.
Save iczero/19e978f252dc73041f51c296c6b8d8b6 to your computer and use it in GitHub Desktop.
crimes against Rust
#![feature(macro_metavar_expr)]
macro_rules! repeat_2 {
($($what:tt)*) => {
$($what)*
$($what)*
}
}
macro_rules! make_repeat_from {
($from:ident, $out:ident) => {
macro_rules! $out {
($$($$what:tt)*) => {
$from! { $$($$what)* }
$from! { $$($$what)* }
}
}
}
}
macro_rules! make_repeat {
($from:ident $out:ident $($rest:ident)*) => {
make_repeat_from! { $from, $out }
make_repeat! { $out $($rest)* }
};
($last:ident) => {}
}
make_repeat! {
repeat_2
repeat_4
repeat_8
repeat_16
repeat_32
repeat_64
repeat_128
repeat_256
repeat_512
repeat_1024
/* uncomment to hang everything
repeat_2048
repeat_4096
repeat_8192
repeat_16384
repeat_32768
repeat_65536
*/
}
fn main() {
let mut i = 0;
repeat_1024! {
println!("hello {}", i);
i += 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment