diff --git a/bitfield/Cargo.toml b/bitfield/Cargo.toml new file mode 100644 index 000000000..1b60685c0 --- /dev/null +++ b/bitfield/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "bitfield" +version = "0.0.0" +edition = "2018" +autotests = false +publish = false + +[[test]] +name = "tests" +path = "tests/progress.rs" + +[dev-dependencies] +workshop-test-runner = { path = "../test-runner" } + +[dependencies] +bitfield-impl = { path = "impl" } diff --git a/bitfield/impl/Cargo.toml b/bitfield/impl/Cargo.toml new file mode 100644 index 000000000..4cc1bc943 --- /dev/null +++ b/bitfield/impl/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "bitfield-impl" +version = "0.0.0" +edition = "2018" +publish = false + +[lib] +proc-macro = true + +[dependencies] +# TODO diff --git a/bitfield/impl/src/lib.rs b/bitfield/impl/src/lib.rs new file mode 100644 index 000000000..65a22e14b --- /dev/null +++ b/bitfield/impl/src/lib.rs @@ -0,0 +1,11 @@ +extern crate proc_macro; + +use proc_macro::TokenStream; + +#[proc_macro_attribute] +pub fn bitfield(args: TokenStream, input: TokenStream) -> TokenStream { + let _ = args; + let _ = input; + + unimplemented!() +} diff --git a/bitfield/src/lib.rs b/bitfield/src/lib.rs new file mode 100644 index 000000000..406e10347 --- /dev/null +++ b/bitfield/src/lib.rs @@ -0,0 +1,15 @@ +// Crates that have the "proc-macro" crate type are only allowed to export +// procedural macros. So we cannot have one crate that defines procedural macros +// alongside other types of public APIs like traits and structs. +// +// For this project we are going to need a #[bitfield] macro but also a trait +// and some structs. We solve this by defining the trait and structs in this +// crate, defining the attribute macro in a separate bitfield-impl crate, and +// then re-exporting the macro from this crate so that users only have one crate +// that they need to import. +// +// From the perspective of a user of this crate, they get all the necessary APIs +// (macro, trait, struct) through the one bitfield crate. +pub use bitfield_impl::bitfield; + +// TODO other things diff --git a/bitfield/tests/00-INCOMPLETE b/bitfield/tests/00-INCOMPLETE new file mode 100644 index 000000000..bab8fbadf --- /dev/null +++ b/bitfield/tests/00-INCOMPLETE @@ -0,0 +1 @@ +This test suite needs more work and explanations... diff --git a/bitfield/tests/01-parse.rs b/bitfield/tests/01-parse.rs new file mode 100644 index 000000000..585bbd8e2 --- /dev/null +++ b/bitfield/tests/01-parse.rs @@ -0,0 +1,11 @@ +use bitfield::*; + +#[bitfield] +pub struct MyFourBytes { + a: B1, + b: B3, + c: B4, + d: B24, +} + +fn main() {} diff --git a/bitfield/tests/progress.rs b/bitfield/tests/progress.rs new file mode 100644 index 000000000..5044d9f93 --- /dev/null +++ b/bitfield/tests/progress.rs @@ -0,0 +1,5 @@ +#[test] +fn tests() { + let t = workshop::TestCases::new(); + //t.pass("tests/01-parse.rs"); +}