Skip to content

Commit

Permalink
fmt rest of generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
keks committed Nov 6, 2024
1 parent 4d3d2f0 commit 112ccc2
Show file tree
Hide file tree
Showing 8 changed files with 2,022 additions and 569 deletions.
36 changes: 18 additions & 18 deletions libcrux-hacl-rs-krml/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use proc_macro::{TokenStream,TokenTree,Delimiter};
use proc_macro::{Delimiter, TokenStream, TokenTree};

fn skip_comma<T: Iterator<Item=TokenTree>>(ts: &mut T) {
fn skip_comma<T: Iterator<Item = TokenTree>>(ts: &mut T) {
match ts.next() {
| Some (TokenTree::Punct(p)) => assert_eq!(p.as_char(), ','),
| _ => panic!("Expected comma")
Some(TokenTree::Punct(p)) => assert_eq!(p.as_char(), ','),
_ => panic!("Expected comma"),
}
}

fn accept_token<T: Iterator<Item=TokenTree>>(ts: &mut T) -> TokenTree {
fn accept_token<T: Iterator<Item = TokenTree>>(ts: &mut T) -> TokenTree {
match ts.next() {
| Some(t) => t,
| _ => panic!("early end")
Some(t) => t,
_ => panic!("early end"),
}
}

Expand All @@ -24,23 +24,23 @@ pub fn unroll_for(ts: TokenStream) -> TokenStream {
let n_loops = accept_token(&mut i).to_string().parse::<u32>().unwrap();
skip_comma(&mut i);
let var = accept_token(&mut i).to_string();
let var = &var[1..var.len()-1];
let var = &var[1..var.len() - 1];
skip_comma(&mut i);
let start = accept_token(&mut i).to_string();
skip_comma(&mut i);
let increment = accept_token(&mut i).to_string();
skip_comma(&mut i);
let grouped_body = brace(TokenStream::from_iter(i));
let chunks =
(0..n_loops).map(|i| {
let chunks = [
format!("const {}: u32 = {} + {} * {};", var, start, i, increment).parse().unwrap(),
TokenStream::from(grouped_body.clone()),
";".parse().unwrap()
];
TokenStream::from(brace(TokenStream::from_iter(chunks)))
})
;
let chunks = (0..n_loops).map(|i| {
let chunks = [
format!("const {}: u32 = {} + {} * {};", var, start, i, increment)
.parse()
.unwrap(),
TokenStream::from(grouped_body.clone()),
";".parse().unwrap(),
];
TokenStream::from(brace(TokenStream::from_iter(chunks)))
});
TokenStream::from(brace(TokenStream::from_iter(chunks.into_iter().flatten())))
// "{ let i = 0; println!(\"FROM MACRO{}\", i); }".parse().unwrap()
}
8 changes: 4 additions & 4 deletions libcrux-hacl-rs/src/bignum.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
pub mod bignum_base;
pub mod bignum;
pub mod bignum32;
pub mod bignum64;
pub mod bignum256;
pub mod bignum256_32;
pub mod bignum32;
pub mod bignum4096;
pub mod bignum4096_32;
pub mod bignum64;
pub mod bignum_base;

pub mod test {
// pub mod bignum4096;
// pub mod bignum4096;
}
Loading

0 comments on commit 112ccc2

Please sign in to comment.