Skip to content

Commit 53e4591

Browse files
frame
1 parent c1180fc commit 53e4591

File tree

4 files changed

+14
-18
lines changed

4 files changed

+14
-18
lines changed

vm/src/frame.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ use crate::obj::objlist;
2121
use crate::obj::objstr;
2222
use crate::obj::objtype;
2323
use crate::pyobject::{
24-
DictProtocol, IdProtocol, PyFuncArgs, PyObject, PyObjectPayload, PyObjectRef, PyResult,
25-
TryFromObject, TypeProtocol,
24+
DictProtocol, IdProtocol, PyContext, PyFuncArgs, PyObject, PyObjectPayload, PyObjectPayload2,
25+
PyObjectRef, PyResult, TryFromObject, TypeProtocol,
2626
};
2727
use crate::vm::VirtualMachine;
2828

@@ -76,6 +76,12 @@ pub struct Frame {
7676
pub lasti: RefCell<usize>, // index of last instruction ran
7777
}
7878

79+
impl PyObjectPayload2 for Frame {
80+
fn required_type(ctx: &PyContext) -> PyObjectRef {
81+
ctx.frame_type()
82+
}
83+
}
84+
7985
// Running a frame can result in one of the below:
8086
pub enum ExecutionResult {
8187
Return(PyObjectRef),

vm/src/obj/objframe.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
*/
44

55
use crate::frame::Frame;
6-
use crate::pyobject::{
7-
PyContext, PyFuncArgs, PyObjectPayload, PyObjectRef, PyResult, TypeProtocol,
8-
};
6+
use crate::pyobject::{PyContext, PyFuncArgs, PyObjectRef, PyResult, TypeProtocol};
97
use crate::vm::VirtualMachine;
108

119
pub fn init(context: &PyContext) {
@@ -39,9 +37,5 @@ fn frame_fcode(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
3937
}
4038

4139
pub fn get_value(obj: &PyObjectRef) -> &Frame {
42-
if let PyObjectPayload::Frame { frame } = &obj.payload {
43-
frame
44-
} else {
45-
panic!("Inner error getting int {:?}", obj);
46-
}
40+
&obj.payload::<Frame>().unwrap()
4741
}

vm/src/obj/objgenerator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* The mythical generator.
33
*/
44

5-
use crate::frame::ExecutionResult;
5+
use crate::frame::{ExecutionResult, Frame};
66
use crate::pyobject::{
77
PyContext, PyFuncArgs, PyObject, PyObjectPayload, PyObjectRef, PyResult, TypeProtocol,
88
};
@@ -56,7 +56,7 @@ fn generator_send(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
5656

5757
fn send(vm: &mut VirtualMachine, gen: &PyObjectRef, value: &PyObjectRef) -> PyResult {
5858
if let PyObjectPayload::Generator { ref frame } = gen.payload {
59-
if let PyObjectPayload::Frame { ref frame } = frame.payload {
59+
if let Some(frame) = frame.payload::<Frame>() {
6060
frame.push_value(value.clone());
6161
} else {
6262
panic!("Generator frame isn't a frame.");

vm/src/pyobject.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,8 @@ impl PyContext {
625625

626626
pub fn new_frame(&self, code: PyObjectRef, scope: ScopeRef) -> PyObjectRef {
627627
PyObject::new(
628-
PyObjectPayload::Frame {
629-
frame: Frame::new(code, scope),
628+
PyObjectPayload::AnyRustValue {
629+
value: Box::new(Frame::new(code, scope)),
630630
},
631631
self.frame_type(),
632632
)
@@ -1508,9 +1508,6 @@ pub enum PyObjectPayload {
15081508
MemoryView {
15091509
obj: PyObjectRef,
15101510
},
1511-
Frame {
1512-
frame: Frame,
1513-
},
15141511
Generator {
15151512
frame: PyObjectRef,
15161513
},
@@ -1538,7 +1535,6 @@ impl fmt::Debug for PyObjectPayload {
15381535
PyObjectPayload::Iterator { .. } => write!(f, "iterator"),
15391536
PyObjectPayload::Slice { .. } => write!(f, "slice"),
15401537
PyObjectPayload::Generator { .. } => write!(f, "generator"),
1541-
PyObjectPayload::Frame { .. } => write!(f, "frame"),
15421538
PyObjectPayload::AnyRustValue { value } => value.fmt(f),
15431539
}
15441540
}

0 commit comments

Comments
 (0)