forked from RustPython/RustPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrozen.rs
More file actions
55 lines (48 loc) · 1.79 KB
/
frozen.rs
File metadata and controls
55 lines (48 loc) · 1.79 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
use crate::builtins::code;
use crate::bytecode;
use crate::VirtualMachine;
use std::collections::HashMap;
pub fn map_frozen<'a>(
vm: &'a VirtualMachine,
i: impl IntoIterator<Item = (String, bytecode::FrozenModule)> + 'a,
) -> impl Iterator<Item = (String, code::FrozenModule)> + 'a {
i.into_iter()
.map(move |(k, bytecode::FrozenModule { code, package })| {
(
k,
code::FrozenModule {
code: vm.map_codeobj(code),
package,
},
)
})
}
pub fn get_module_inits(vm: &VirtualMachine) -> HashMap<String, code::FrozenModule> {
let mut modules = HashMap::new();
macro_rules! ext_modules {
($($t:tt)*) => {
modules.extend(map_frozen(vm, py_freeze!($($t)*)));
};
}
ext_modules!(
source = "initialized = True; print(\"Hello world!\")\n",
module_name = "__hello__",
);
// Python modules that the vm calls into, but are not actually part of the stdlib. They could
// in theory be implemented in Rust, but are easiest to do in Python for one reason or another.
// Includes _importlib_bootstrap and _importlib_bootstrap_external
// For Windows: did you forget to run `powershell scripts\symlinks-to-hardlinks.ps1`?
ext_modules!(dir = "Lib/python_builtins/");
#[cfg(not(feature = "freeze-stdlib"))]
{
// core stdlib Python modules that the vm calls into, but are still used in Python
// application code, e.g. copyreg
ext_modules!(dir = "Lib/core_modules/");
}
// if we're on freeze-stdlib, the core stdlib modules will be included anyway
#[cfg(feature = "freeze-stdlib")]
{
modules.extend(map_frozen(vm, rustpython_pylib::frozen_stdlib()));
}
modules
}