Skip to content

Commit 185dd4a

Browse files
committed
Split derive-impl and derive
1 parent 38a735a commit 185dd4a

File tree

15 files changed

+148
-97
lines changed

15 files changed

+148
-97
lines changed

Cargo.lock

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ include = ["LICENSE", "Cargo.toml", "src/**/*.rs"]
1515
resolver = "2"
1616
members = [
1717
"compiler", "compiler/ast", "compiler/core", "compiler/codegen", "compiler/parser",
18-
".", "common", "derive", "jit", "vm", "pylib", "stdlib", "wasm/lib",
18+
".", "common", "derive", "jit", "vm", "pylib", "stdlib", "wasm/lib", "derive-impl",
1919
]
2020

2121
[features]

compiler/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use rustpython_codegen::{compile, symboltable};
2-
use rustpython_compiler_core::CodeObject;
32
use rustpython_parser::{
43
ast::{fold::Fold, ConstantOptimizer},
54
error::ParseErrorType,
65
parser,
76
};
87

98
pub use rustpython_codegen::compile::CompileOpts;
9+
pub use rustpython_compiler_core::CodeObject;
1010
pub use rustpython_compiler_core::{BaseError as CompileErrorBody, Mode};
1111

1212
#[derive(Debug, thiserror::Error)]

derive-impl/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "rustpython-derive-impl"
3+
version = "0.0.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
rustpython-compiler-core = { path = "../compiler/core", version = "0.1.1" }
8+
rustpython-doc = { git = "https://github.com/RustPython/__doc__", branch = "main" }
9+
10+
indexmap = "1.8.1"
11+
itertools = "0.10.3"
12+
maplit = "1.0.2"
13+
once_cell = "1.10.0"
14+
proc-macro2 = "1.0.37"
15+
quote = "1.0.18"
16+
syn = { version = "1.0.91", features = ["full", "extra-traits"] }
17+
syn-ext = { version = "0.4.0", features = ["full"] }
18+
textwrap = { version = "0.15.0", default-features = false }

derive-impl/src/lib.rs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#![recursion_limit = "128"]
2+
#![doc(html_logo_url = "https://raw.githubusercontent.com/RustPython/RustPython/main/logo.png")]
3+
#![doc(html_root_url = "https://docs.rs/rustpython-derive/")]
4+
5+
extern crate proc_macro;
6+
7+
#[macro_use]
8+
extern crate maplit;
9+
10+
#[macro_use]
11+
mod error;
12+
#[macro_use]
13+
mod util;
14+
15+
mod compile_bytecode;
16+
mod from_args;
17+
mod pyclass;
18+
mod pymodule;
19+
mod pypayload;
20+
mod pystructseq;
21+
22+
use error::{extract_spans, Diagnostic};
23+
use proc_macro2::TokenStream;
24+
use quote::ToTokens;
25+
use rustpython_doc as doc;
26+
use syn::{AttributeArgs, DeriveInput, Item};
27+
28+
pub use compile_bytecode::Compiler;
29+
30+
fn result_to_tokens(result: Result<TokenStream, impl Into<Diagnostic>>) -> TokenStream {
31+
result
32+
.map_err(|e| e.into())
33+
.unwrap_or_else(ToTokens::into_token_stream)
34+
}
35+
36+
pub fn derive_from_args(input: DeriveInput) -> TokenStream {
37+
result_to_tokens(from_args::impl_from_args(input))
38+
}
39+
40+
pub fn pyclass(attr: AttributeArgs, item: Item) -> TokenStream {
41+
if matches!(item, syn::Item::Impl(_) | syn::Item::Trait(_)) {
42+
result_to_tokens(pyclass::impl_pyimpl(attr, item))
43+
} else {
44+
result_to_tokens(pyclass::impl_pyclass(attr, item))
45+
}
46+
}
47+
48+
pub use pyclass::PyExceptionDef;
49+
pub fn define_exception(exc_def: PyExceptionDef) -> TokenStream {
50+
result_to_tokens(pyclass::impl_define_exception(exc_def))
51+
}
52+
53+
pub fn pyexception(attr: AttributeArgs, item: Item) -> TokenStream {
54+
result_to_tokens(pyclass::impl_pyexception(attr, item))
55+
}
56+
57+
pub fn pymodule(attr: AttributeArgs, item: Item) -> TokenStream {
58+
result_to_tokens(pymodule::impl_pymodule(attr, item))
59+
}
60+
61+
pub fn pystruct_sequence(input: DeriveInput) -> TokenStream {
62+
result_to_tokens(pystructseq::impl_pystruct_sequence(input))
63+
}
64+
65+
pub fn pystruct_sequence_try_from_object(input: DeriveInput) -> TokenStream {
66+
result_to_tokens(pystructseq::impl_pystruct_sequence_try_from_object(input))
67+
}
68+
69+
pub fn py_compile(input: TokenStream, compiler: &dyn Compiler) -> TokenStream {
70+
result_to_tokens(compile_bytecode::impl_py_compile(input, compiler))
71+
}
72+
73+
pub fn py_freeze(input: TokenStream, compiler: &dyn Compiler) -> TokenStream {
74+
result_to_tokens(compile_bytecode::impl_py_freeze(input, compiler))
75+
}
76+
77+
pub fn pypayload(input: DeriveInput) -> TokenStream {
78+
result_to_tokens(pypayload::impl_pypayload(input))
79+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,7 @@ where
12841284
}
12851285

12861286
#[derive(Debug)]
1287-
pub(crate) struct PyExceptionDef {
1287+
pub struct PyExceptionDef {
12881288
pub class_name: Ident,
12891289
pub base_class: Ident,
12901290
pub ctx_name: Ident,

0 commit comments

Comments
 (0)