Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ name = "bench"
path = "./benchmarks/bench.rs"

[features]
default = ["rustpython-vm/use-proc-macro-hack"]
flame-it = ["rustpython-vm/flame-it", "flame", "flamescope"]
freeze-stdlib = ["rustpython-vm/freeze-stdlib"]

Expand Down
4 changes: 0 additions & 4 deletions derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ edition = "2018"
[lib]
proc-macro = true

[features]
default = ["proc-macro-hack"]

[dependencies]
syn = { version = "0.15.29", features = ["full"] }
quote = "0.6.11"
proc-macro2 = "0.4.27"
rustpython-compiler = { path = "../compiler", version = "0.1.1" }
rustpython-bytecode = { path = "../bytecode", version = "0.1.1" }
proc-macro-hack = { version = "0.5", optional = true }
maplit = "1.0"
15 changes: 12 additions & 3 deletions derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,17 @@ pub fn pystruct_sequence(attr: TokenStream, item: TokenStream) -> TokenStream {
result_to_tokens(pyclass::impl_pystruct_sequence(attr, item))
}

#[cfg_attr(feature = "proc-macro-hack", proc_macro_hack::proc_macro_hack)]
#[cfg_attr(not(feature = "proc-macro-hack"), proc_macro)]
fn result_to_tokens_expr(result: Result<TokenStream2, Diagnostic>) -> TokenStream {
result_to_tokens(result.map(|out_expr| {
quote::quote! {
macro_rules! __proc_macro_call {
() => {{ #out_expr }};
}
}
}))
}

#[proc_macro]
pub fn py_compile_bytecode(input: TokenStream) -> TokenStream {
result_to_tokens(compile_bytecode::impl_py_compile_bytecode(input.into()))
result_to_tokens_expr(compile_bytecode::impl_py_compile_bytecode(input.into()))
}
4 changes: 1 addition & 3 deletions vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ edition = "2018"
include = ["src/**/*.rs", "Cargo.toml", "build.rs", "Lib/**/*.py"]

[features]
default = ["rustpython-parser", "rustpython-compiler", "use-proc-macro-hack"]
default = ["rustpython-parser", "rustpython-compiler"]
vm-tracing-logging = []
flame-it = ["flame", "flamer"]
use-proc-macro-hack = ["proc-macro-hack", "rustpython-derive/proc-macro-hack"]
freeze-stdlib = []

[dependencies]
Expand Down Expand Up @@ -60,7 +59,6 @@ unicode-casing = "0.1"
unic = "0.9"
unic-common = "0.9"
maplit = "1.0"
proc-macro-hack = { version = "0.5", optional = true }
bitflags = "1.1"
libc = "0.2"
nix = "0.15.0"
Expand Down
17 changes: 13 additions & 4 deletions vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
)]
#![doc(html_logo_url = "https://raw.githubusercontent.com/RustPython/RustPython/master/logo.png")]
#![doc(html_root_url = "https://docs.rs/rustpython-vm/")]
#![cfg_attr(not(feature = "use-proc-macro-hack"), feature(proc_macro_hygiene))]

#[cfg(feature = "flame-it")]
#[macro_use]
Expand All @@ -37,9 +36,19 @@ extern crate self as rustpython_vm;

pub use rustpython_derive::*;

#[cfg(feature = "use-proc-macro-hack")]
#[proc_macro_hack::proc_macro_hack]
pub use rustpython_derive::py_compile_bytecode;
#[doc(hidden)]
pub use rustpython_derive::py_compile_bytecode as _py_compile_bytecode;

#[macro_export]
macro_rules! py_compile_bytecode {
($($arg:tt)*) => {{
#[macro_use]
mod __m {
$crate::_py_compile_bytecode!($($arg)*);
}
__proc_macro_call!()
}};
}

//extern crate eval; use eval::eval::*;
// use py_code_object::{Function, NativeType, PyCodeObject};
Expand Down