@@ -10,7 +10,6 @@ use std::str;
10
10
use num_bigint:: Sign ;
11
11
use num_traits:: { Signed , ToPrimitive , Zero } ;
12
12
13
- use crate :: compile;
14
13
use crate :: obj:: objbool;
15
14
use crate :: obj:: objbytes:: PyBytesRef ;
16
15
use crate :: obj:: objcode:: PyCodeRef ;
@@ -19,6 +18,8 @@ use crate::obj::objint::{self, PyIntRef};
19
18
use crate :: obj:: objiter;
20
19
use crate :: obj:: objstr:: { self , PyString , PyStringRef } ;
21
20
use crate :: obj:: objtype:: { self , PyClassRef } ;
21
+ #[ cfg( feature = "rustpython_compiler" ) ]
22
+ use rustpython_compiler:: compile;
22
23
23
24
use crate :: frame:: Scope ;
24
25
use crate :: function:: { single_or_tuple_any, Args , KwArgs , OptionalArg , PyFuncArgs } ;
@@ -98,6 +99,7 @@ struct CompileArgs {
98
99
optimize : OptionalArg < PyIntRef > ,
99
100
}
100
101
102
+ #[ cfg( feature = "rustpython_compiler" ) ]
101
103
fn builtin_compile ( args : CompileArgs , vm : & VirtualMachine ) -> PyResult < PyCodeRef > {
102
104
// TODO: compile::compile should probably get bytes
103
105
let source = match args. source {
@@ -153,6 +155,7 @@ fn builtin_divmod(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
153
155
154
156
/// Implements `eval`.
155
157
/// See also: https://docs.python.org/3/library/functions.html#eval
158
+ #[ cfg( feature = "rustpython_compiler" ) ]
156
159
fn builtin_eval ( vm : & VirtualMachine , args : PyFuncArgs ) -> PyResult {
157
160
// TODO: support any mapping for `locals`
158
161
arg_check ! (
@@ -184,6 +187,7 @@ fn builtin_eval(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
184
187
185
188
/// Implements `exec`
186
189
/// https://docs.python.org/3/library/functions.html#exec
190
+ #[ cfg( feature = "rustpython_compiler" ) ]
187
191
fn builtin_exec ( vm : & VirtualMachine , args : PyFuncArgs ) -> PyResult {
188
192
arg_check ! (
189
193
vm,
@@ -785,6 +789,15 @@ pub fn make_module(vm: &VirtualMachine, module: PyObjectRef) {
785
789
#[ cfg( not( target_arch = "wasm32" ) ) ]
786
790
let open = vm. ctx . new_rustfunc ( io_open) ;
787
791
792
+ #[ cfg( feature = "rustpython_compiler" ) ]
793
+ {
794
+ extend_module ! ( vm, module, {
795
+ "compile" => ctx. new_rustfunc( builtin_compile) ,
796
+ "eval" => ctx. new_rustfunc( builtin_eval) ,
797
+ "exec" => ctx. new_rustfunc( builtin_exec) ,
798
+ } ) ;
799
+ }
800
+
788
801
extend_module ! ( vm, module, {
789
802
//set __name__ fixes: https://github.com/RustPython/RustPython/issues/146
790
803
"__name__" => ctx. new_str( String :: from( "__main__" ) ) ,
@@ -799,15 +812,12 @@ pub fn make_module(vm: &VirtualMachine, module: PyObjectRef) {
799
812
"callable" => ctx. new_rustfunc( builtin_callable) ,
800
813
"chr" => ctx. new_rustfunc( builtin_chr) ,
801
814
"classmethod" => ctx. classmethod_type( ) ,
802
- "compile" => ctx. new_rustfunc( builtin_compile) ,
803
815
"complex" => ctx. complex_type( ) ,
804
816
"delattr" => ctx. new_rustfunc( builtin_delattr) ,
805
817
"dict" => ctx. dict_type( ) ,
806
818
"divmod" => ctx. new_rustfunc( builtin_divmod) ,
807
819
"dir" => ctx. new_rustfunc( builtin_dir) ,
808
820
"enumerate" => ctx. enumerate_type( ) ,
809
- "eval" => ctx. new_rustfunc( builtin_eval) ,
810
- "exec" => ctx. new_rustfunc( builtin_exec) ,
811
821
"float" => ctx. float_type( ) ,
812
822
"frozenset" => ctx. frozenset_type( ) ,
813
823
"filter" => ctx. filter_type( ) ,
0 commit comments