Skip to content

Commit

Permalink
Better step macro
Browse files Browse the repository at this point in the history
  • Loading branch information
taikiy committed Aug 8, 2023
1 parent 9d0a1b1 commit 399f403
Show file tree
Hide file tree
Showing 49 changed files with 4,295 additions and 22,976 deletions.
3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,11 @@ serde = { version = "1.0", optional = true, features = ["derive"] }
serde_json = { version = "1.0", optional = true }
sha2 = "0.10.6"
shuttle-crate = { package = "shuttle", version = "0.6.1", optional = true }
strum = {version = "0.25", features = ["derive"] }
thiserror = "1.0"
time = { version = "0.3", optional = true }
tinyvec = "1.6"
tokio = { version = "1.28", features = ["rt", "rt-multi-thread", "macros"] }
tokio-rustls = { version = "0.24.0", optional = true }
tokio-stream = "0.1.14"
tokio-util = "0.7.8"
toml = { version = "0.7", optional = true }
tower = { version = "0.4.13", optional = true }
tower-http = { version = "0.4.0", optional = true, features = ["trace"] }
Expand Down
124 changes: 0 additions & 124 deletions ipa-macros/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 1 addition & 12 deletions ipa-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,6 @@ edition = "2021"
[lib]
proc-macro = true

[features]
trybuild = []

[[test]]
name = "tests"
path = "tests/mod.rs"
required-features = ["trybuild"]

[dependencies]
syn = { version = "2.0.15", features = ["full"] }
syn = { version = "2.0.15", features = ["full", "extra-traits"] }
quote = "1.0.27"

[dev-dependencies]
trybuild = { version = "1.0.80", features = ["diff"] }
25 changes: 2 additions & 23 deletions ipa-macros/src/derive_gate/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::parser::{group_by_modules, ipa_state_transition_map, module_string_to_ast};
use crate::parser::{group_by_modules, ipa_state_transition_map};
use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, DeriveInput};
Expand Down Expand Up @@ -77,28 +77,7 @@ pub fn expand(item: TokenStream) -> TokenStream {
let mut reverse_map = Vec::new();
let mut deserialize_map = Vec::new();

for (module, steps) in grouped_steps {
// generate the `StepNarrow` implementation for each module
let module = module_string_to_ast(&module);
let states = steps.iter().map(|s| {
let new_state = &s.name;
let new_state_id = s.id;
let previous_state_id = s.get_parent().unwrap().id;
quote!(
(#previous_state_id, #new_state) => #new_state_id,
)
});
expanded.extend(quote!(
impl StepNarrow<#module> for #gate {
fn narrow(&self, step: &#module) -> Self {
Self(match (self.0, step.as_ref()) {
#(#states)*
_ => static_state_map(self.0, step.as_ref()),
})
}
}
));

for (_, steps) in grouped_steps {
// generate the reverse map for `impl AsRef<str> for Compact`
// this is used to convert a state ID to a string representation of the state.
reverse_map.extend(steps.iter().map(|s| {
Expand Down
Loading

0 comments on commit 399f403

Please sign in to comment.