1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
// TODO make this deny eventually
//! This crate provides powerful macros to derive traits from the core crate.
//! It also provides macros to automatically construct AuxStorage structs
//! used to store intermediate data for running update steps and Communicator
//! struct to send messages between threads running the simulation.
//!
//! All macros are documented in the core crate unless their functionality can be
//! displayed without any additional dependencies.
/// Run a particularly structured test multiple times for combinations of aspects
///
/// The tests which we would like to run are macros that will
/// be given as one argument to this `proc_macro`.
/// These tests need to adhere to a strict format.
/// ```
/// macro_rules! some_test(
/// (
/// name:$test_name:ident,
/// aspects:[$($asp:ident),*]
/// ) => {
/// // Any code can be run here.
/// // For example, we can create a docstring test by using
///
/// /// ```
/// /// assert_eq!(0_usize, 10_usize - 10_usize);
/// $(#[doc = concat!("println!(\"", stringify!($asp), "\")")])*
/// /// ```
/// fn $test_name () {}
/// }
/// );
///
/// // This is how you would call the test by hand
///
/// some_test!(
/// name:my_test_name,
/// aspects: [Mechanics, Interaction]
/// );
/// ```
///
/// In the next step, we can use `run_test_for_aspects` to run this automatically generated
/// docstring test for every combination of aspects that we specify.
///
/// ```
/// # macro_rules! some_test(
/// # (
/// # name:$test_name:ident,
/// # aspects:[$($asp:ident),*]
/// # ) => {
/// # // Any code can be run here.
/// # // For example, we can create a docstring test by using
/// #
/// # /// ```
/// # /// assert_eq!(0_usize, 10_usize - 10_usize);
/// # $(#[doc = concat!("println!(\"", stringify!($asp), "\")")])*
/// # /// ```
/// # fn $test_name () {}
/// # }
/// # );
/// # use cellular_raza_core_proc_macro::run_test_for_aspects;
/// run_test_for_aspects!(
/// test: some_test,
/// aspects: [Mechanics, Interaction]
/// );
/// ```
/// This will have generated the following code:
/// ```
/// # macro_rules! some_test(
/// # (
/// # name:$test_name:ident,
/// # aspects:[$($asp:ident),*]
/// # ) => {
/// # // Any code can be run here.
/// # // For example, we can create a docstring test by using
/// #
/// # /// ```
/// # /// assert_eq!(0_usize, 10_usize - 10_usize);
/// # $(#[doc = concat!("println!(\"", stringify!($asp), "\")")])*
/// # /// ```
/// # fn $test_name () {}
/// # }
/// # );
/// some_test!(
/// name:mechanics,
/// aspects: [Mechanics]
/// );
/// some_test!(
/// name:interaction,
/// aspects: [Interaction]
/// );
/// some_test!(
/// name:mechanics_interaction,
/// aspects: [Mechanics, Interaction]
/// );
/// some_test!(
/// name:interaction_mechanics,
/// aspects: [Interaction, Mechanics]
/// );
/// ```
/* #[derive(Clone, Debug)]
enum Aspect {
Mechanics,
Cycle,
Interaction,
CellularReactions,
}
fn element_to_aspect(element: syn::Expr) -> syn::Result<Aspect> {
match element.clone() {
syn::Expr::Path(path) => {
let ident: syn::Ident = path.path.segments.into_iter().next().unwrap().ident;
if ident == "Mechanics" {
Ok(Aspect::Mechanics)
} else if ident.to_string().to_lowercase() == "cycle" {
Ok(Aspect::Cycle)
} else if ident.to_string().to_lowercase() == "interaction" {
Ok(Aspect::Interaction)
} else if ident.to_string().to_lowercase() == "cellularreactions" {
Ok(Aspect::CellularReactions)
} else {
Err(syn::Error::new(
element.span(),
format!("Expected one of [Mechanics, Cycle, Interaction, CellularReactions]"),
))
}
}
_ => Err(syn::Error::new(element.span(), "Expected expression here.")),
}
}
struct SimulationInformation {
setup: syn::Ident,
settings: syn::Ident,
aspects: Vec<Aspect>,
}
impl syn::parse::Parse for SimulationInformation {
fn parse(input: ParseStream) -> syn::parse::Result<Self> {
let setup: syn::Ident = input.parse()?;
let _: syn::token::Comma = input.parse()?;
let settings: syn::Ident = input.parse()?;
let _: syn::token::Comma = input.parse()?;
let aspects: syn::ExprArray = input.parse()?;
let aspects = aspects
.elems
.into_iter()
.map(element_to_aspect)
.collect::<syn::Result<Vec<_>>>()?;
Ok(Self {
setup,
settings,
aspects,
})
}
}
///
#[proc_macro]
pub fn run_full_simulation(input: TokenStream) -> TokenStream {
// let mut tokens = parse_non_delimiter_tokens(input).into_iter();
// let setup = tokens.next().unwrap();
// let settings = tokens.next().unwrap();
// let aspects = tokens.next().unwrap();
let SimulationInformation {
setup,
settings,
aspects,
} = parse_macro_input!(input as SimulationInformation);
TokenStream::from(quote!({
// TODO construct the aux storage from the simulation aspects
struct AuxStorage {}
1_u8
}))
}*/