Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
FL03 committed Feb 20, 2024
1 parent 463be75 commit 0f16ea5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion acme/examples/autodiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
extern crate acme;

use acme::prelude::sigmoid;
use acme::{autodiff, partial, show_item, show_streams};
use acme::{autodiff, show_item, show_streams};

macro_rules! eval {
($var:ident: $ex:expr) => {
Expand Down
9 changes: 7 additions & 2 deletions derive/src/cmp/params/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ pub fn generate_keys(fields: &Fields, name: &Ident) -> TokenStream {

fn handle_named_fields(fields: &FieldsNamed, name: &Ident) -> TokenStream {
let FieldsNamed { named, .. } = fields;
let varaints = named.iter().cloned().map(| field | {
let fields_str = named.clone().map(|field| {
field.ident.unwrap()
});
let variants = named.iter().cloned().map(|field | {
let ident = field.ident.unwrap();
let variant_ident = format_ident!("{}", capitalize_first(&ident.to_string()));
Variant {
Expand All @@ -26,11 +29,13 @@ fn handle_named_fields(fields: &FieldsNamed, name: &Ident) -> TokenStream {
discriminant: None,
}
});


quote! {
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]

pub enum #name {
#(#varaints),*
#(#variants),*
}
}
}
2 changes: 1 addition & 1 deletion derive/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Contrib: FL03 <jo3mccain@icloud.com>
*/


/// A function for capitalizing the first letter of a string.
pub fn capitalize_first(s: &str) -> String {
s.chars()
.take(1)
Expand Down
6 changes: 3 additions & 3 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn show_streams(attr: TokenStream, item: TokenStream) -> TokenStream {
let input = parse_macro_input!(item as syn::ItemFn);
println!("attr: \"{:?}\"", &attr);
println!("item: \"{:?}\"", &input);
quote! { #input }.into()
(quote! { #input }).into()
}

#[proc_macro]
Expand All @@ -38,7 +38,7 @@ pub fn show_item(item: TokenStream) -> TokenStream {
println!("Span (start, end): ({:?}, {:?})", span.start(), span.end());
println!("Source File: {:?}", span.unwrap().source_file());
println!("Source Text: {:?}", span.source_text());
quote! { #expr }.into()
(quote! { #expr }).into()
}

#[proc_macro_attribute]
Expand All @@ -47,7 +47,7 @@ pub fn partial(attr: TokenStream, item: TokenStream) -> TokenStream {
println!("attr: \"{}\"", attr.to_string());
// let result = ad::handle::item::handle_item(&input);
// TokenStream::from(result)
quote! { #input }.into()
(quote! { #input }).into()
}

#[proc_macro]
Expand Down

0 comments on commit 0f16ea5

Please sign in to comment.