mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Modify original vm._pow usage
Signed-off-by: snowapril <sinjihng@gmail.com>
This commit is contained in:
@@ -1654,7 +1654,7 @@ impl ExecutingFrame<'_> {
|
||||
bytecode::BinaryOperator::Add => vm._add(a_ref, b_ref),
|
||||
bytecode::BinaryOperator::Multiply => vm._mul(a_ref, b_ref),
|
||||
bytecode::BinaryOperator::MatrixMultiply => vm._matmul(a_ref, b_ref),
|
||||
bytecode::BinaryOperator::Power => vm._pow(a_ref, b_ref),
|
||||
bytecode::BinaryOperator::Power => vm._pow(a_ref, b_ref, &vm.ctx.none()),
|
||||
bytecode::BinaryOperator::Divide => vm._truediv(a_ref, b_ref),
|
||||
bytecode::BinaryOperator::FloorDivide => vm._floordiv(a_ref, b_ref),
|
||||
bytecode::BinaryOperator::Modulo => vm._mod(a_ref, b_ref),
|
||||
|
||||
@@ -623,37 +623,8 @@ mod builtins {
|
||||
modulus,
|
||||
} = args;
|
||||
match modulus {
|
||||
None => vm.binary_op(&x, &y, PyNumberBinaryOp::Power, "pow"),
|
||||
Some(z) => {
|
||||
let try_pow_value = |obj: &PyObject,
|
||||
args: (PyObjectRef, PyObjectRef, PyObjectRef)|
|
||||
-> Option<PyResult> {
|
||||
let method = obj.get_class_attr(identifier!(vm, __pow__))?;
|
||||
let result = match method.call(args, vm) {
|
||||
Ok(x) => x,
|
||||
Err(e) => return Some(Err(e)),
|
||||
};
|
||||
Some(Ok(PyArithmeticValue::from_object(vm, result).into_option()?))
|
||||
};
|
||||
|
||||
if let Some(val) = try_pow_value(&x, (x.clone(), y.clone(), z.clone())) {
|
||||
return val;
|
||||
}
|
||||
|
||||
if !x.class().is(y.class()) {
|
||||
if let Some(val) = try_pow_value(&y, (x.clone(), y.clone(), z.clone())) {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
if !x.class().is(z.class()) && !y.class().is(z.class()) {
|
||||
if let Some(val) = try_pow_value(&z, (x.clone(), y.clone(), z.clone())) {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
Err(vm.new_unsupported_ternop_error(&x, &y, &z, "pow"))
|
||||
}
|
||||
None => vm._pow(&x, &y, &vm.ctx.none()),
|
||||
Some(z) => vm._pow(&x, &y, &z),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -133,7 +133,7 @@ mod _operator {
|
||||
|
||||
#[pyfunction]
|
||||
fn pow(a: PyObjectRef, b: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
vm._pow(&a, &b)
|
||||
vm._pow(&a, &b, &vm.ctx.none())
|
||||
}
|
||||
|
||||
#[pyfunction]
|
||||
@@ -292,7 +292,7 @@ mod _operator {
|
||||
|
||||
#[pyfunction]
|
||||
fn ipow(a: PyObjectRef, b: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
vm._ipow(&a, &b)
|
||||
vm._ipow(&a, &b, &vm.ctx.none())
|
||||
}
|
||||
|
||||
#[pyfunction]
|
||||
|
||||
Reference in New Issue
Block a user