forked from RustPython/RustPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.rs
More file actions
215 lines (209 loc) · 6.01 KB
/
mod.rs
File metadata and controls
215 lines (209 loc) · 6.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
mod array;
#[cfg(feature = "rustpython-ast")]
pub(crate) mod ast;
mod atexit;
mod binascii;
mod bisect;
mod cmath;
mod codecs;
mod collections;
mod csv;
mod dis;
mod errno;
mod functools;
mod hashlib;
mod imp;
pub(crate) mod io;
mod itertools;
mod json;
#[cfg(feature = "rustpython-parser")]
mod keyword;
mod marshal;
mod math;
mod operator;
mod platform;
mod pyexpat;
pub(crate) mod pystruct;
mod random;
// TODO: maybe make this an extension module, if we ever get those
// mod re;
#[cfg(not(target_arch = "wasm32"))]
mod socket;
mod sre;
mod string;
#[cfg(feature = "rustpython-compiler")]
mod symtable;
mod sysconfigdata;
#[cfg(unix)]
mod syslog;
#[cfg(feature = "threading")]
mod thread;
mod time;
mod unicodedata;
mod warnings;
mod weakref;
mod zlib;
#[cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))]
#[macro_use]
pub(crate) mod os;
#[cfg(windows)]
pub(crate) mod nt;
#[cfg(unix)]
pub(crate) mod posix;
#[cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))]
#[cfg(not(any(unix, windows)))]
pub(crate) mod posix_compat;
#[cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))]
#[cfg(not(any(unix, windows)))]
pub(crate) use posix_compat as posix;
#[cfg(not(target_arch = "wasm32"))]
mod faulthandler;
#[cfg(any(unix, target_os = "wasi"))]
mod fcntl;
#[cfg(windows)]
pub(crate) mod msvcrt;
#[cfg(not(target_arch = "wasm32"))]
mod multiprocessing;
#[cfg(unix)]
mod posixsubprocess;
#[cfg(all(unix, not(any(target_os = "android", target_os = "redox"))))]
mod pwd;
// libc is missing constants on redox
#[cfg(all(unix, not(target_os = "redox")))]
mod resource;
#[cfg(target_os = "macos")]
mod scproxy;
#[cfg(not(target_arch = "wasm32"))]
mod select;
#[cfg(not(target_arch = "wasm32"))]
pub(crate) mod signal;
#[cfg(all(not(target_arch = "wasm32"), feature = "ssl"))]
mod ssl;
#[cfg(all(unix, not(target_os = "redox")))]
mod termios;
#[cfg(windows)]
mod winapi;
#[cfg(windows)]
mod winreg;
use crate::vm::VirtualMachine;
use crate::PyObjectRef;
use std::borrow::Cow;
use std::collections::HashMap;
pub type StdlibInitFunc = Box<py_dyn_fn!(dyn Fn(&VirtualMachine) -> PyObjectRef)>;
pub type StdlibMap = HashMap<Cow<'static, str>, StdlibInitFunc, ahash::RandomState>;
pub fn get_module_inits() -> StdlibMap {
macro_rules! modules {
{
$(
#[cfg($cfg:meta)]
{ $( $key:expr => $val:expr),* $(,)? }
)*
} => {{
let iter = std::array::IntoIter::new([
$(
$(#[cfg($cfg)] (Cow::<'static, str>::from($key), Box::new($val) as StdlibInitFunc),)*
)*
]);
iter.collect()
}};
}
modules! {
#[cfg(all())]
{
"array" => array::make_module,
"atexit" => atexit::make_module,
"binascii" => binascii::make_module,
"_bisect" => bisect::make_module,
"cmath" => cmath::make_module,
"_codecs" => codecs::make_module,
"_collections" => collections::make_module,
"_csv" => csv::make_module,
"dis" => dis::make_module,
"errno" => errno::make_module,
"_functools" => functools::make_module,
"hashlib" => hashlib::make_module,
"itertools" => itertools::make_module,
"_io" => io::make_module,
"_json" => json::make_module,
"marshal" => marshal::make_module,
"math" => math::make_module,
"_operator" => operator::make_module,
"pyexpat" => pyexpat::make_module,
"_platform" => platform::make_module,
"_random" => random::make_module,
"_sre" => sre::make_module,
"_string" => string::make_module,
"_struct" => pystruct::make_module,
"time" => time::make_module,
"_weakref" => weakref::make_module,
"_imp" => imp::make_module,
"unicodedata" => unicodedata::make_module,
"_warnings" => warnings::make_module,
"zlib" => zlib::make_module,
crate::sysmodule::sysconfigdata_name() => sysconfigdata::make_module,
}
// parser related modules:
#[cfg(feature = "rustpython-ast")]
{
"_ast" => ast::make_module,
}
#[cfg(feature = "rustpython-parser")]
{
"keyword" => keyword::make_module,
}
// compiler related modules:
#[cfg(feature = "rustpython-compiler")]
{
"symtable" => symtable::make_module,
}
#[cfg(any(unix, target_os = "wasi"))]
{
"posix" => posix::make_module,
"fcntl" => fcntl::make_module,
}
// disable some modules on WASM
#[cfg(not(target_arch = "wasm32"))]
{
"_socket" => socket::make_module,
"_multiprocessing" => multiprocessing::make_module,
"_signal" => signal::make_module,
"select" => select::make_module,
"faulthandler" => faulthandler::make_module,
}
#[cfg(feature = "ssl")]
{
"_ssl" => ssl::make_module,
}
#[cfg(all(feature = "threading", not(target_arch = "wasm32")))]
{
"_thread" => thread::make_module,
}
// Unix-only
#[cfg(all(unix, not(any(target_os = "android", target_os = "redox"))))]
{
"pwd" => pwd::make_module,
}
#[cfg(all(unix, not(target_os = "redox")))]
{
"termios" => termios::make_module,
"resource" => resource::make_module,
}
#[cfg(unix)]
{
"_posixsubprocess" => posixsubprocess::make_module,
"syslog" => syslog::make_module,
}
// Windows-only
#[cfg(windows)]
{
"nt" => nt::make_module,
"msvcrt" => msvcrt::make_module,
"_winapi" => winapi::make_module,
"winreg" => winreg::make_module,
}
#[cfg(target_os = "macos")]
{
"_scproxy" => scproxy::make_module,
}
}
}