@@ -10,7 +10,6 @@ use std::str;
1010use num_bigint:: Sign ;
1111use num_traits:: { Signed , ToPrimitive , Zero } ;
1212
13- use crate :: compile;
1413use crate :: obj:: objbool;
1514use crate :: obj:: objbytes:: PyBytesRef ;
1615use crate :: obj:: objcode:: PyCodeRef ;
@@ -19,6 +18,8 @@ use crate::obj::objint::{self, PyIntRef};
1918use crate :: obj:: objiter;
2019use crate :: obj:: objstr:: { self , PyString , PyStringRef } ;
2120use crate :: obj:: objtype:: { self , PyClassRef } ;
21+ #[ cfg( feature = "rustpython_compiler" ) ]
22+ use rustpython_compiler:: compile;
2223
2324use crate :: frame:: Scope ;
2425use crate :: function:: { single_or_tuple_any, Args , KwArgs , OptionalArg , PyFuncArgs } ;
@@ -98,6 +99,7 @@ struct CompileArgs {
9899 optimize : OptionalArg < PyIntRef > ,
99100}
100101
102+ #[ cfg( feature = "rustpython_compiler" ) ]
101103fn builtin_compile ( args : CompileArgs , vm : & VirtualMachine ) -> PyResult < PyCodeRef > {
102104 // TODO: compile::compile should probably get bytes
103105 let source = match args. source {
@@ -153,6 +155,7 @@ fn builtin_divmod(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
153155
154156/// Implements `eval`.
155157/// See also: https://docs.python.org/3/library/functions.html#eval
158+ #[ cfg( feature = "rustpython_compiler" ) ]
156159fn builtin_eval ( vm : & VirtualMachine , args : PyFuncArgs ) -> PyResult {
157160 // TODO: support any mapping for `locals`
158161 arg_check ! (
@@ -184,6 +187,7 @@ fn builtin_eval(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
184187
185188/// Implements `exec`
186189/// https://docs.python.org/3/library/functions.html#exec
190+ #[ cfg( feature = "rustpython_compiler" ) ]
187191fn builtin_exec ( vm : & VirtualMachine , args : PyFuncArgs ) -> PyResult {
188192 arg_check ! (
189193 vm,
@@ -785,6 +789,15 @@ pub fn make_module(vm: &VirtualMachine, module: PyObjectRef) {
785789 #[ cfg( not( target_arch = "wasm32" ) ) ]
786790 let open = vm. ctx . new_rustfunc ( io_open) ;
787791
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+
788801 extend_module ! ( vm, module, {
789802 //set __name__ fixes: https://github.com/RustPython/RustPython/issues/146
790803 "__name__" => ctx. new_str( String :: from( "__main__" ) ) ,
@@ -799,15 +812,12 @@ pub fn make_module(vm: &VirtualMachine, module: PyObjectRef) {
799812 "callable" => ctx. new_rustfunc( builtin_callable) ,
800813 "chr" => ctx. new_rustfunc( builtin_chr) ,
801814 "classmethod" => ctx. classmethod_type( ) ,
802- "compile" => ctx. new_rustfunc( builtin_compile) ,
803815 "complex" => ctx. complex_type( ) ,
804816 "delattr" => ctx. new_rustfunc( builtin_delattr) ,
805817 "dict" => ctx. dict_type( ) ,
806818 "divmod" => ctx. new_rustfunc( builtin_divmod) ,
807819 "dir" => ctx. new_rustfunc( builtin_dir) ,
808820 "enumerate" => ctx. enumerate_type( ) ,
809- "eval" => ctx. new_rustfunc( builtin_eval) ,
810- "exec" => ctx. new_rustfunc( builtin_exec) ,
811821 "float" => ctx. float_type( ) ,
812822 "frozenset" => ctx. frozenset_type( ) ,
813823 "filter" => ctx. filter_type( ) ,
0 commit comments