@@ -570,15 +570,9 @@ impl VirtualMachine {
570570 fn _invoke ( & self , func_ref : & PyObjectRef , args : PyFuncArgs ) -> PyResult {
571571 vm_trace ! ( "Invoke: {:?} {:?}" , func_ref, args) ;
572572
573- if let Some ( PyFunction {
574- ref code,
575- ref scope,
576- ref defaults,
577- ref kw_only_defaults,
578- } ) = func_ref. payload ( )
579- {
573+ if let Some ( py_func) = func_ref. payload ( ) {
580574 self . trace_event ( TraceEvent :: Call ) ?;
581- let res = self . invoke_python_function ( code , scope , defaults , kw_only_defaults , args) ;
575+ let res = self . invoke_python_function ( py_func , args) ;
582576 self . trace_event ( TraceEvent :: Return ) ?;
583577 res
584578 } else if let Some ( PyMethod {
@@ -634,21 +628,30 @@ impl VirtualMachine {
634628 Ok ( ( ) )
635629 }
636630
637- fn invoke_python_function (
631+ pub fn invoke_python_function ( & self , func : & PyFunction , func_args : PyFuncArgs ) -> PyResult {
632+ self . invoke_python_function_with_scope ( func, func_args, & func. scope )
633+ }
634+
635+ pub fn invoke_python_function_with_scope (
638636 & self ,
639- code : & PyCodeRef ,
640- scope : & Scope ,
641- defaults : & Option < PyTupleRef > ,
642- kw_only_defaults : & Option < PyDictRef > ,
637+ func : & PyFunction ,
643638 func_args : PyFuncArgs ,
639+ scope : & Scope ,
644640 ) -> PyResult {
645- let scope = scope. new_child_scope ( & self . ctx ) ;
641+ let code = & func. code ;
642+
643+ let scope = if func. new_locals {
644+ scope. new_child_scope ( & self . ctx )
645+ } else {
646+ scope. clone ( )
647+ } ;
648+
646649 self . fill_locals_from_args (
647650 & code. code ,
648651 & scope. get_locals ( ) ,
649652 func_args,
650- defaults,
651- kw_only_defaults,
653+ & func . defaults ,
654+ & func . kw_only_defaults ,
652655 ) ?;
653656
654657 // Construct frame:
@@ -662,25 +665,6 @@ impl VirtualMachine {
662665 }
663666 }
664667
665- pub fn invoke_with_locals (
666- & self ,
667- function : & PyObjectRef ,
668- cells : PyDictRef ,
669- locals : PyDictRef ,
670- ) -> PyResult {
671- if let Some ( PyFunction { code, scope, .. } ) = & function. payload ( ) {
672- let scope = scope
673- . new_child_scope_with_locals ( cells)
674- . new_child_scope_with_locals ( locals) ;
675- let frame = Frame :: new ( code. clone ( ) , scope) . into_ref ( self ) ;
676- return self . run_frame_full ( frame) ;
677- }
678- panic ! (
679- "invoke_with_locals: expected python function, got: {:?}" ,
680- * function
681- ) ;
682- }
683-
684668 fn fill_locals_from_args (
685669 & self ,
686670 code_object : & bytecode:: CodeObject ,
0 commit comments