Make parser and compiler optional features for vm crate.

This commit is contained in:
Windel Bouwman
2019-06-30 20:11:40 +02:00
parent 36adf45b27
commit 3954dbe716
12 changed files with 58 additions and 24 deletions

View File

@@ -1,3 +1,4 @@
#[cfg(feature = "rustpython_parser")]
mod ast;
mod binascii;
mod dis;
@@ -5,6 +6,7 @@ mod hashlib;
mod imp;
mod itertools;
mod json;
#[cfg(feature = "rustpython_parser")]
mod keyword;
mod marshal;
mod math;
@@ -16,6 +18,7 @@ pub mod socket;
mod string;
mod thread;
mod time_module;
#[cfg(feature = "rustpython_parser")]
mod tokenize;
mod warnings;
mod weakref;
@@ -37,13 +40,11 @@ pub type StdlibInitFunc = Box<dyn Fn(&VirtualMachine) -> PyObjectRef>;
pub fn get_module_inits() -> HashMap<String, StdlibInitFunc> {
#[allow(unused_mut)]
let mut modules = hashmap! {
"ast".to_string() => Box::new(ast::make_module) as StdlibInitFunc,
"binascii".to_string() => Box::new(binascii::make_module),
"dis".to_string() => Box::new(dis::make_module),
"binascii".to_string() => Box::new(binascii::make_module) as StdlibInitFunc,
"dis".to_string() => Box::new(dis::make_module) as StdlibInitFunc,
"hashlib".to_string() => Box::new(hashlib::make_module),
"itertools".to_string() => Box::new(itertools::make_module),
"json".to_string() => Box::new(json::make_module),
"keyword".to_string() => Box::new(keyword::make_module),
"marshal".to_string() => Box::new(marshal::make_module),
"math".to_string() => Box::new(math::make_module),
"platform".to_string() => Box::new(platform::make_module),
@@ -53,12 +54,22 @@ pub fn get_module_inits() -> HashMap<String, StdlibInitFunc> {
"struct".to_string() => Box::new(pystruct::make_module),
"_thread".to_string() => Box::new(thread::make_module),
"time".to_string() => Box::new(time_module::make_module),
"tokenize".to_string() => Box::new(tokenize::make_module),
"_weakref".to_string() => Box::new(weakref::make_module),
"_imp".to_string() => Box::new(imp::make_module),
"_warnings".to_string() => Box::new(warnings::make_module),
};
// Insert parser related modules:
#[cfg(feature = "rustpython_parser")]
{
modules.insert(
"ast".to_string(),
Box::new(ast::make_module) as StdlibInitFunc,
);
modules.insert("keyword".to_string(), Box::new(keyword::make_module));
modules.insert("tokenize".to_string(), Box::new(tokenize::make_module));
}
// disable some modules on WASM
#[cfg(not(target_arch = "wasm32"))]
{