Skip to content

Remove PyObjectPayload enum #653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 2 additions & 7 deletions vm/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use crate::bytecode::{self, CallType, CodeObject, Instruction};
use crate::error::CompileError;
use crate::obj::objcode;
use crate::pyobject::{PyObject, PyObjectPayload, PyObjectRef};
use crate::pyobject::{PyObject, PyObjectRef};
use num_complex::Complex64;
use rustpython_parser::{ast, parser};

Expand Down Expand Up @@ -49,12 +49,7 @@ pub fn compile(

let code = compiler.pop_code_object();
trace!("Compilation completed: {:?}", code);
Ok(PyObject::new(
PyObjectPayload::AnyRustValue {
value: Box::new(objcode::PyCode::new(code)),
},
code_type,
))
Ok(PyObject::new(objcode::PyCode::new(code), code_type))
}

pub enum Mode {
Expand Down
19 changes: 5 additions & 14 deletions vm/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use crate::obj::objslice::PySlice;
use crate::obj::objstr;
use crate::obj::objtype;
use crate::pyobject::{
DictProtocol, IdProtocol, PyContext, PyFuncArgs, PyObject, PyObjectPayload, PyObjectPayload2,
PyObjectRef, PyResult, TryFromObject, TypeProtocol,
DictProtocol, IdProtocol, PyContext, PyFuncArgs, PyObject, PyObjectRef, PyResult, PyValue,
TryFromObject, TypeProtocol,
};
use crate::vm::VirtualMachine;

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

impl PyObjectPayload2 for Frame {
impl PyValue for Frame {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find myself mixed on this changed - probably just because I'm used to Payload now. I'm sure I'll get used to PyValue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking was that this would be easier to understand for project newcomers - e.g. it feels like it'd be easier to explain that a PyRef is a reference to some type that is a PyValue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm always attached to old names :), but I also feel PyPayload better reflects the fact that it is not a Python value, but a rust inner data for a Python value. That being said, we can always change it later.

fn required_type(ctx: &PyContext) -> PyObjectRef {
ctx.frame_type()
}
Expand Down Expand Up @@ -407,12 +407,7 @@ impl Frame {
let stop = out[1].take();
let step = if out.len() == 3 { out[2].take() } else { None };

let obj = PyObject::new(
PyObjectPayload::AnyRustValue {
value: Box::new(PySlice { start, stop, step }),
},
vm.ctx.slice_type(),
);
let obj = PyObject::new(PySlice { start, stop, step }, vm.ctx.slice_type());
self.push_value(obj);
Ok(None)
}
Expand Down Expand Up @@ -706,11 +701,7 @@ impl Frame {
}
bytecode::Instruction::LoadBuildClass => {
let rustfunc = PyObject::new(
PyObjectPayload::AnyRustValue {
value: Box::new(PyBuiltinFunction::new(Box::new(
builtins::builtin_build_class_,
))),
},
PyBuiltinFunction::new(Box::new(builtins::builtin_build_class_)),
vm.ctx.type_type(),
);
self.push_value(rustfunc);
Expand Down
118 changes: 0 additions & 118 deletions vm/src/function.rs

This file was deleted.

1 change: 0 additions & 1 deletion vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ pub mod eval;
mod exceptions;
pub mod format;
pub mod frame;
pub mod function;
pub mod import;
pub mod obj;
pub mod pyobject;
Expand Down
4 changes: 2 additions & 2 deletions vm/src/obj/objbuiltinfunc.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::fmt;

use crate::pyobject::{PyContext, PyNativeFunc, PyObjectPayload2, PyObjectRef};
use crate::pyobject::{PyContext, PyNativeFunc, PyObjectRef, PyValue};

pub struct PyBuiltinFunction {
// TODO: shouldn't be public
pub value: PyNativeFunc,
}

impl PyObjectPayload2 for PyBuiltinFunction {
impl PyValue for PyBuiltinFunction {
fn required_type(ctx: &PyContext) -> PyObjectRef {
ctx.builtin_function_or_method_type()
}
Expand Down
12 changes: 3 additions & 9 deletions vm/src/obj/objbytearray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use std::fmt::Write;
use std::ops::{Deref, DerefMut};

use crate::pyobject::{
PyContext, PyFuncArgs, PyObject, PyObjectPayload, PyObjectPayload2, PyObjectRef, PyResult,
TypeProtocol,
PyContext, PyFuncArgs, PyObject, PyObjectRef, PyResult, PyValue, TypeProtocol,
};

use super::objint;
Expand All @@ -29,7 +28,7 @@ impl PyByteArray {
}
}

impl PyObjectPayload2 for PyByteArray {
impl PyValue for PyByteArray {
fn required_type(ctx: &PyContext) -> PyObjectRef {
ctx.bytearray_type()
}
Expand Down Expand Up @@ -173,12 +172,7 @@ fn bytearray_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
} else {
vec![]
};
Ok(PyObject::new(
PyObjectPayload::AnyRustValue {
value: Box::new(PyByteArray::new(value)),
},
cls.clone(),
))
Ok(PyObject::new(PyByteArray::new(value), cls.clone()))
}

fn bytesarray_len(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
Expand Down
20 changes: 6 additions & 14 deletions vm/src/obj/objbytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use std::ops::Deref;
use super::objint;
use super::objtype;
use crate::pyobject::{
PyContext, PyFuncArgs, PyIteratorValue, PyObject, PyObjectPayload, PyObjectPayload2,
PyObjectRef, PyResult, TypeProtocol,
PyContext, PyFuncArgs, PyIteratorValue, PyObject, PyObjectRef, PyResult, PyValue, TypeProtocol,
};
use crate::vm::VirtualMachine;
use num_traits::ToPrimitive;
Expand All @@ -30,7 +29,7 @@ impl Deref for PyBytes {
}
}

impl PyObjectPayload2 for PyBytes {
impl PyValue for PyBytes {
fn required_type(ctx: &PyContext) -> PyObjectRef {
ctx.bytes_type()
}
Expand Down Expand Up @@ -95,12 +94,7 @@ fn bytes_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
vec![]
};

Ok(PyObject::new(
PyObjectPayload::AnyRustValue {
value: Box::new(PyBytes::new(value)),
},
cls.clone(),
))
Ok(PyObject::new(PyBytes::new(value), cls.clone()))
}

fn bytes_eq(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
Expand Down Expand Up @@ -209,11 +203,9 @@ fn bytes_iter(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
arg_check!(vm, args, required = [(obj, Some(vm.ctx.bytes_type()))]);

let iter_obj = PyObject::new(
PyObjectPayload::AnyRustValue {
value: Box::new(PyIteratorValue {
position: Cell::new(0),
iterated_obj: obj.clone(),
}),
PyIteratorValue {
position: Cell::new(0),
iterated_obj: obj.clone(),
},
vm.ctx.iter_type(),
);
Expand Down
4 changes: 2 additions & 2 deletions vm/src/obj/objcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use crate::bytecode;
use crate::pyobject::{
IdProtocol, PyContext, PyFuncArgs, PyObjectPayload2, PyObjectRef, PyResult, TypeProtocol,
IdProtocol, PyContext, PyFuncArgs, PyObjectRef, PyResult, PyValue, TypeProtocol,
};
use crate::vm::VirtualMachine;
use std::fmt;
Expand All @@ -25,7 +25,7 @@ impl fmt::Debug for PyCode {
}
}

impl PyObjectPayload2 for PyCode {
impl PyValue for PyCode {
fn required_type(ctx: &PyContext) -> PyObjectRef {
ctx.code_type()
}
Expand Down
12 changes: 3 additions & 9 deletions vm/src/obj/objcomplex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use super::objfloat;
use super::objint;
use super::objtype;
use crate::pyobject::{
PyContext, PyFuncArgs, PyObject, PyObjectPayload, PyObjectPayload2, PyObjectRef, PyResult,
TypeProtocol,
PyContext, PyFuncArgs, PyObject, PyObjectRef, PyResult, PyValue, TypeProtocol,
};
use crate::vm::VirtualMachine;
use num_complex::Complex64;
Expand All @@ -14,7 +13,7 @@ pub struct PyComplex {
value: Complex64,
}

impl PyObjectPayload2 for PyComplex {
impl PyValue for PyComplex {
fn required_type(ctx: &PyContext) -> PyObjectRef {
ctx.complex_type()
}
Expand Down Expand Up @@ -90,12 +89,7 @@ fn complex_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {

let value = Complex64::new(real, imag);

Ok(PyObject::new(
PyObjectPayload::AnyRustValue {
value: Box::new(PyComplex { value }),
},
cls.clone(),
))
Ok(PyObject::new(PyComplex { value }, cls.clone()))
}

fn complex_real(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
Expand Down
Loading