Skip to content

Commit e2e13af

Browse files
Remove PyObjectPayload
1 parent 45bc8c8 commit e2e13af

26 files changed

+210
-468
lines changed

vm/src/compile.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use crate::bytecode::{self, CallType, CodeObject, Instruction};
99
use crate::error::CompileError;
1010
use crate::obj::objcode;
11-
use crate::pyobject::{PyObject, PyObjectPayload, PyObjectRef};
11+
use crate::pyobject::{PyObject, PyObjectRef};
1212
use num_complex::Complex64;
1313
use rustpython_parser::{ast, parser};
1414

@@ -50,9 +50,7 @@ pub fn compile(
5050
let code = compiler.pop_code_object();
5151
trace!("Compilation completed: {:?}", code);
5252
Ok(PyObject::new(
53-
PyObjectPayload::AnyRustValue {
54-
value: Box::new(objcode::PyCode::new(code)),
55-
},
53+
Box::new(objcode::PyCode::new(code)),
5654
code_type,
5755
))
5856
}

vm/src/frame.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ use crate::obj::objslice::PySlice;
2222
use crate::obj::objstr;
2323
use crate::obj::objtype;
2424
use crate::pyobject::{
25-
DictProtocol, IdProtocol, PyContext, PyFuncArgs, PyObject, PyObjectPayload, PyObjectPayload2,
26-
PyObjectRef, PyResult, TryFromObject, TypeProtocol,
25+
DictProtocol, IdProtocol, PyContext, PyFuncArgs, PyObject, PyObjectPayload2, PyObjectRef,
26+
PyResult, TryFromObject, TypeProtocol,
2727
};
2828
use crate::vm::VirtualMachine;
2929

@@ -407,12 +407,8 @@ impl Frame {
407407
let stop = out[1].take();
408408
let step = if out.len() == 3 { out[2].take() } else { None };
409409

410-
let obj = PyObject::new(
411-
PyObjectPayload::AnyRustValue {
412-
value: Box::new(PySlice { start, stop, step }),
413-
},
414-
vm.ctx.slice_type(),
415-
);
410+
let obj =
411+
PyObject::new(Box::new(PySlice { start, stop, step }), vm.ctx.slice_type());
416412
self.push_value(obj);
417413
Ok(None)
418414
}
@@ -706,11 +702,9 @@ impl Frame {
706702
}
707703
bytecode::Instruction::LoadBuildClass => {
708704
let rustfunc = PyObject::new(
709-
PyObjectPayload::AnyRustValue {
710-
value: Box::new(PyBuiltinFunction::new(Box::new(
711-
builtins::builtin_build_class_,
712-
))),
713-
},
705+
Box::new(PyBuiltinFunction::new(Box::new(
706+
builtins::builtin_build_class_,
707+
))),
714708
vm.ctx.type_type(),
715709
);
716710
self.push_value(rustfunc);

vm/src/obj/objbytearray.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ use std::fmt::Write;
55
use std::ops::{Deref, DerefMut};
66

77
use crate::pyobject::{
8-
PyContext, PyFuncArgs, PyObject, PyObjectPayload, PyObjectPayload2, PyObjectRef, PyResult,
9-
TypeProtocol,
8+
PyContext, PyFuncArgs, PyObject, PyObjectPayload2, PyObjectRef, PyResult, TypeProtocol,
109
};
1110

1211
use super::objint;
@@ -174,9 +173,7 @@ fn bytearray_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
174173
vec![]
175174
};
176175
Ok(PyObject::new(
177-
PyObjectPayload::AnyRustValue {
178-
value: Box::new(PyByteArray::new(value)),
179-
},
176+
Box::new(PyByteArray::new(value)),
180177
cls.clone(),
181178
))
182179
}

vm/src/obj/objbytes.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use std::ops::Deref;
55
use super::objint;
66
use super::objtype;
77
use crate::pyobject::{
8-
PyContext, PyFuncArgs, PyIteratorValue, PyObject, PyObjectPayload, PyObjectPayload2,
9-
PyObjectRef, PyResult, TypeProtocol,
8+
PyContext, PyFuncArgs, PyIteratorValue, PyObject, PyObjectPayload2, PyObjectRef, PyResult,
9+
TypeProtocol,
1010
};
1111
use crate::vm::VirtualMachine;
1212
use num_traits::ToPrimitive;
@@ -95,12 +95,7 @@ fn bytes_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
9595
vec![]
9696
};
9797

98-
Ok(PyObject::new(
99-
PyObjectPayload::AnyRustValue {
100-
value: Box::new(PyBytes::new(value)),
101-
},
102-
cls.clone(),
103-
))
98+
Ok(PyObject::new(Box::new(PyBytes::new(value)), cls.clone()))
10499
}
105100

106101
fn bytes_eq(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
@@ -209,12 +204,10 @@ fn bytes_iter(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
209204
arg_check!(vm, args, required = [(obj, Some(vm.ctx.bytes_type()))]);
210205

211206
let iter_obj = PyObject::new(
212-
PyObjectPayload::AnyRustValue {
213-
value: Box::new(PyIteratorValue {
214-
position: Cell::new(0),
215-
iterated_obj: obj.clone(),
216-
}),
217-
},
207+
Box::new(PyIteratorValue {
208+
position: Cell::new(0),
209+
iterated_obj: obj.clone(),
210+
}),
218211
vm.ctx.iter_type(),
219212
);
220213

vm/src/obj/objcomplex.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ use super::objfloat;
22
use super::objint;
33
use super::objtype;
44
use crate::pyobject::{
5-
PyContext, PyFuncArgs, PyObject, PyObjectPayload, PyObjectPayload2, PyObjectRef, PyResult,
6-
TypeProtocol,
5+
PyContext, PyFuncArgs, PyObject, PyObjectPayload2, PyObjectRef, PyResult, TypeProtocol,
76
};
87
use crate::vm::VirtualMachine;
98
use num_complex::Complex64;
@@ -90,12 +89,7 @@ fn complex_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
9089

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

93-
Ok(PyObject::new(
94-
PyObjectPayload::AnyRustValue {
95-
value: Box::new(PyComplex { value }),
96-
},
97-
cls.clone(),
98-
))
92+
Ok(PyObject::new(Box::new(PyComplex { value }), cls.clone()))
9993
}
10094

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

vm/src/obj/objdict.rs

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use std::collections::HashMap;
33
use std::ops::{Deref, DerefMut};
44

55
use crate::pyobject::{
6-
PyAttributes, PyContext, PyFuncArgs, PyIteratorValue, PyObject, PyObjectPayload,
7-
PyObjectPayload2, PyObjectRef, PyRef, PyResult, TypeProtocol,
6+
PyAttributes, PyContext, PyFuncArgs, PyIteratorValue, PyObject, PyObjectPayload2, PyObjectRef,
7+
PyRef, PyResult, TypeProtocol,
88
};
99
use crate::vm::{ReprGuard, VirtualMachine};
1010

@@ -251,12 +251,10 @@ fn dict_iter(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
251251
let key_list = vm.ctx.new_list(keys);
252252

253253
let iter_obj = PyObject::new(
254-
PyObjectPayload::AnyRustValue {
255-
value: Box::new(PyIteratorValue {
256-
position: Cell::new(0),
257-
iterated_obj: key_list,
258-
}),
259-
},
254+
Box::new(PyIteratorValue {
255+
position: Cell::new(0),
256+
iterated_obj: key_list,
257+
}),
260258
vm.ctx.iter_type(),
261259
);
262260

@@ -273,12 +271,10 @@ fn dict_values(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
273271
let values_list = vm.ctx.new_list(values);
274272

275273
let iter_obj = PyObject::new(
276-
PyObjectPayload::AnyRustValue {
277-
value: Box::new(PyIteratorValue {
278-
position: Cell::new(0),
279-
iterated_obj: values_list,
280-
}),
281-
},
274+
Box::new(PyIteratorValue {
275+
position: Cell::new(0),
276+
iterated_obj: values_list,
277+
}),
282278
vm.ctx.iter_type(),
283279
);
284280

@@ -295,12 +291,10 @@ fn dict_items(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
295291
let items_list = vm.ctx.new_list(items);
296292

297293
let iter_obj = PyObject::new(
298-
PyObjectPayload::AnyRustValue {
299-
value: Box::new(PyIteratorValue {
300-
position: Cell::new(0),
301-
iterated_obj: items_list,
302-
}),
303-
},
294+
Box::new(PyIteratorValue {
295+
position: Cell::new(0),
296+
iterated_obj: items_list,
297+
}),
304298
vm.ctx.iter_type(),
305299
);
306300

@@ -348,12 +342,10 @@ pub fn create_type(type_type: PyObjectRef, object_type: PyObjectRef, dict_type:
348342
// this is not ideal
349343
let ptr = PyObjectRef::into_raw(dict_type.clone()) as *mut PyObject;
350344
unsafe {
351-
(*ptr).payload = PyObjectPayload::AnyRustValue {
352-
value: Box::new(objtype::PyClass {
353-
name: String::from("dict"),
354-
mro: vec![object_type],
355-
}),
356-
};
345+
(*ptr).payload = Box::new(objtype::PyClass {
346+
name: String::from("dict"),
347+
mro: vec![object_type],
348+
});
357349
(*ptr).dict = Some(RefCell::new(HashMap::new()));
358350
(*ptr).typ = Some(type_type.clone());
359351
}

vm/src/obj/objenumerate.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ use std::ops::AddAssign;
44
use super::objint;
55
use super::objiter;
66
use crate::pyobject::{
7-
PyContext, PyFuncArgs, PyObject, PyObjectPayload, PyObjectPayload2, PyObjectRef, PyResult,
8-
TypeProtocol,
7+
PyContext, PyFuncArgs, PyObject, PyObjectPayload2, PyObjectRef, PyResult, TypeProtocol,
98
};
109
use crate::vm::VirtualMachine;
1110
use num_bigint::BigInt;
@@ -37,12 +36,10 @@ fn enumerate_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
3736
};
3837
let iterator = objiter::get_iter(vm, iterable)?;
3938
Ok(PyObject::new(
40-
PyObjectPayload::AnyRustValue {
41-
value: Box::new(PyEnumerate {
42-
counter: RefCell::new(counter),
43-
iterator,
44-
}),
45-
},
39+
Box::new(PyEnumerate {
40+
counter: RefCell::new(counter),
41+
iterator,
42+
}),
4643
cls.clone(),
4744
))
4845
}

vm/src/obj/objfilter.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::pyobject::{
2-
IdProtocol, PyContext, PyFuncArgs, PyObject, PyObjectPayload, PyObjectPayload2, PyObjectRef,
3-
PyResult, TypeProtocol,
2+
IdProtocol, PyContext, PyFuncArgs, PyObject, PyObjectPayload2, PyObjectRef, PyResult,
3+
TypeProtocol,
44
};
55
use crate::vm::VirtualMachine; // Required for arg_check! to use isinstance
66

@@ -27,12 +27,10 @@ fn filter_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
2727
);
2828
let iterator = objiter::get_iter(vm, iterable)?;
2929
Ok(PyObject::new(
30-
PyObjectPayload::AnyRustValue {
31-
value: Box::new(PyFilter {
32-
predicate: function.clone(),
33-
iterator,
34-
}),
35-
},
30+
Box::new(PyFilter {
31+
predicate: function.clone(),
32+
iterator,
33+
}),
3634
cls.clone(),
3735
))
3836
}

vm/src/obj/objfloat.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ use super::objint;
33
use super::objstr;
44
use super::objtype;
55
use crate::pyobject::{
6-
IntoPyObject, PyContext, PyObject, PyObjectPayload, PyObjectPayload2, PyObjectRef, PyRef,
7-
PyResult, TypeProtocol,
6+
IntoPyObject, PyContext, PyObject, PyObjectPayload2, PyObjectRef, PyRef, PyResult, TypeProtocol,
87
};
98
use crate::vm::VirtualMachine;
109
use num_bigint::ToBigInt;
@@ -189,12 +188,7 @@ impl PyFloatRef {
189188
let type_name = objtype::get_type_name(&arg.typ());
190189
return Err(vm.new_type_error(format!("can't convert {} to float", type_name)));
191190
};
192-
Ok(PyObject::new(
193-
PyObjectPayload::AnyRustValue {
194-
value: Box::new(PyFloat { value }),
195-
},
196-
cls.clone(),
197-
))
191+
Ok(PyObject::new(Box::new(PyFloat { value }), cls.clone()))
198192
}
199193

200194
fn mod_(self, other: PyObjectRef, vm: &mut VirtualMachine) -> PyResult {

vm/src/obj/objgenerator.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
use crate::frame::{ExecutionResult, Frame};
66
use crate::pyobject::{
7-
PyContext, PyFuncArgs, PyObject, PyObjectPayload, PyObjectPayload2, PyObjectRef, PyResult,
8-
TypeProtocol,
7+
PyContext, PyFuncArgs, PyObject, PyObjectPayload2, PyObjectRef, PyResult, TypeProtocol,
98
};
109
use crate::vm::VirtualMachine;
1110

@@ -41,9 +40,7 @@ pub fn init(context: &PyContext) {
4140

4241
pub fn new_generator(vm: &mut VirtualMachine, frame: PyObjectRef) -> PyResult {
4342
Ok(PyObject::new(
44-
PyObjectPayload::AnyRustValue {
45-
value: Box::new(PyGenerator { frame }),
46-
},
43+
Box::new(PyGenerator { frame }),
4744
vm.ctx.generator_type.clone(),
4845
))
4946
}

vm/src/obj/objint.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use num_traits::{Pow, Signed, ToPrimitive, Zero};
66

77
use crate::format::FormatSpec;
88
use crate::pyobject::{
9-
FromPyObjectRef, IntoPyObject, PyContext, PyFuncArgs, PyObject, PyObjectPayload,
10-
PyObjectPayload2, PyObjectRef, PyRef, PyResult, TryFromObject, TypeProtocol,
9+
FromPyObjectRef, IntoPyObject, PyContext, PyFuncArgs, PyObject, PyObjectPayload2, PyObjectRef,
10+
PyRef, PyResult, TryFromObject, TypeProtocol,
1111
};
1212
use crate::vm::VirtualMachine;
1313

@@ -105,12 +105,7 @@ fn int_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
105105
Some(val) => to_int(vm, val, base)?,
106106
None => Zero::zero(),
107107
};
108-
Ok(PyObject::new(
109-
PyObjectPayload::AnyRustValue {
110-
value: Box::new(PyInt::new(val)),
111-
},
112-
cls.clone(),
113-
))
108+
Ok(PyObject::new(Box::new(PyInt::new(val)), cls.clone()))
114109
}
115110

116111
// Casting function:

vm/src/obj/objlist.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use super::objsequence::{
99
use super::objstr;
1010
use super::objtype;
1111
use crate::pyobject::{
12-
IdProtocol, OptionalArg, PyContext, PyFuncArgs, PyIteratorValue, PyObject, PyObjectPayload,
13-
PyObjectPayload2, PyObjectRef, PyRef, PyResult, TypeProtocol,
12+
IdProtocol, OptionalArg, PyContext, PyFuncArgs, PyIteratorValue, PyObject, PyObjectPayload2,
13+
PyObjectRef, PyRef, PyResult, TypeProtocol,
1414
};
1515
use crate::vm::{ReprGuard, VirtualMachine};
1616
use num_traits::ToPrimitive;
@@ -111,12 +111,10 @@ impl PyListRef {
111111

112112
fn iter(self, vm: &mut VirtualMachine) -> PyObjectRef {
113113
PyObject::new(
114-
PyObjectPayload::AnyRustValue {
115-
value: Box::new(PyIteratorValue {
116-
position: Cell::new(0),
117-
iterated_obj: self.into_object(),
118-
}),
119-
},
114+
Box::new(PyIteratorValue {
115+
position: Cell::new(0),
116+
iterated_obj: self.into_object(),
117+
}),
120118
vm.ctx.iter_type(),
121119
)
122120
}
@@ -305,9 +303,7 @@ fn list_new(
305303
};
306304

307305
Ok(PyObject::new(
308-
PyObjectPayload::AnyRustValue {
309-
value: Box::new(PyList::from(elements)),
310-
},
306+
Box::new(PyList::from(elements)),
311307
cls.into_object(),
312308
))
313309
}

0 commit comments

Comments
 (0)