forked from RustPython/RustPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjframe.rs
More file actions
71 lines (58 loc) · 1.58 KB
/
objframe.rs
File metadata and controls
71 lines (58 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*! The python `frame` type.
*/
use super::objcode::PyCodeRef;
use super::objdict::PyDictRef;
use crate::frame::FrameRef;
use crate::pyobject::{IdProtocol, PyClassImpl, PyContext, PyResult};
use crate::vm::VirtualMachine;
pub fn init(context: &PyContext) {
FrameRef::extend_class(context, &context.types.frame_type);
}
#[pyimpl]
impl FrameRef {
#[pyslot]
fn tp_new(_cls: FrameRef, vm: &VirtualMachine) -> PyResult<Self> {
Err(vm.new_type_error("Cannot directly create frame object".to_owned()))
}
#[pymethod(name = "__repr__")]
fn repr(self) -> String {
"<frame object at .. >".to_owned()
}
#[pymethod]
fn clear(self) {
// TODO
}
#[pyproperty]
fn f_globals(self) -> PyDictRef {
self.scope.globals.clone()
}
#[pyproperty]
fn f_locals(self) -> PyDictRef {
self.scope.get_locals()
}
#[pyproperty]
fn f_code(self) -> PyCodeRef {
self.code.clone()
}
#[pyproperty]
fn f_back(self, vm: &VirtualMachine) -> Option<FrameRef> {
// TODO: actually store f_back inside Frame struct
// get the frame in the frame stack that appears before this one.
// won't work if this frame isn't in the frame stack, hence the todo above
vm.frames
.borrow()
.iter()
.rev()
.skip_while(|p| !p.is(&self))
.nth(1)
.cloned()
}
#[pyproperty]
fn f_lasti(self) -> usize {
self.lasti()
}
#[pyproperty]
fn f_lineno(self) -> usize {
self.current_location().row()
}
}