Skip to content

Commit 892493e

Browse files
committed
Rename PyObjectKind into PyObjectPayload
1 parent 31523fe commit 892493e

29 files changed

+283
-269
lines changed

vm/src/builtins.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use super::obj::objstr;
1515
use super::obj::objtype;
1616

1717
use super::pyobject::{
18-
AttributeProtocol, IdProtocol, PyContext, PyFuncArgs, PyObject, PyObjectKind, PyObjectRef,
18+
AttributeProtocol, IdProtocol, PyContext, PyFuncArgs, PyObject, PyObjectPayload, PyObjectRef,
1919
PyResult, Scope, TypeProtocol,
2020
};
2121
use super::stdlib::io::io_open;
@@ -240,7 +240,7 @@ fn builtin_eval(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
240240
parent: None,
241241
};
242242
let scope = PyObject {
243-
kind: PyObjectKind::Scope { scope: scope_inner },
243+
payload: PyObjectPayload::Scope { scope: scope_inner },
244244
typ: None,
245245
}
246246
.into_ref();
@@ -288,7 +288,7 @@ fn builtin_exec(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
288288
parent: None,
289289
};
290290
let scope = PyObject {
291-
kind: PyObjectKind::Scope { scope: scope_inner },
291+
payload: PyObjectPayload::Scope { scope: scope_inner },
292292
typ: None,
293293
}
294294
.into_ref();

vm/src/compile.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//! https://github.com/micropython/micropython/blob/master/py/compile.c
88
99
use super::bytecode::{self, CallType, CodeObject, Instruction};
10-
use super::pyobject::{PyObject, PyObjectKind, PyResult};
10+
use super::pyobject::{PyObject, PyObjectPayload, PyResult};
1111
use super::vm::VirtualMachine;
1212
use num_complex::Complex64;
1313
use rustpython_parser::{ast, parser};
@@ -53,7 +53,7 @@ pub fn compile(
5353
let code = compiler.pop_code_object();
5454
trace!("Compilation completed: {:?}", code);
5555
Ok(PyObject::new(
56-
PyObjectKind::Code { code: code },
56+
PyObjectPayload::Code { code: code },
5757
vm.ctx.code_type(),
5858
))
5959
}

vm/src/frame.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use super::obj::objlist;
1616
use super::obj::objstr;
1717
use super::obj::objtype;
1818
use super::pyobject::{
19-
DictProtocol, IdProtocol, ParentProtocol, PyFuncArgs, PyObject, PyObjectKind, PyObjectRef,
19+
DictProtocol, IdProtocol, ParentProtocol, PyFuncArgs, PyObject, PyObjectPayload, PyObjectRef,
2020
PyResult, TypeProtocol,
2121
};
2222
use super::vm::VirtualMachine;
@@ -265,9 +265,9 @@ impl Frame {
265265

266266
let mut out: Vec<Option<i32>> = elements
267267
.into_iter()
268-
.map(|x| match x.borrow().kind {
269-
PyObjectKind::Integer { ref value } => Some(value.to_i32().unwrap()),
270-
PyObjectKind::None => None,
268+
.map(|x| match x.borrow().payload {
269+
PyObjectPayload::Integer { ref value } => Some(value.to_i32().unwrap()),
270+
PyObjectPayload::None => None,
271271
_ => panic!("Expect Int or None as BUILD_SLICE arguments, got {:?}", x),
272272
})
273273
.collect();
@@ -277,7 +277,7 @@ impl Frame {
277277
let step = if out.len() == 3 { out[2] } else { None };
278278

279279
let obj = PyObject::new(
280-
PyObjectKind::Slice { start, stop, step },
280+
PyObjectPayload::Slice { start, stop, step },
281281
vm.ctx.type_type(),
282282
);
283283
self.push_value(obj);
@@ -542,8 +542,8 @@ impl Frame {
542542
}
543543
bytecode::Instruction::PrintExpr => {
544544
let expr = self.pop_value();
545-
match expr.borrow().kind {
546-
PyObjectKind::None => (),
545+
match expr.borrow().payload {
546+
PyObjectPayload::None => (),
547547
_ => {
548548
let repr = vm.to_repr(&expr)?;
549549
builtins::builtin_print(
@@ -559,7 +559,7 @@ impl Frame {
559559
}
560560
bytecode::Instruction::LoadBuildClass => {
561561
let rustfunc = PyObject::new(
562-
PyObjectKind::RustFunction {
562+
PyObjectPayload::RustFunction {
563563
function: Box::new(builtins::builtin_build_class_),
564564
},
565565
vm.ctx.type_type(),
@@ -569,8 +569,8 @@ impl Frame {
569569
}
570570
bytecode::Instruction::StoreLocals => {
571571
let locals = self.pop_value();
572-
match self.locals.borrow_mut().kind {
573-
PyObjectKind::Scope { ref mut scope } => {
572+
match self.locals.borrow_mut().payload {
573+
PyObjectPayload::Scope { ref mut scope } => {
574574
scope.locals = locals;
575575
}
576576
_ => panic!("We really expect our scope to be a scope!"),
@@ -827,8 +827,8 @@ impl Frame {
827827
}
828828

829829
fn delete_name(&mut self, vm: &mut VirtualMachine, name: &str) -> FrameResult {
830-
let locals = match self.locals.borrow().kind {
831-
PyObjectKind::Scope { ref scope } => scope.locals.clone(),
830+
let locals = match self.locals.borrow().payload {
831+
PyObjectPayload::Scope { ref scope } => scope.locals.clone(),
832832
_ => panic!("We really expect our scope to be a scope!"),
833833
};
834834

@@ -1045,7 +1045,7 @@ impl Frame {
10451045
bytecode::Constant::Bytes { ref value } => vm.ctx.new_bytes(value.clone()),
10461046
bytecode::Constant::Boolean { ref value } => vm.new_bool(value.clone()),
10471047
bytecode::Constant::Code { ref code } => {
1048-
PyObject::new(PyObjectKind::Code { code: code.clone() }, vm.get_type())
1048+
PyObject::new(PyObjectPayload::Code { code: code.clone() }, vm.get_type())
10491049
}
10501050
bytecode::Constant::Tuple { ref elements } => vm.ctx.new_tuple(
10511051
elements
@@ -1109,9 +1109,9 @@ impl fmt::Debug for Frame {
11091109
.map(|elem| format!("\n > {:?}", elem))
11101110
.collect::<Vec<_>>()
11111111
.join("");
1112-
let local_str = match self.locals.borrow().kind {
1113-
PyObjectKind::Scope { ref scope } => match scope.locals.borrow().kind {
1114-
PyObjectKind::Dict { ref elements } => {
1112+
let local_str = match self.locals.borrow().payload {
1113+
PyObjectPayload::Scope { ref scope } => match scope.locals.borrow().payload {
1114+
PyObjectPayload::Dict { ref elements } => {
11151115
objdict::get_key_value_pairs_from_content(elements)
11161116
.iter()
11171117
.map(|elem| {

vm/src/obj/objbool.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
use super::super::pyobject::{
2-
PyContext, PyFuncArgs, PyObjectKind, PyObjectRef, PyResult, TypeProtocol,
2+
PyContext, PyFuncArgs, PyObjectPayload, PyObjectRef, PyResult, TypeProtocol,
33
};
44
use super::super::vm::VirtualMachine;
55
use super::objtype;
66
use num_traits::Zero;
77

88
pub fn boolval(vm: &mut VirtualMachine, obj: PyObjectRef) -> Result<bool, PyObjectRef> {
9-
let result = match obj.borrow().kind {
10-
PyObjectKind::Integer { ref value } => !value.is_zero(),
11-
PyObjectKind::Float { value } => value != 0.0,
12-
PyObjectKind::Sequence { ref elements } => !elements.is_empty(),
13-
PyObjectKind::Dict { ref elements } => !elements.is_empty(),
14-
PyObjectKind::String { ref value } => !value.is_empty(),
15-
PyObjectKind::None { .. } => false,
9+
let result = match obj.borrow().payload {
10+
PyObjectPayload::Integer { ref value } => !value.is_zero(),
11+
PyObjectPayload::Float { value } => value != 0.0,
12+
PyObjectPayload::Sequence { ref elements } => !elements.is_empty(),
13+
PyObjectPayload::Dict { ref elements } => !elements.is_empty(),
14+
PyObjectPayload::String { ref value } => !value.is_empty(),
15+
PyObjectPayload::None { .. } => false,
1616
_ => {
1717
if let Ok(f) = vm.get_method(obj.clone(), "__bool__") {
1818
let bool_res = vm.invoke(f, PyFuncArgs::default())?;
19-
let v = match bool_res.borrow().kind {
20-
PyObjectKind::Integer { ref value } => !value.is_zero(),
19+
let v = match bool_res.borrow().payload {
20+
PyObjectPayload::Integer { ref value } => !value.is_zero(),
2121
_ => return Err(vm.new_type_error(String::from("TypeError"))),
2222
};
2323
v
@@ -46,7 +46,7 @@ pub fn not(vm: &mut VirtualMachine, obj: &PyObjectRef) -> PyResult {
4646

4747
// Retrieve inner int value:
4848
pub fn get_value(obj: &PyObjectRef) -> bool {
49-
if let PyObjectKind::Integer { value } = &obj.borrow().kind {
49+
if let PyObjectPayload::Integer { value } = &obj.borrow().payload {
5050
!value.is_zero()
5151
} else {
5252
panic!("Inner error getting inner boolean");

vm/src/obj/objbytearray.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Implementation of the python bytearray object.
22
33
use super::super::pyobject::{
4-
PyContext, PyFuncArgs, PyObject, PyObjectKind, PyObjectRef, PyResult, TypeProtocol,
4+
PyContext, PyFuncArgs, PyObject, PyObjectPayload, PyObjectRef, PyResult, TypeProtocol,
55
};
66

77
use super::objint;
@@ -64,7 +64,7 @@ fn bytearray_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
6464
vec![]
6565
};
6666
Ok(PyObject::new(
67-
PyObjectKind::Bytes { value: value },
67+
PyObjectPayload::Bytes { value: value },
6868
cls.clone(),
6969
))
7070
}
@@ -105,7 +105,7 @@ fn bytearray_getitem(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
105105
*/
106106
/*
107107
fn set_value(obj: &PyObjectRef, value: Vec<u8>) {
108-
obj.borrow_mut().kind = PyObjectKind::Bytes { value };
108+
obj.borrow_mut().kind = PyObjectPayload::Bytes { value };
109109
}
110110
*/
111111

vm/src/obj/objbytes.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::super::pyobject::{
2-
PyContext, PyFuncArgs, PyObject, PyObjectKind, PyObjectRef, PyResult, TypeProtocol,
2+
PyContext, PyFuncArgs, PyObject, PyObjectPayload, PyObjectRef, PyResult, TypeProtocol,
33
};
44
use super::super::vm::VirtualMachine;
55
use super::objint;
@@ -48,7 +48,7 @@ fn bytes_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
4848
};
4949

5050
Ok(PyObject::new(
51-
PyObjectKind::Bytes { value: value },
51+
PyObjectPayload::Bytes { value: value },
5252
cls.clone(),
5353
))
5454
}
@@ -87,7 +87,7 @@ fn bytes_hash(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
8787

8888
pub fn get_value<'a>(obj: &'a PyObjectRef) -> impl Deref<Target = Vec<u8>> + 'a {
8989
Ref::map(obj.borrow(), |py_obj| {
90-
if let PyObjectKind::Bytes { ref value } = py_obj.kind {
90+
if let PyObjectPayload::Bytes { ref value } = py_obj.payload {
9191
value
9292
} else {
9393
panic!("Inner error getting int {:?}", obj);

vm/src/obj/objcode.rs

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

55
use super::super::bytecode;
66
use super::super::pyobject::{
7-
PyContext, PyFuncArgs, PyObjectKind, PyObjectRef, PyResult, TypeProtocol,
7+
PyContext, PyFuncArgs, PyObjectPayload, PyObjectRef, PyResult, TypeProtocol,
88
};
99
use super::super::vm::VirtualMachine;
1010
use super::objtype;
@@ -18,7 +18,7 @@ pub fn init(context: &PyContext) {
1818
/// Extract rust bytecode object from a python code object.
1919
pub fn copy_code(code_obj: &PyObjectRef) -> bytecode::CodeObject {
2020
let code_obj = code_obj.borrow();
21-
if let PyObjectKind::Code { ref code } = code_obj.kind {
21+
if let PyObjectPayload::Code { ref code } = code_obj.payload {
2222
code.clone()
2323
} else {
2424
panic!("Must be code obj");

vm/src/obj/objcomplex.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::super::pyobject::{
2-
PyContext, PyFuncArgs, PyObject, PyObjectKind, PyObjectRef, PyResult, TypeProtocol,
2+
PyContext, PyFuncArgs, PyObject, PyObjectPayload, PyObjectRef, PyResult, TypeProtocol,
33
};
44
use super::super::vm::VirtualMachine;
55
use super::objfloat;
@@ -23,7 +23,7 @@ pub fn init(context: &PyContext) {
2323
}
2424

2525
pub fn get_value(obj: &PyObjectRef) -> Complex64 {
26-
if let PyObjectKind::Complex { value } = &obj.borrow().kind {
26+
if let PyObjectPayload::Complex { value } = &obj.borrow().payload {
2727
*value
2828
} else {
2929
panic!("Inner error getting complex");
@@ -54,7 +54,10 @@ fn complex_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
5454

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

57-
Ok(PyObject::new(PyObjectKind::Complex { value }, cls.clone()))
57+
Ok(PyObject::new(
58+
PyObjectPayload::Complex { value },
59+
cls.clone(),
60+
))
5861
}
5962

6063
fn complex_add(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {

vm/src/obj/objdict.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::super::pyobject::{
2-
PyContext, PyFuncArgs, PyObject, PyObjectKind, PyObjectRef, PyResult, TypeProtocol,
2+
PyContext, PyFuncArgs, PyObject, PyObjectPayload, PyObjectRef, PyResult, TypeProtocol,
33
};
44
use super::super::vm::VirtualMachine;
55
use super::objiter;
@@ -18,7 +18,7 @@ pub type DictContentType = HashMap<String, (PyObjectRef, PyObjectRef)>;
1818

1919
pub fn new(dict_type: PyObjectRef) -> PyObjectRef {
2020
PyObject::new(
21-
PyObjectKind::Dict {
21+
PyObjectPayload::Dict {
2222
elements: HashMap::new(),
2323
},
2424
dict_type.clone(),
@@ -27,7 +27,7 @@ pub fn new(dict_type: PyObjectRef) -> PyObjectRef {
2727

2828
pub fn get_elements<'a>(obj: &'a PyObjectRef) -> impl Deref<Target = DictContentType> + 'a {
2929
Ref::map(obj.borrow(), |py_obj| {
30-
if let PyObjectKind::Dict { ref elements } = py_obj.kind {
30+
if let PyObjectPayload::Dict { ref elements } = py_obj.payload {
3131
elements
3232
} else {
3333
panic!("Cannot extract dict elements");
@@ -37,7 +37,7 @@ pub fn get_elements<'a>(obj: &'a PyObjectRef) -> impl Deref<Target = DictContent
3737

3838
fn get_mut_elements<'a>(obj: &'a PyObjectRef) -> impl DerefMut<Target = DictContentType> + 'a {
3939
RefMut::map(obj.borrow_mut(), |py_obj| {
40-
if let PyObjectKind::Dict { ref mut elements } = py_obj.kind {
40+
if let PyObjectPayload::Dict { ref mut elements } = py_obj.payload {
4141
elements
4242
} else {
4343
panic!("Cannot extract dict elements");
@@ -227,7 +227,7 @@ fn dict_iter(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
227227
let key_list = vm.ctx.new_list(keys);
228228

229229
let iter_obj = PyObject::new(
230-
PyObjectKind::Iterator {
230+
PyObjectPayload::Iterator {
231231
position: 0,
232232
iterated_obj: key_list,
233233
},
@@ -275,7 +275,7 @@ fn dict_getitem(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
275275
}
276276

277277
pub fn create_type(type_type: PyObjectRef, object_type: PyObjectRef, dict_type: PyObjectRef) {
278-
(*dict_type.borrow_mut()).kind = PyObjectKind::Class {
278+
(*dict_type.borrow_mut()).payload = PyObjectPayload::Class {
279279
name: String::from("dict"),
280280
dict: new(dict_type.clone()),
281281
mro: vec![object_type],

vm/src/obj/objfloat.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::super::pyobject::{
2-
PyContext, PyFuncArgs, PyObjectKind, PyObjectRef, PyResult, TypeProtocol,
2+
PyContext, PyFuncArgs, PyObjectPayload, PyObjectRef, PyResult, TypeProtocol,
33
};
44
use super::super::vm::VirtualMachine;
55
use super::objint;
@@ -32,7 +32,7 @@ fn float_init(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
3232

3333
// Retrieve inner float value:
3434
pub fn get_value(obj: &PyObjectRef) -> f64 {
35-
if let PyObjectKind::Float { value } = &obj.borrow().kind {
35+
if let PyObjectPayload::Float { value } = &obj.borrow().payload {
3636
*value
3737
} else {
3838
panic!("Inner error getting float");
@@ -57,7 +57,7 @@ pub fn make_float(vm: &mut VirtualMachine, obj: &PyObjectRef) -> Result<f64, PyO
5757
}
5858

5959
fn set_value(obj: &PyObjectRef, value: f64) {
60-
obj.borrow_mut().kind = PyObjectKind::Float { value };
60+
obj.borrow_mut().payload = PyObjectPayload::Float { value };
6161
}
6262

6363
fn float_eq(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {

vm/src/obj/objframe.rs

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

55
use super::super::frame::Frame;
66
use super::super::pyobject::{
7-
PyContext, PyFuncArgs, PyObjectKind, PyObjectRef, PyResult, TypeProtocol,
7+
PyContext, PyFuncArgs, PyObjectPayload, PyObjectRef, PyResult, TypeProtocol,
88
};
99
use super::super::vm::VirtualMachine;
1010
use super::objtype;
@@ -34,7 +34,7 @@ fn frame_flocals(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
3434
let py_scope = frame.locals.clone();
3535
let py_scope = py_scope.borrow();
3636

37-
if let PyObjectKind::Scope { scope } = &py_scope.kind {
37+
if let PyObjectPayload::Scope { scope } = &py_scope.payload {
3838
Ok(scope.locals.clone())
3939
} else {
4040
panic!("The scope isn't a scope!");
@@ -47,7 +47,7 @@ fn frame_fcode(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
4747
}
4848

4949
pub fn get_value(obj: &PyObjectRef) -> Frame {
50-
if let PyObjectKind::Frame { frame } = &obj.borrow().kind {
50+
if let PyObjectPayload::Frame { frame } = &obj.borrow().payload {
5151
frame.clone()
5252
} else {
5353
panic!("Inner error getting int {:?}", obj);

0 commit comments

Comments
 (0)