Skip to content

Commit 9822749

Browse files
committed
PyNumberBinaryOpSlot -> PyNumberBinaryOp
it is not a slot
1 parent d9fc95c commit 9822749

File tree

6 files changed

+31
-45
lines changed

6 files changed

+31
-45
lines changed

vm/src/protocol/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ pub use callable::PyCallable;
1111
pub use iter::{PyIter, PyIterIter, PyIterReturn};
1212
pub use mapping::{PyMapping, PyMappingMethods};
1313
pub use number::{
14-
PyNumber, PyNumberBinaryFunc, PyNumberBinaryOpSlot, PyNumberMethods, PyNumberUnaryFunc,
14+
PyNumber, PyNumberBinaryFunc, PyNumberBinaryOp, PyNumberMethods, PyNumberUnaryFunc,
1515
};
1616
pub use sequence::{PySequence, PySequenceMethods};

vm/src/protocol/number.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ impl PyNumberMethods {
196196

197197
pub fn get_binary_op(
198198
&self,
199-
op_slot: &PyNumberBinaryOpSlot,
199+
op_slot: PyNumberBinaryOp,
200200
) -> PyResult<&Option<PyNumberBinaryFunc>> {
201-
use PyNumberBinaryOpSlot::*;
201+
use PyNumberBinaryOp::*;
202202
let binary_op = match op_slot {
203203
Add => &self.add,
204204
Subtract => &self.subtract,
@@ -233,7 +233,7 @@ impl PyNumberMethods {
233233
}
234234

235235
#[derive(Copy, Clone)]
236-
pub enum PyNumberBinaryOpSlot {
236+
pub enum PyNumberBinaryOp {
237237
Add,
238238
Subtract,
239239
Multiply,
@@ -291,7 +291,7 @@ impl PyNumber<'_> {
291291

292292
pub fn get_binary_op(
293293
&self,
294-
op_slot: &PyNumberBinaryOpSlot,
294+
op_slot: PyNumberBinaryOp,
295295
) -> PyResult<&Option<PyNumberBinaryFunc>> {
296296
self.methods().get_binary_op(op_slot)
297297
}

vm/src/protocol/sequence.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{
22
builtins::{type_::PointerSlot, PyList, PyListRef, PySlice, PyTuple, PyTupleRef},
33
convert::ToPyObject,
44
function::PyArithmeticValue,
5-
protocol::{PyMapping, PyNumberBinaryOpSlot},
5+
protocol::{PyMapping, PyNumberBinaryOp},
66
AsObject, PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine,
77
};
88
use crossbeam_utils::atomic::AtomicCell;
@@ -118,7 +118,7 @@ impl PySequence<'_> {
118118

119119
// if both arguments apear to be sequences, try fallback to __add__
120120
if self.check() && other.to_sequence(vm).check() {
121-
let ret = vm.binary_op1(self.obj, other, &PyNumberBinaryOpSlot::Add)?;
121+
let ret = vm.binary_op1(self.obj, other, PyNumberBinaryOp::Add)?;
122122
if let PyArithmeticValue::Implemented(ret) = PyArithmeticValue::from_object(vm, ret) {
123123
return Ok(ret);
124124
}
@@ -137,11 +137,7 @@ impl PySequence<'_> {
137137

138138
// fallback to __mul__
139139
if self.check() {
140-
let ret = vm.binary_op1(
141-
self.obj,
142-
&n.to_pyobject(vm),
143-
&PyNumberBinaryOpSlot::Multiply,
144-
)?;
140+
let ret = vm.binary_op1(self.obj, &n.to_pyobject(vm), PyNumberBinaryOp::Multiply)?;
145141
if let PyArithmeticValue::Implemented(ret) = PyArithmeticValue::from_object(vm, ret) {
146142
return Ok(ret);
147143
}

vm/src/stdlib/builtins.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ mod builtins {
2121
ArgBytesLike, ArgCallable, ArgIntoBool, ArgIterable, ArgMapping, ArgStrOrBytesLike,
2222
Either, FuncArgs, KwArgs, OptionalArg, OptionalOption, PosArgs, PyArithmeticValue,
2323
},
24-
protocol::{PyIter, PyIterReturn, PyNumberBinaryOpSlot},
24+
protocol::{PyIter, PyIterReturn, PyNumberBinaryOp},
2525
py_io,
2626
readline::{Readline, ReadlineResult},
2727
stdlib::sys,
@@ -605,7 +605,7 @@ mod builtins {
605605
modulus,
606606
} = args;
607607
match modulus {
608-
None => vm.binary_op(&x, &y, &PyNumberBinaryOpSlot::Power, "pow"),
608+
None => vm.binary_op(&x, &y, PyNumberBinaryOp::Power, "pow"),
609609
Some(z) => {
610610
let try_pow_value = |obj: &PyObject,
611611
args: (PyObjectRef, PyObjectRef, PyObjectRef)|

vm/src/types/slot.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
identifier,
88
protocol::{
99
PyBuffer, PyIterReturn, PyMapping, PyMappingMethods, PyNumber, PyNumberBinaryFunc,
10-
PyNumberBinaryOpSlot, PyNumberMethods, PyNumberUnaryFunc, PySequence, PySequenceMethods,
10+
PyNumberBinaryOp, PyNumberMethods, PyNumberUnaryFunc, PySequence, PySequenceMethods,
1111
},
1212
vm::Context,
1313
AsObject, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
@@ -163,9 +163,9 @@ pub struct PyNumberSlots {
163163
impl PyNumberSlots {
164164
pub fn get_left_binary_op(
165165
&self,
166-
op_slot: &PyNumberBinaryOpSlot,
166+
op_slot: PyNumberBinaryOp,
167167
) -> PyResult<Option<PyNumberBinaryFunc>> {
168-
use PyNumberBinaryOpSlot::*;
168+
use PyNumberBinaryOp::*;
169169
let binary_op = match op_slot {
170170
Add => self.add.load(),
171171
Subtract => self.subtract.load(),
@@ -200,9 +200,9 @@ impl PyNumberSlots {
200200

201201
pub fn get_right_binary_op(
202202
&self,
203-
op_slot: &PyNumberBinaryOpSlot,
203+
op_slot: PyNumberBinaryOp,
204204
) -> PyResult<Option<PyNumberBinaryFunc>> {
205-
use PyNumberBinaryOpSlot::*;
205+
use PyNumberBinaryOp::*;
206206
let binary_op = match op_slot {
207207
Add => self.right_add.load(),
208208
Subtract => self.right_subtract.load(),
@@ -1281,7 +1281,7 @@ macro_rules! extend_number_slot {
12811281
if $methods.$method.is_some() {
12821282
$slots.number.$method.store($methods.$method);
12831283
$slots.number.$right_method.store(Some(|num, other, vm| {
1284-
num.get_binary_op(&PyNumberBinaryOpSlot::$op_slot)?.unwrap()(
1284+
num.get_binary_op(PyNumberBinaryOp::$op_slot)?.unwrap()(
12851285
other.to_number(),
12861286
num.obj,
12871287
vm,

vm/src/vm/vm_ops.rs

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ use super::{PyMethod, VirtualMachine};
22
use crate::{
33
builtins::{PyInt, PyIntRef, PyStr, PyStrRef},
44
object::{AsObject, PyObject, PyObjectRef, PyResult},
5-
protocol::{PyIterReturn, PyNumberBinaryOpSlot, PySequence},
5+
protocol::{PyIterReturn, PyNumberBinaryOp, PySequence},
66
types::PyComparisonOp,
77
};
88
use num_traits::ToPrimitive;
99

1010
macro_rules! binary_func {
1111
($fn:ident, $op_slot:ident, $op:expr) => {
1212
pub fn $fn(&self, a: &PyObject, b: &PyObject) -> PyResult {
13-
self.binary_op(a, b, &PyNumberBinaryOpSlot::$op_slot, $op)
13+
self.binary_op(a, b, PyNumberBinaryOp::$op_slot, $op)
1414
}
1515
};
1616
}
@@ -21,8 +21,8 @@ macro_rules! inplace_binary_func {
2121
self.binary_iop(
2222
a,
2323
b,
24-
&PyNumberBinaryOpSlot::$iop_slot,
25-
&PyNumberBinaryOpSlot::$op_slot,
24+
PyNumberBinaryOp::$iop_slot,
25+
PyNumberBinaryOp::$op_slot,
2626
$op,
2727
)
2828
}
@@ -131,12 +131,7 @@ impl VirtualMachine {
131131
/// b.rop(b,a)[*], a.op(a,b), b.rop(b,a)
132132
///
133133
/// [*] only when Py_TYPE(a) != Py_TYPE(b) && Py_TYPE(b) is a subclass of Py_TYPE(a)
134-
pub fn binary_op1(
135-
&self,
136-
a: &PyObject,
137-
b: &PyObject,
138-
op_slot: &PyNumberBinaryOpSlot,
139-
) -> PyResult {
134+
pub fn binary_op1(&self, a: &PyObject, b: &PyObject, op_slot: PyNumberBinaryOp) -> PyResult {
140135
let slot_a = a.class().slots.number.get_left_binary_op(op_slot)?;
141136
let mut slot_b = if b.class().is(a.class()) {
142137
None
@@ -181,7 +176,7 @@ impl VirtualMachine {
181176
&self,
182177
a: &PyObject,
183178
b: &PyObject,
184-
op_slot: &PyNumberBinaryOpSlot,
179+
op_slot: PyNumberBinaryOp,
185180
op: &str,
186181
) -> PyResult {
187182
let result = self.binary_op1(a, b, op_slot)?;
@@ -208,8 +203,8 @@ impl VirtualMachine {
208203
&self,
209204
a: &PyObject,
210205
b: &PyObject,
211-
iop_slot: &PyNumberBinaryOpSlot,
212-
op_slot: &PyNumberBinaryOpSlot,
206+
iop_slot: PyNumberBinaryOp,
207+
op_slot: PyNumberBinaryOp,
213208
) -> PyResult {
214209
if let Some(slot) = a.class().slots.number.get_left_binary_op(iop_slot)? {
215210
let x = slot(a.to_number(), b, self)?;
@@ -224,8 +219,8 @@ impl VirtualMachine {
224219
&self,
225220
a: &PyObject,
226221
b: &PyObject,
227-
iop_slot: &PyNumberBinaryOpSlot,
228-
op_slot: &PyNumberBinaryOpSlot,
222+
iop_slot: PyNumberBinaryOp,
223+
op_slot: PyNumberBinaryOp,
229224
op: &str,
230225
) -> PyResult {
231226
let result = self.binary_iop1(a, b, iop_slot, op_slot)?;
@@ -261,7 +256,7 @@ impl VirtualMachine {
261256
inplace_binary_func!(_imatmul, InplaceMatrixMultiply, MatrixMultiply, "@=");
262257

263258
pub fn _add(&self, a: &PyObject, b: &PyObject) -> PyResult {
264-
let result = self.binary_op1(a, b, &PyNumberBinaryOpSlot::Add)?;
259+
let result = self.binary_op1(a, b, PyNumberBinaryOp::Add)?;
265260
if !result.is(&self.ctx.not_implemented) {
266261
return Ok(result);
267262
}
@@ -275,12 +270,7 @@ impl VirtualMachine {
275270
}
276271

277272
pub fn _iadd(&self, a: &PyObject, b: &PyObject) -> PyResult {
278-
let result = self.binary_iop1(
279-
a,
280-
b,
281-
&PyNumberBinaryOpSlot::InplaceAdd,
282-
&PyNumberBinaryOpSlot::Add,
283-
)?;
273+
let result = self.binary_iop1(a, b, PyNumberBinaryOp::InplaceAdd, PyNumberBinaryOp::Add)?;
284274
if !result.is(&self.ctx.not_implemented) {
285275
return Ok(result);
286276
}
@@ -294,7 +284,7 @@ impl VirtualMachine {
294284
}
295285

296286
pub fn _mul(&self, a: &PyObject, b: &PyObject) -> PyResult {
297-
let result = self.binary_op1(a, b, &PyNumberBinaryOpSlot::Multiply)?;
287+
let result = self.binary_op1(a, b, PyNumberBinaryOp::Multiply)?;
298288
if !result.is(&self.ctx.not_implemented) {
299289
return Ok(result);
300290
}
@@ -318,8 +308,8 @@ impl VirtualMachine {
318308
let result = self.binary_iop1(
319309
a,
320310
b,
321-
&PyNumberBinaryOpSlot::InplaceMultiply,
322-
&PyNumberBinaryOpSlot::Multiply,
311+
PyNumberBinaryOp::InplaceMultiply,
312+
PyNumberBinaryOp::Multiply,
323313
)?;
324314
if !result.is(&self.ctx.not_implemented) {
325315
return Ok(result);

0 commit comments

Comments
 (0)