44#[ cfg( feature = "rustpython-compiler" ) ]
55use crate :: compile;
66use crate :: {
7- builtins:: { code , code :: CodeObject , list, traceback:: PyTraceback , PyBaseExceptionRef } ,
7+ builtins:: { list, traceback:: PyTraceback , PyBaseExceptionRef , PyCode } ,
88 scope:: Scope ,
99 version:: get_git_revision,
1010 vm:: { thread, VirtualMachine } ,
@@ -85,12 +85,11 @@ pub(crate) fn init_importlib_package(
8585 } )
8686}
8787
88- pub fn make_frozen ( vm : & VirtualMachine , name : & str ) -> PyResult < code:: CodeObject > {
89- vm. state
90- . frozen
91- . get ( name)
92- . map ( |frozen| vm. ctx . new_code_object ( frozen. code . clone ( ) ) )
93- . ok_or_else ( || vm. new_import_error ( format ! ( "No such frozen object named {}" , name) , name) )
88+ pub fn make_frozen ( vm : & VirtualMachine , name : & str ) -> PyResult < PyRef < PyCode > > {
89+ let frozen = vm. state . frozen . get ( name) . ok_or_else ( || {
90+ vm. new_import_error ( format ! ( "No such frozen object named {}" , name) , name)
91+ } ) ?;
92+ Ok ( vm. ctx . new_code ( frozen. code . clone ( ) ) )
9493}
9594
9695pub fn import_frozen ( vm : & VirtualMachine , module_name : & str ) -> PyResult {
@@ -122,15 +121,16 @@ pub fn import_file(
122121 file_path : String ,
123122 content : String ,
124123) -> PyResult {
125- let code = compile:: compile ( & content, compile:: Mode :: Exec , file_path, vm. compile_opts ( ) )
124+ let code = vm
125+ . compile_with_opts ( & content, compile:: Mode :: Exec , file_path, vm. compile_opts ( ) )
126126 . map_err ( |err| vm. new_syntax_error ( & err) ) ?;
127- import_codeobj ( vm, module_name, vm . ctx . new_code_object ( code) , true )
127+ import_codeobj ( vm, module_name, code, true )
128128}
129129
130130pub fn import_codeobj (
131131 vm : & VirtualMachine ,
132132 module_name : & str ,
133- code_obj : CodeObject ,
133+ code_obj : PyRef < PyCode > ,
134134 set_file_attr : bool ,
135135) -> PyResult {
136136 let attrs = vm. ctx . new_dict ( ) ;
@@ -145,10 +145,7 @@ pub fn import_codeobj(
145145 sys_modules. set_item ( module_name, module. clone ( ) , vm) ?;
146146
147147 // Execute main code in module:
148- vm. run_code_obj (
149- code:: PyCode :: new ( code_obj) . into_ref ( vm) ,
150- Scope :: with_builtins ( None , attrs, vm) ,
151- ) ?;
148+ vm. run_code_obj ( code_obj, Scope :: with_builtins ( None , attrs, vm) ) ?;
152149 Ok ( module)
153150}
154151
0 commit comments