Skip to content

Commit

Permalink
init WIP add proc_macro generator generator
Browse files Browse the repository at this point in the history
  • Loading branch information
DevinR528 committed Nov 26, 2019
1 parent c25ff87 commit 52bd626
Show file tree
Hide file tree
Showing 8 changed files with 573 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
target
**/*.rs.bk
.vscode
59 changes: 59 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ include = ["Cargo.toml", "README-crates-io.md", "src/**/*.rs"]

[dependencies]
futures-core = { version = "0.3.1", optional = true }
gen_proc_macro = { path = "./gen_proc_macro" }

[workspace]
members = [ "gen_proc_macro" ]

[dev-dependencies]
futures = "0.3.1"
Expand Down
57 changes: 57 additions & 0 deletions examples/await.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#![feature(async_closure)]
#![feature(proc_macro_hygiene)]
#![feature(generators)]

use genawaiter::{
generator_mut,
stack::{Co, Gen, Shelf},
// sync::{Gen, Co},
};

use gen_proc_macro::{yielder_cls, yielder_fn};

#[yielder_fn(u8)]
async fn odds() {
for n in (1_u8..).step_by(2).take_while(|&n| n < 10) {
yield n;
}
}

fn main() {
#[yielder_cls(u8)]
let hello = async move |co: Co<'static, u8>| {
let mut n = 1_u8;
while n < 10 {
yield n;
n += 2;
}
};

// let hello = async move |co: Co<'_, (), String>| {
// let x = co.yield_(()).await;
// println!("{}", x)
// };
// generator_mut!(gen, hello);
// gen.resume_with("hello".to_string());

let mut shelf = Shelf::new();
#[yielder_cls(u8)]
let gen = unsafe { Gen::new(&mut shelf, async move || {
let mut n = 1_u8;
while n < 10 {
yield n;
n += 2;
}
}) };
// let gen = Gen::new(odds);

// generator_mut!(test, hello);

//generator_mut!(gen, odds);

for x in gen {
println!("{}", x);
}
assert!(true);
assert_eq!(0, 0)
}
103 changes: 103 additions & 0 deletions gen_proc_macro/Cargo.lock

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

24 changes: 24 additions & 0 deletions gen_proc_macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "gen_proc_macro"
version = "0.0.0"
authors = ["Devin R <[email protected]>"]
description = "procedural macro for generators (genawaiter)"
keywords = ["proc_macro", "procmacro", "async"]
edition = "2018"

[lib]
proc-macro = true

[dependencies]
quote = "1"
proc-macro2 = "1.0"
syn = {version = "1.0", features = [
"derive",
"parsing",
"printing",
"extra-traits",
"full",
"visit-mut",
"clone-impls"
] }
proc-macro-error = "0.4"
Loading

0 comments on commit 52bd626

Please sign in to comment.