mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
PyNumberBinaryOpSlot -> PyNumberBinaryOp
it is not a slot
This commit is contained in:
@@ -11,6 +11,6 @@ pub use callable::PyCallable;
|
||||
pub use iter::{PyIter, PyIterIter, PyIterReturn};
|
||||
pub use mapping::{PyMapping, PyMappingMethods};
|
||||
pub use number::{
|
||||
PyNumber, PyNumberBinaryFunc, PyNumberBinaryOpSlot, PyNumberMethods, PyNumberUnaryFunc,
|
||||
PyNumber, PyNumberBinaryFunc, PyNumberBinaryOp, PyNumberMethods, PyNumberUnaryFunc,
|
||||
};
|
||||
pub use sequence::{PySequence, PySequenceMethods};
|
||||
|
||||
@@ -196,9 +196,9 @@ impl PyNumberMethods {
|
||||
|
||||
pub fn get_binary_op(
|
||||
&self,
|
||||
op_slot: &PyNumberBinaryOpSlot,
|
||||
op_slot: PyNumberBinaryOp,
|
||||
) -> PyResult<&Option<PyNumberBinaryFunc>> {
|
||||
use PyNumberBinaryOpSlot::*;
|
||||
use PyNumberBinaryOp::*;
|
||||
let binary_op = match op_slot {
|
||||
Add => &self.add,
|
||||
Subtract => &self.subtract,
|
||||
@@ -233,7 +233,7 @@ impl PyNumberMethods {
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub enum PyNumberBinaryOpSlot {
|
||||
pub enum PyNumberBinaryOp {
|
||||
Add,
|
||||
Subtract,
|
||||
Multiply,
|
||||
@@ -291,7 +291,7 @@ impl PyNumber<'_> {
|
||||
|
||||
pub fn get_binary_op(
|
||||
&self,
|
||||
op_slot: &PyNumberBinaryOpSlot,
|
||||
op_slot: PyNumberBinaryOp,
|
||||
) -> PyResult<&Option<PyNumberBinaryFunc>> {
|
||||
self.methods().get_binary_op(op_slot)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::{
|
||||
builtins::{type_::PointerSlot, PyList, PyListRef, PySlice, PyTuple, PyTupleRef},
|
||||
convert::ToPyObject,
|
||||
function::PyArithmeticValue,
|
||||
protocol::{PyMapping, PyNumberBinaryOpSlot},
|
||||
protocol::{PyMapping, PyNumberBinaryOp},
|
||||
AsObject, PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine,
|
||||
};
|
||||
use crossbeam_utils::atomic::AtomicCell;
|
||||
@@ -118,7 +118,7 @@ impl PySequence<'_> {
|
||||
|
||||
// if both arguments apear to be sequences, try fallback to __add__
|
||||
if self.check() && other.to_sequence(vm).check() {
|
||||
let ret = vm.binary_op1(self.obj, other, &PyNumberBinaryOpSlot::Add)?;
|
||||
let ret = vm.binary_op1(self.obj, other, PyNumberBinaryOp::Add)?;
|
||||
if let PyArithmeticValue::Implemented(ret) = PyArithmeticValue::from_object(vm, ret) {
|
||||
return Ok(ret);
|
||||
}
|
||||
@@ -137,11 +137,7 @@ impl PySequence<'_> {
|
||||
|
||||
// fallback to __mul__
|
||||
if self.check() {
|
||||
let ret = vm.binary_op1(
|
||||
self.obj,
|
||||
&n.to_pyobject(vm),
|
||||
&PyNumberBinaryOpSlot::Multiply,
|
||||
)?;
|
||||
let ret = vm.binary_op1(self.obj, &n.to_pyobject(vm), PyNumberBinaryOp::Multiply)?;
|
||||
if let PyArithmeticValue::Implemented(ret) = PyArithmeticValue::from_object(vm, ret) {
|
||||
return Ok(ret);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ mod builtins {
|
||||
ArgBytesLike, ArgCallable, ArgIntoBool, ArgIterable, ArgMapping, ArgStrOrBytesLike,
|
||||
Either, FuncArgs, KwArgs, OptionalArg, OptionalOption, PosArgs, PyArithmeticValue,
|
||||
},
|
||||
protocol::{PyIter, PyIterReturn, PyNumberBinaryOpSlot},
|
||||
protocol::{PyIter, PyIterReturn, PyNumberBinaryOp},
|
||||
py_io,
|
||||
readline::{Readline, ReadlineResult},
|
||||
stdlib::sys,
|
||||
@@ -605,7 +605,7 @@ mod builtins {
|
||||
modulus,
|
||||
} = args;
|
||||
match modulus {
|
||||
None => vm.binary_op(&x, &y, &PyNumberBinaryOpSlot::Power, "pow"),
|
||||
None => vm.binary_op(&x, &y, PyNumberBinaryOp::Power, "pow"),
|
||||
Some(z) => {
|
||||
let try_pow_value = |obj: &PyObject,
|
||||
args: (PyObjectRef, PyObjectRef, PyObjectRef)|
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::{
|
||||
identifier,
|
||||
protocol::{
|
||||
PyBuffer, PyIterReturn, PyMapping, PyMappingMethods, PyNumber, PyNumberBinaryFunc,
|
||||
PyNumberBinaryOpSlot, PyNumberMethods, PyNumberUnaryFunc, PySequence, PySequenceMethods,
|
||||
PyNumberBinaryOp, PyNumberMethods, PyNumberUnaryFunc, PySequence, PySequenceMethods,
|
||||
},
|
||||
vm::Context,
|
||||
AsObject, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
@@ -163,9 +163,9 @@ pub struct PyNumberSlots {
|
||||
impl PyNumberSlots {
|
||||
pub fn get_left_binary_op(
|
||||
&self,
|
||||
op_slot: &PyNumberBinaryOpSlot,
|
||||
op_slot: PyNumberBinaryOp,
|
||||
) -> PyResult<Option<PyNumberBinaryFunc>> {
|
||||
use PyNumberBinaryOpSlot::*;
|
||||
use PyNumberBinaryOp::*;
|
||||
let binary_op = match op_slot {
|
||||
Add => self.add.load(),
|
||||
Subtract => self.subtract.load(),
|
||||
@@ -200,9 +200,9 @@ impl PyNumberSlots {
|
||||
|
||||
pub fn get_right_binary_op(
|
||||
&self,
|
||||
op_slot: &PyNumberBinaryOpSlot,
|
||||
op_slot: PyNumberBinaryOp,
|
||||
) -> PyResult<Option<PyNumberBinaryFunc>> {
|
||||
use PyNumberBinaryOpSlot::*;
|
||||
use PyNumberBinaryOp::*;
|
||||
let binary_op = match op_slot {
|
||||
Add => self.right_add.load(),
|
||||
Subtract => self.right_subtract.load(),
|
||||
@@ -1281,7 +1281,7 @@ macro_rules! extend_number_slot {
|
||||
if $methods.$method.is_some() {
|
||||
$slots.number.$method.store($methods.$method);
|
||||
$slots.number.$right_method.store(Some(|num, other, vm| {
|
||||
num.get_binary_op(&PyNumberBinaryOpSlot::$op_slot)?.unwrap()(
|
||||
num.get_binary_op(PyNumberBinaryOp::$op_slot)?.unwrap()(
|
||||
other.to_number(),
|
||||
num.obj,
|
||||
vm,
|
||||
|
||||
@@ -2,7 +2,7 @@ use super::{PyMethod, VirtualMachine};
|
||||
use crate::{
|
||||
builtins::{PyInt, PyIntRef, PyStr, PyStrRef},
|
||||
object::{AsObject, PyObject, PyObjectRef, PyResult},
|
||||
protocol::{PyIterReturn, PyNumberBinaryOpSlot, PySequence},
|
||||
protocol::{PyIterReturn, PyNumberBinaryOp, PySequence},
|
||||
types::PyComparisonOp,
|
||||
};
|
||||
use num_traits::ToPrimitive;
|
||||
@@ -10,7 +10,7 @@ use num_traits::ToPrimitive;
|
||||
macro_rules! binary_func {
|
||||
($fn:ident, $op_slot:ident, $op:expr) => {
|
||||
pub fn $fn(&self, a: &PyObject, b: &PyObject) -> PyResult {
|
||||
self.binary_op(a, b, &PyNumberBinaryOpSlot::$op_slot, $op)
|
||||
self.binary_op(a, b, PyNumberBinaryOp::$op_slot, $op)
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -21,8 +21,8 @@ macro_rules! inplace_binary_func {
|
||||
self.binary_iop(
|
||||
a,
|
||||
b,
|
||||
&PyNumberBinaryOpSlot::$iop_slot,
|
||||
&PyNumberBinaryOpSlot::$op_slot,
|
||||
PyNumberBinaryOp::$iop_slot,
|
||||
PyNumberBinaryOp::$op_slot,
|
||||
$op,
|
||||
)
|
||||
}
|
||||
@@ -131,12 +131,7 @@ impl VirtualMachine {
|
||||
/// b.rop(b,a)[*], a.op(a,b), b.rop(b,a)
|
||||
///
|
||||
/// [*] only when Py_TYPE(a) != Py_TYPE(b) && Py_TYPE(b) is a subclass of Py_TYPE(a)
|
||||
pub fn binary_op1(
|
||||
&self,
|
||||
a: &PyObject,
|
||||
b: &PyObject,
|
||||
op_slot: &PyNumberBinaryOpSlot,
|
||||
) -> PyResult {
|
||||
pub fn binary_op1(&self, a: &PyObject, b: &PyObject, op_slot: PyNumberBinaryOp) -> PyResult {
|
||||
let slot_a = a.class().slots.number.get_left_binary_op(op_slot)?;
|
||||
let mut slot_b = if b.class().is(a.class()) {
|
||||
None
|
||||
@@ -181,7 +176,7 @@ impl VirtualMachine {
|
||||
&self,
|
||||
a: &PyObject,
|
||||
b: &PyObject,
|
||||
op_slot: &PyNumberBinaryOpSlot,
|
||||
op_slot: PyNumberBinaryOp,
|
||||
op: &str,
|
||||
) -> PyResult {
|
||||
let result = self.binary_op1(a, b, op_slot)?;
|
||||
@@ -208,8 +203,8 @@ impl VirtualMachine {
|
||||
&self,
|
||||
a: &PyObject,
|
||||
b: &PyObject,
|
||||
iop_slot: &PyNumberBinaryOpSlot,
|
||||
op_slot: &PyNumberBinaryOpSlot,
|
||||
iop_slot: PyNumberBinaryOp,
|
||||
op_slot: PyNumberBinaryOp,
|
||||
) -> PyResult {
|
||||
if let Some(slot) = a.class().slots.number.get_left_binary_op(iop_slot)? {
|
||||
let x = slot(a.to_number(), b, self)?;
|
||||
@@ -224,8 +219,8 @@ impl VirtualMachine {
|
||||
&self,
|
||||
a: &PyObject,
|
||||
b: &PyObject,
|
||||
iop_slot: &PyNumberBinaryOpSlot,
|
||||
op_slot: &PyNumberBinaryOpSlot,
|
||||
iop_slot: PyNumberBinaryOp,
|
||||
op_slot: PyNumberBinaryOp,
|
||||
op: &str,
|
||||
) -> PyResult {
|
||||
let result = self.binary_iop1(a, b, iop_slot, op_slot)?;
|
||||
@@ -261,7 +256,7 @@ impl VirtualMachine {
|
||||
inplace_binary_func!(_imatmul, InplaceMatrixMultiply, MatrixMultiply, "@=");
|
||||
|
||||
pub fn _add(&self, a: &PyObject, b: &PyObject) -> PyResult {
|
||||
let result = self.binary_op1(a, b, &PyNumberBinaryOpSlot::Add)?;
|
||||
let result = self.binary_op1(a, b, PyNumberBinaryOp::Add)?;
|
||||
if !result.is(&self.ctx.not_implemented) {
|
||||
return Ok(result);
|
||||
}
|
||||
@@ -275,12 +270,7 @@ impl VirtualMachine {
|
||||
}
|
||||
|
||||
pub fn _iadd(&self, a: &PyObject, b: &PyObject) -> PyResult {
|
||||
let result = self.binary_iop1(
|
||||
a,
|
||||
b,
|
||||
&PyNumberBinaryOpSlot::InplaceAdd,
|
||||
&PyNumberBinaryOpSlot::Add,
|
||||
)?;
|
||||
let result = self.binary_iop1(a, b, PyNumberBinaryOp::InplaceAdd, PyNumberBinaryOp::Add)?;
|
||||
if !result.is(&self.ctx.not_implemented) {
|
||||
return Ok(result);
|
||||
}
|
||||
@@ -294,7 +284,7 @@ impl VirtualMachine {
|
||||
}
|
||||
|
||||
pub fn _mul(&self, a: &PyObject, b: &PyObject) -> PyResult {
|
||||
let result = self.binary_op1(a, b, &PyNumberBinaryOpSlot::Multiply)?;
|
||||
let result = self.binary_op1(a, b, PyNumberBinaryOp::Multiply)?;
|
||||
if !result.is(&self.ctx.not_implemented) {
|
||||
return Ok(result);
|
||||
}
|
||||
@@ -318,8 +308,8 @@ impl VirtualMachine {
|
||||
let result = self.binary_iop1(
|
||||
a,
|
||||
b,
|
||||
&PyNumberBinaryOpSlot::InplaceMultiply,
|
||||
&PyNumberBinaryOpSlot::Multiply,
|
||||
PyNumberBinaryOp::InplaceMultiply,
|
||||
PyNumberBinaryOp::Multiply,
|
||||
)?;
|
||||
if !result.is(&self.ctx.not_implemented) {
|
||||
return Ok(result);
|
||||
|
||||
Reference in New Issue
Block a user