File tree 1 file changed +23
-6
lines changed 1 file changed +23
-6
lines changed Original file line number Diff line number Diff line change 5
5
use super :: objcode:: PyCodeRef ;
6
6
use super :: objdict:: PyDictRef ;
7
7
use crate :: frame:: FrameRef ;
8
- use crate :: pyobject:: { PyClassImpl , PyContext , PyObjectRef , PyResult } ;
8
+ use crate :: pyobject:: { IdProtocol , PyClassImpl , PyContext , PyResult } ;
9
9
use crate :: vm:: VirtualMachine ;
10
10
11
11
pub fn init ( context : & PyContext ) {
@@ -45,13 +45,30 @@ impl FrameRef {
45
45
}
46
46
47
47
#[ pyproperty]
48
- fn f_back ( self , vm : & VirtualMachine ) -> PyObjectRef {
49
- // TODO: how to retrieve the upper stack frame??
50
- vm. ctx . none ( )
48
+ fn f_back ( self , vm : & VirtualMachine ) -> Option < FrameRef > {
49
+ // TODO: actually store f_back inside Frame struct
50
+
51
+ // get the frame in the frame stack that appears before this one.
52
+ // won't work if this frame isn't in the frame stack, hence the todo above
53
+ vm. frames
54
+ . borrow ( )
55
+ . iter ( )
56
+ . rev ( )
57
+ . skip_while ( |p| !p. is ( & self ) )
58
+ . nth ( 1 )
59
+ . cloned ( )
60
+ }
61
+
62
+ #[ pyproperty]
63
+ fn f_lasti ( self ) -> usize {
64
+ self . lasti . get ( )
51
65
}
52
66
53
67
#[ pyproperty]
54
- fn f_lasti ( self , vm : & VirtualMachine ) -> PyObjectRef {
55
- vm. ctx . new_int ( self . lasti . get ( ) )
68
+ fn f_lineno ( self ) -> Option < usize > {
69
+ self . code
70
+ . locations
71
+ . get ( self . lasti . get ( ) )
72
+ . map ( |loc| loc. row ( ) )
56
73
}
57
74
}
You can’t perform that action at this time.
0 commit comments