Skip to content

Commit 7a4d653

Browse files
Merge pull request RustPython#679 from RustPython/joey/vm-not-pycontext
Make it possible to implement PyValue in stdlib
2 parents bbe2704 + 976afed commit 7a4d653

34 files changed

+123
-115
lines changed

vm/src/frame.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ pub struct Frame {
184184
}
185185

186186
impl PyValue for Frame {
187-
fn required_type(ctx: &PyContext) -> PyObjectRef {
188-
ctx.frame_type()
187+
fn class(vm: &mut VirtualMachine) -> PyObjectRef {
188+
vm.ctx.frame_type()
189189
}
190190
}
191191

vm/src/obj/objbool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use super::objtuple::PyTuple;
1212
use super::objtype;
1313

1414
impl IntoPyObject for bool {
15-
fn into_pyobject(self, ctx: &PyContext) -> PyResult {
16-
Ok(ctx.new_bool(self))
15+
fn into_pyobject(self, vm: &mut VirtualMachine) -> PyResult {
16+
Ok(vm.ctx.new_bool(self))
1717
}
1818
}
1919

vm/src/obj/objbuiltinfunc.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
use std::fmt;
22

3-
use crate::pyobject::{PyContext, PyNativeFunc, PyObjectRef, PyValue};
3+
use crate::pyobject::{PyNativeFunc, PyObjectRef, PyValue};
4+
use crate::vm::VirtualMachine;
45

56
pub struct PyBuiltinFunction {
67
// TODO: shouldn't be public
78
pub value: PyNativeFunc,
89
}
910

1011
impl PyValue for PyBuiltinFunction {
11-
fn required_type(ctx: &PyContext) -> PyObjectRef {
12-
ctx.builtin_function_or_method_type()
12+
fn class(vm: &mut VirtualMachine) -> PyObjectRef {
13+
vm.ctx.builtin_function_or_method_type()
1314
}
1415
}
1516

vm/src/obj/objbytearray.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ impl PyByteArray {
2929
}
3030

3131
impl PyValue for PyByteArray {
32-
fn required_type(ctx: &PyContext) -> PyObjectRef {
33-
ctx.bytearray_type()
32+
fn class(vm: &mut VirtualMachine) -> PyObjectRef {
33+
vm.ctx.bytearray_type()
3434
}
3535
}
3636

vm/src/obj/objbytes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ impl Deref for PyBytes {
3030
}
3131

3232
impl PyValue for PyBytes {
33-
fn required_type(ctx: &PyContext) -> PyObjectRef {
34-
ctx.bytes_type()
33+
fn class(vm: &mut VirtualMachine) -> PyObjectRef {
34+
vm.ctx.bytes_type()
3535
}
3636
}
3737

vm/src/obj/objcode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ impl fmt::Debug for PyCode {
2626
}
2727

2828
impl PyValue for PyCode {
29-
fn required_type(ctx: &PyContext) -> PyObjectRef {
30-
ctx.code_type()
29+
fn class(vm: &mut VirtualMachine) -> PyObjectRef {
30+
vm.ctx.code_type()
3131
}
3232
}
3333

vm/src/obj/objcomplex.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ pub struct PyComplex {
1414
}
1515

1616
impl PyValue for PyComplex {
17-
fn required_type(ctx: &PyContext) -> PyObjectRef {
18-
ctx.complex_type()
17+
fn class(vm: &mut VirtualMachine) -> PyObjectRef {
18+
vm.ctx.complex_type()
1919
}
2020
}
2121

vm/src/obj/objdict.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ impl fmt::Debug for PyDict {
3030
}
3131

3232
impl PyValue for PyDict {
33-
fn required_type(ctx: &PyContext) -> PyObjectRef {
34-
ctx.dict_type()
33+
fn class(vm: &mut VirtualMachine) -> PyObjectRef {
34+
vm.ctx.dict_type()
3535
}
3636
}
3737

vm/src/obj/objenumerate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ pub struct PyEnumerate {
1717
}
1818

1919
impl PyValue for PyEnumerate {
20-
fn required_type(ctx: &PyContext) -> PyObjectRef {
21-
ctx.enumerate_type()
20+
fn class(vm: &mut VirtualMachine) -> PyObjectRef {
21+
vm.ctx.enumerate_type()
2222
}
2323
}
2424

vm/src/obj/objfilter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ pub struct PyFilter {
1313
}
1414

1515
impl PyValue for PyFilter {
16-
fn required_type(ctx: &PyContext) -> PyObjectRef {
17-
ctx.filter_type()
16+
fn class(vm: &mut VirtualMachine) -> PyObjectRef {
17+
vm.ctx.filter_type()
1818
}
1919
}
2020

vm/src/obj/objfloat.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ pub struct PyFloat {
1616
}
1717

1818
impl PyValue for PyFloat {
19-
fn required_type(ctx: &PyContext) -> PyObjectRef {
20-
ctx.float_type()
19+
fn class(vm: &mut VirtualMachine) -> PyObjectRef {
20+
vm.ctx.float_type()
2121
}
2222
}
2323

2424
impl IntoPyObject for f64 {
25-
fn into_pyobject(self, ctx: &PyContext) -> PyResult {
26-
Ok(ctx.new_float(self))
25+
fn into_pyobject(self, vm: &mut VirtualMachine) -> PyResult {
26+
Ok(vm.ctx.new_float(self))
2727
}
2828
}
2929

vm/src/obj/objfunction.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ impl PyFunction {
2323
}
2424

2525
impl PyValue for PyFunction {
26-
fn required_type(ctx: &PyContext) -> PyObjectRef {
27-
ctx.function_type()
26+
fn class(vm: &mut VirtualMachine) -> PyObjectRef {
27+
vm.ctx.function_type()
2828
}
2929
}
3030

@@ -42,8 +42,8 @@ impl PyMethod {
4242
}
4343

4444
impl PyValue for PyMethod {
45-
fn required_type(ctx: &PyContext) -> PyObjectRef {
46-
ctx.bound_method_type()
45+
fn class(vm: &mut VirtualMachine) -> PyObjectRef {
46+
vm.ctx.bound_method_type()
4747
}
4848
}
4949

vm/src/obj/objgenerator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ pub struct PyGenerator {
1414
}
1515

1616
impl PyValue for PyGenerator {
17-
fn required_type(ctx: &PyContext) -> PyObjectRef {
18-
ctx.generator_type()
17+
fn class(vm: &mut VirtualMachine) -> PyObjectRef {
18+
vm.ctx.generator_type()
1919
}
2020
}
2121

vm/src/obj/objint.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,22 @@ impl PyInt {
3030
}
3131

3232
impl IntoPyObject for BigInt {
33-
fn into_pyobject(self, ctx: &PyContext) -> PyResult {
34-
Ok(ctx.new_int(self))
33+
fn into_pyobject(self, vm: &mut VirtualMachine) -> PyResult {
34+
Ok(vm.ctx.new_int(self))
3535
}
3636
}
3737

3838
impl PyValue for PyInt {
39-
fn required_type(ctx: &PyContext) -> PyObjectRef {
40-
ctx.int_type()
39+
fn class(vm: &mut VirtualMachine) -> PyObjectRef {
40+
vm.ctx.int_type()
4141
}
4242
}
4343

4444
macro_rules! impl_into_pyobject_int {
4545
($($t:ty)*) => {$(
4646
impl IntoPyObject for $t {
47-
fn into_pyobject(self, ctx: &PyContext) -> PyResult {
48-
Ok(ctx.new_int(self))
47+
fn into_pyobject(self, vm: &mut VirtualMachine) -> PyResult {
48+
Ok(vm.ctx.new_int(self))
4949
}
5050
}
5151
)*};

vm/src/obj/objlist.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ impl From<Vec<PyObjectRef>> for PyList {
3838
}
3939

4040
impl PyValue for PyList {
41-
fn required_type(ctx: &PyContext) -> PyObjectRef {
42-
ctx.list_type()
41+
fn class(vm: &mut VirtualMachine) -> PyObjectRef {
42+
vm.ctx.list_type()
4343
}
4444
}
4545

vm/src/obj/objmap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ pub struct PyMap {
1212
}
1313

1414
impl PyValue for PyMap {
15-
fn required_type(ctx: &PyContext) -> PyObjectRef {
16-
ctx.map_type()
15+
fn class(vm: &mut VirtualMachine) -> PyObjectRef {
16+
vm.ctx.map_type()
1717
}
1818
}
1919

vm/src/obj/objmemory.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ pub struct PyMemoryView {
99
}
1010

1111
impl PyValue for PyMemoryView {
12-
fn required_type(ctx: &PyContext) -> PyObjectRef {
13-
ctx.memoryview_type()
12+
fn class(vm: &mut VirtualMachine) -> PyObjectRef {
13+
vm.ctx.memoryview_type()
1414
}
1515
}
1616

vm/src/obj/objmodule.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ pub struct PyModule {
99
pub type PyModuleRef = PyRef<PyModule>;
1010

1111
impl PyValue for PyModule {
12-
fn required_type(ctx: &PyContext) -> PyObjectRef {
13-
ctx.module_type()
12+
fn class(vm: &mut VirtualMachine) -> PyObjectRef {
13+
vm.ctx.module_type()
1414
}
1515
}
1616

vm/src/obj/objnone.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@ pub struct PyNone;
88
pub type PyNoneRef = PyRef<PyNone>;
99

1010
impl PyValue for PyNone {
11-
fn required_type(ctx: &PyContext) -> PyObjectRef {
12-
ctx.none().typ()
11+
fn class(vm: &mut VirtualMachine) -> PyObjectRef {
12+
vm.ctx.none().typ()
1313
}
1414
}
1515

1616
// This allows a built-in function to not return a value, mapping to
1717
// Python's behavior of returning `None` in this situation.
1818
impl IntoPyObject for () {
19-
fn into_pyobject(self, ctx: &PyContext) -> PyResult {
20-
Ok(ctx.none())
19+
fn into_pyobject(self, vm: &mut VirtualMachine) -> PyResult {
20+
Ok(vm.ctx.none())
2121
}
2222
}
2323

2424
impl<T: IntoPyObject> IntoPyObject for Option<T> {
25-
fn into_pyobject(self, ctx: &PyContext) -> PyResult {
25+
fn into_pyobject(self, vm: &mut VirtualMachine) -> PyResult {
2626
match self {
27-
Some(x) => x.into_pyobject(ctx),
28-
None => Ok(ctx.none()),
27+
Some(x) => x.into_pyobject(vm),
28+
None => Ok(vm.ctx.none()),
2929
}
3030
}
3131
}

vm/src/obj/objobject.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use crate::vm::VirtualMachine;
1212
pub struct PyInstance;
1313

1414
impl PyValue for PyInstance {
15-
fn required_type(ctx: &PyContext) -> PyObjectRef {
16-
ctx.object()
15+
fn class(vm: &mut VirtualMachine) -> PyObjectRef {
16+
vm.ctx.object()
1717
}
1818
}
1919

vm/src/obj/objproperty.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ pub struct PyReadOnlyProperty {
1616
}
1717

1818
impl PyValue for PyReadOnlyProperty {
19-
fn required_type(ctx: &PyContext) -> PyObjectRef {
20-
ctx.readonly_property_type()
19+
fn class(vm: &mut VirtualMachine) -> PyObjectRef {
20+
vm.ctx.readonly_property_type()
2121
}
2222
}
2323

@@ -38,8 +38,8 @@ pub struct PyProperty {
3838
}
3939

4040
impl PyValue for PyProperty {
41-
fn required_type(ctx: &PyContext) -> PyObjectRef {
42-
ctx.property_type()
41+
fn class(vm: &mut VirtualMachine) -> PyObjectRef {
42+
vm.ctx.property_type()
4343
}
4444
}
4545

vm/src/obj/objrange.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ pub struct PyRange {
2424
}
2525

2626
impl PyValue for PyRange {
27-
fn required_type(ctx: &PyContext) -> PyObjectRef {
28-
ctx.range_type()
27+
fn class(vm: &mut VirtualMachine) -> PyObjectRef {
28+
vm.ctx.range_type()
2929
}
3030
}
3131

vm/src/obj/objset.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ impl fmt::Debug for PySet {
3030
}
3131

3232
impl PyValue for PySet {
33-
fn required_type(ctx: &PyContext) -> PyObjectRef {
34-
ctx.set_type()
33+
fn class(vm: &mut VirtualMachine) -> PyObjectRef {
34+
vm.ctx.set_type()
3535
}
3636
}
3737

vm/src/obj/objslice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ pub struct PySlice {
1414
}
1515

1616
impl PyValue for PySlice {
17-
fn required_type(ctx: &PyContext) -> PyObjectRef {
18-
ctx.slice_type()
17+
fn class(vm: &mut VirtualMachine) -> PyObjectRef {
18+
vm.ctx.slice_type()
1919
}
2020
}
2121

vm/src/obj/objstr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -597,14 +597,14 @@ impl PyStringRef {
597597
}
598598

599599
impl PyValue for PyString {
600-
fn required_type(ctx: &PyContext) -> PyObjectRef {
601-
ctx.str_type()
600+
fn class(vm: &mut VirtualMachine) -> PyObjectRef {
601+
vm.ctx.str_type()
602602
}
603603
}
604604

605605
impl IntoPyObject for String {
606-
fn into_pyobject(self, ctx: &PyContext) -> PyResult {
607-
Ok(ctx.new_str(self))
606+
fn into_pyobject(self, vm: &mut VirtualMachine) -> PyResult {
607+
Ok(vm.ctx.new_str(self))
608608
}
609609
}
610610

vm/src/obj/objtuple.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ impl From<Vec<PyObjectRef>> for PyTuple {
3939
}
4040

4141
impl PyValue for PyTuple {
42-
fn required_type(ctx: &PyContext) -> PyObjectRef {
43-
ctx.tuple_type()
42+
fn class(vm: &mut VirtualMachine) -> PyObjectRef {
43+
vm.ctx.tuple_type()
4444
}
4545
}
4646

vm/src/obj/objtype.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ pub struct PyClass {
2222
pub type PyClassRef = PyRef<PyClass>;
2323

2424
impl PyValue for PyClass {
25-
fn required_type(ctx: &PyContext) -> PyObjectRef {
26-
ctx.type_type()
25+
fn class(vm: &mut VirtualMachine) -> PyObjectRef {
26+
vm.ctx.type_type()
2727
}
2828
}
2929

vm/src/obj/objweakref.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ impl PyWeak {
2323
}
2424

2525
impl PyValue for PyWeak {
26-
fn required_type(ctx: &PyContext) -> PyObjectRef {
27-
ctx.weakref_type()
26+
fn class(vm: &mut VirtualMachine) -> PyObjectRef {
27+
vm.ctx.weakref_type()
2828
}
2929
}
3030

0 commit comments

Comments
 (0)