Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
frame
  • Loading branch information
OddCoincidence committed Mar 9, 2019
commit 53e4591911947bd63530ffaa5947ebc3f7269b12
10 changes: 8 additions & 2 deletions vm/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use crate::obj::objlist;
use crate::obj::objstr;
use crate::obj::objtype;
use crate::pyobject::{
DictProtocol, IdProtocol, PyFuncArgs, PyObject, PyObjectPayload, PyObjectRef, PyResult,
TryFromObject, TypeProtocol,
DictProtocol, IdProtocol, PyContext, PyFuncArgs, PyObject, PyObjectPayload, PyObjectPayload2,
PyObjectRef, PyResult, TryFromObject, TypeProtocol,
};
use crate::vm::VirtualMachine;

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

impl PyObjectPayload2 for Frame {
fn required_type(ctx: &PyContext) -> PyObjectRef {
ctx.frame_type()
}
}

// Running a frame can result in one of the below:
pub enum ExecutionResult {
Return(PyObjectRef),
Expand Down
10 changes: 2 additions & 8 deletions vm/src/obj/objframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
*/

use crate::frame::Frame;
use crate::pyobject::{
PyContext, PyFuncArgs, PyObjectPayload, PyObjectRef, PyResult, TypeProtocol,
};
use crate::pyobject::{PyContext, PyFuncArgs, PyObjectRef, PyResult, TypeProtocol};
use crate::vm::VirtualMachine;

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

pub fn get_value(obj: &PyObjectRef) -> &Frame {
if let PyObjectPayload::Frame { frame } = &obj.payload {
frame
} else {
panic!("Inner error getting int {:?}", obj);
}
&obj.payload::<Frame>().unwrap()
}
4 changes: 2 additions & 2 deletions vm/src/obj/objgenerator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* The mythical generator.
*/

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

fn send(vm: &mut VirtualMachine, gen: &PyObjectRef, value: &PyObjectRef) -> PyResult {
if let PyObjectPayload::Generator { ref frame } = gen.payload {
if let PyObjectPayload::Frame { ref frame } = frame.payload {
if let Some(frame) = frame.payload::<Frame>() {
frame.push_value(value.clone());
} else {
panic!("Generator frame isn't a frame.");
Expand Down
8 changes: 2 additions & 6 deletions vm/src/pyobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,8 +625,8 @@ impl PyContext {

pub fn new_frame(&self, code: PyObjectRef, scope: ScopeRef) -> PyObjectRef {
PyObject::new(
PyObjectPayload::Frame {
frame: Frame::new(code, scope),
PyObjectPayload::AnyRustValue {
value: Box::new(Frame::new(code, scope)),
},
self.frame_type(),
)
Expand Down Expand Up @@ -1508,9 +1508,6 @@ pub enum PyObjectPayload {
MemoryView {
obj: PyObjectRef,
},
Frame {
frame: Frame,
},
Generator {
frame: PyObjectRef,
},
Expand Down Expand Up @@ -1538,7 +1535,6 @@ impl fmt::Debug for PyObjectPayload {
PyObjectPayload::Iterator { .. } => write!(f, "iterator"),
PyObjectPayload::Slice { .. } => write!(f, "slice"),
PyObjectPayload::Generator { .. } => write!(f, "generator"),
PyObjectPayload::Frame { .. } => write!(f, "frame"),
PyObjectPayload::AnyRustValue { value } => value.fmt(f),
}
}
Expand Down