@@ -10,19 +10,17 @@ use crate::common::cell::PyMutex;
1010use crate :: exceptions:: { self , ExceptionCtor , PyBaseExceptionRef } ;
1111use crate :: function:: PyFuncArgs ;
1212use crate :: obj:: objasyncgenerator:: PyAsyncGenWrappedValue ;
13- use crate :: obj:: objbool;
1413use crate :: obj:: objcode:: PyCodeRef ;
1514use crate :: obj:: objcoroinner:: Coro ;
1615use crate :: obj:: objcoroutine:: PyCoroutine ;
1716use crate :: obj:: objdict:: { PyDict , PyDictRef } ;
1817use crate :: obj:: objgenerator:: PyGenerator ;
19- use crate :: obj:: objiter;
20- use crate :: obj:: objlist;
2118use crate :: obj:: objslice:: PySlice ;
2219use crate :: obj:: objstr:: { self , PyStr , PyStrRef } ;
2320use crate :: obj:: objtraceback:: PyTraceback ;
2421use crate :: obj:: objtuple:: PyTuple ;
2522use crate :: obj:: objtype:: { self , PyTypeRef } ;
23+ use crate :: obj:: { objbool, objiter, objlist, objset} ;
2624use crate :: pyobject:: {
2725 BorrowValue , IdProtocol , ItemProtocol , PyObjectRef , PyRef , PyResult , PyValue , TryFromObject ,
2826 TypeProtocol ,
@@ -177,6 +175,7 @@ impl Frame {
177175}
178176
179177impl FrameRef {
178+ #[ inline]
180179 fn with_exec < R > ( & self , f : impl FnOnce ( ExecutingFrame ) -> R ) -> R {
181180 let mut state = self . state . lock ( ) ;
182181 let exec = ExecutingFrame {
@@ -350,14 +349,10 @@ impl ExecutingFrame<'_> {
350349 } => self . import ( vm, name, symbols, * level) ,
351350 bytecode:: Instruction :: ImportStar => self . import_star ( vm) ,
352351 bytecode:: Instruction :: ImportFrom { ref name } => self . import_from ( vm, name) ,
353- bytecode:: Instruction :: LoadName {
354- ref name,
355- ref scope,
356- } => self . load_name ( vm, name, scope) ,
357- bytecode:: Instruction :: StoreName {
358- ref name,
359- ref scope,
360- } => self . store_name ( vm, name, scope) ,
352+ bytecode:: Instruction :: LoadName { ref name, scope } => self . load_name ( vm, name, * scope) ,
353+ bytecode:: Instruction :: StoreName { ref name, scope } => {
354+ self . store_name ( vm, name, * scope)
355+ }
361356 bytecode:: Instruction :: DeleteName { ref name } => self . delete_name ( vm, name) ,
362357 bytecode:: Instruction :: Subscript => self . execute_subscript ( vm) ,
363358 bytecode:: Instruction :: StoreSubscript => self . execute_store_subscript ( vm) ,
@@ -393,11 +388,11 @@ impl ExecutingFrame<'_> {
393388 }
394389 bytecode:: Instruction :: BuildSet { size, unpack } => {
395390 let elements = self . get_elements ( vm, * size, * unpack) ?;
396- let py_obj = vm. ctx . new_set ( ) ;
391+ let set = vm. ctx . new_set ( ) ;
397392 for item in elements {
398- vm . call_method ( & py_obj , "add" , vec ! [ item ] ) ?;
393+ set . add ( item , vm ) ?;
399394 }
400- self . push_value ( py_obj ) ;
395+ self . push_value ( set . into_object ( ) ) ;
401396 Ok ( None )
402397 }
403398 bytecode:: Instruction :: BuildTuple { size, unpack } => {
@@ -421,22 +416,22 @@ impl ExecutingFrame<'_> {
421416 bytecode:: Instruction :: SetAdd { i } => {
422417 let set_obj = self . nth_value ( * i) ;
423418 let item = self . pop_value ( ) ;
424- vm . call_method ( & set_obj , " add" , vec ! [ item ] ) ?;
419+ objset :: PySetRef :: try_from_object ( vm , set_obj ) ? . add ( item , vm ) ?;
425420 Ok ( None )
426421 }
427422 bytecode:: Instruction :: MapAdd { i } => {
428423 let dict_obj = self . nth_value ( * i + 1 ) ;
429424 let key = self . pop_value ( ) ;
430425 let value = self . pop_value ( ) ;
431- vm . call_method ( & dict_obj , "__setitem__" , vec ! [ key, value] ) ?;
426+ PyDictRef :: try_from_object ( vm , dict_obj ) ? . set_item ( key, value, vm ) ?;
432427 Ok ( None )
433428 }
434429 bytecode:: Instruction :: MapAddRev { i } => {
435430 // change order of evalutio of key and value to support Py3.8 Named expressions in dict comprehension
436431 let dict_obj = self . nth_value ( * i + 1 ) ;
437432 let value = self . pop_value ( ) ;
438433 let key = self . pop_value ( ) ;
439- vm . call_method ( & dict_obj , "__setitem__" , vec ! [ key, value] ) ?;
434+ PyDictRef :: try_from_object ( vm , dict_obj ) ? . set_item ( key, value, vm ) ?;
440435 Ok ( None )
441436 }
442437 bytecode:: Instruction :: BinaryOperation { ref op, inplace } => {
@@ -882,7 +877,7 @@ impl ExecutingFrame<'_> {
882877 & mut self ,
883878 vm : & VirtualMachine ,
884879 name : & str ,
885- name_scope : & bytecode:: NameScope ,
880+ name_scope : bytecode:: NameScope ,
886881 ) -> FrameResult {
887882 let obj = self . pop_value ( ) ;
888883 match name_scope {
@@ -910,11 +905,12 @@ impl ExecutingFrame<'_> {
910905 }
911906
912907 #[ cfg_attr( feature = "flame-it" , flame( "Frame" ) ) ]
908+ #[ inline]
913909 fn load_name (
914910 & mut self ,
915911 vm : & VirtualMachine ,
916912 name : & str ,
917- name_scope : & bytecode:: NameScope ,
913+ name_scope : bytecode:: NameScope ,
918914 ) -> FrameResult {
919915 let optional_value = match name_scope {
920916 bytecode:: NameScope :: Global => self . scope . load_global ( vm, name) ,
@@ -1210,8 +1206,7 @@ impl ExecutingFrame<'_> {
12101206
12111207 fn jump ( & mut self , label : bytecode:: Label ) {
12121208 let target_pc = self . code . label_map [ & label] ;
1213- #[ cfg( feature = "vm-tracing-logging" ) ]
1214- trace ! ( "jump from {:?} to {:?}" , self . lasti( ) , target_pc) ;
1209+ vm_trace ! ( "jump from {:?} to {:?}" , self . lasti( ) , target_pc) ;
12151210 self . lasti . store ( target_pc, Ordering :: Relaxed ) ;
12161211 }
12171212
0 commit comments