55use super :: objcode:: PyCodeRef ;
66use super :: objdict:: PyDictRef ;
77use crate :: frame:: FrameRef ;
8- use crate :: pyobject:: { PyContext , PyResult } ;
8+ use crate :: pyobject:: { PyContext , PyObjectRef , PyResult } ;
99use crate :: vm:: VirtualMachine ;
1010
1111pub fn init ( context : & PyContext ) {
1212 extend_class ! ( context, & context. frame_type, {
1313 "__new__" => context. new_rustfunc( FrameRef :: new) ,
1414 "__repr__" => context. new_rustfunc( FrameRef :: repr) ,
1515 "f_locals" => context. new_property( FrameRef :: flocals) ,
16+ "f_globals" => context. new_property( FrameRef :: f_globals) ,
1617 "f_code" => context. new_property( FrameRef :: fcode) ,
18+ "f_back" => context. new_property( FrameRef :: f_back) ,
19+ "f_lasti" => context. new_property( FrameRef :: f_lasti) ,
1720 } ) ;
1821}
1922
@@ -27,11 +30,24 @@ impl FrameRef {
2730 "<frame object at .. >" . to_string ( )
2831 }
2932
33+ fn f_globals ( self , _vm : & VirtualMachine ) -> PyDictRef {
34+ self . scope . globals . clone ( )
35+ }
36+
3037 fn flocals ( self , _vm : & VirtualMachine ) -> PyDictRef {
3138 self . scope . get_locals ( )
3239 }
3340
3441 fn fcode ( self , vm : & VirtualMachine ) -> PyCodeRef {
3542 vm. ctx . new_code_object ( self . code . clone ( ) )
3643 }
44+
45+ fn f_back ( self , vm : & VirtualMachine ) -> PyObjectRef {
46+ // TODO: how to retrieve the upper stack frame??
47+ vm. ctx . none ( )
48+ }
49+
50+ fn f_lasti ( self , vm : & VirtualMachine ) -> PyObjectRef {
51+ vm. ctx . new_int ( * self . lasti . borrow ( ) )
52+ }
3753}
0 commit comments