Skip to content

Commit

Permalink
start slotted-egraphs-derive
Browse files Browse the repository at this point in the history
  • Loading branch information
memoryleak47 committed Nov 19, 2024
1 parent b2a682b commit 96ba1a7
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ trace = ["tracing/max_level_trace", "tracing/release_max_level_trace", "tracing"
features = ["explanations"]

[dependencies]
slotted-egraphs-derive = { path = "slotted-egraphs-derive" }
fnv = "1.0.7"
tracing = { version = "0.1", features = ["attributes"], optional = true }

Expand Down
12 changes: 12 additions & 0 deletions slotted-egraphs-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "slotted-egraphs-derive"
version = "0.1.0"
edition = "2021"

[dependencies]
syn = { version = "2.0", features = ["full"] }
quote = "1.0"
proc-macro2 = "1.0"

[lib]
proc-macro = true
14 changes: 14 additions & 0 deletions slotted-egraphs-derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use proc_macro::TokenStream as TokenStream1;
use proc_macro2::TokenStream as TokenStream2;
use quote::{format_ident, quote, ToTokens};
use syn::*;

#[proc_macro]
pub fn define_language(input: TokenStream1) -> TokenStream1 {
let mut xx: ItemEnum = parse(input).unwrap();
xx.variants.iter_mut().for_each(|x| {
x.attrs.clear();
x.discriminant = None;
});
quote! { #xx }.to_token_stream().into()
}
14 changes: 14 additions & 0 deletions src/lang.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
use crate::*;

pub struct Bind<T> {
pub slot: Slot,
pub elem: T,
}

define_language! {
enum ExampleLanguage {
Lambda(Bind<AppliedId>) = "lambda",
App(AppliedId, AppliedId) = "app",
Var(Slot) = "var",
#[substitution_op] Let(AppliedId, Bind<AppliedId>) = "let",
}
}

#[derive(Debug, Clone)]
/// A child node of some term ("child" in the sense of an AST).
///
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const CHECKS: bool = true;
#[cfg(not(feature = "checks"))]
const CHECKS: bool = false;

pub use slotted_egraphs_derive::define_language;

mod slot;
pub use slot::*;

Expand Down

0 comments on commit 96ba1a7

Please sign in to comment.