Skip to content

Commit b06c0f8

Browse files
committed
Modify original vm._pow usage
Signed-off-by: snowapril <sinjihng@gmail.com>
1 parent 05900fb commit b06c0f8

File tree

3 files changed

+5
-34
lines changed

3 files changed

+5
-34
lines changed

vm/src/frame.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1654,7 +1654,7 @@ impl ExecutingFrame<'_> {
16541654
bytecode::BinaryOperator::Add => vm._add(a_ref, b_ref),
16551655
bytecode::BinaryOperator::Multiply => vm._mul(a_ref, b_ref),
16561656
bytecode::BinaryOperator::MatrixMultiply => vm._matmul(a_ref, b_ref),
1657-
bytecode::BinaryOperator::Power => vm._pow(a_ref, b_ref),
1657+
bytecode::BinaryOperator::Power => vm._pow(a_ref, b_ref, &vm.ctx.none()),
16581658
bytecode::BinaryOperator::Divide => vm._truediv(a_ref, b_ref),
16591659
bytecode::BinaryOperator::FloorDivide => vm._floordiv(a_ref, b_ref),
16601660
bytecode::BinaryOperator::Modulo => vm._mod(a_ref, b_ref),

vm/src/stdlib/builtins.rs

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -623,37 +623,8 @@ mod builtins {
623623
modulus,
624624
} = args;
625625
match modulus {
626-
None => vm.binary_op(&x, &y, PyNumberBinaryOp::Power, "pow"),
627-
Some(z) => {
628-
let try_pow_value = |obj: &PyObject,
629-
args: (PyObjectRef, PyObjectRef, PyObjectRef)|
630-
-> Option<PyResult> {
631-
let method = obj.get_class_attr(identifier!(vm, __pow__))?;
632-
let result = match method.call(args, vm) {
633-
Ok(x) => x,
634-
Err(e) => return Some(Err(e)),
635-
};
636-
Some(Ok(PyArithmeticValue::from_object(vm, result).into_option()?))
637-
};
638-
639-
if let Some(val) = try_pow_value(&x, (x.clone(), y.clone(), z.clone())) {
640-
return val;
641-
}
642-
643-
if !x.class().is(y.class()) {
644-
if let Some(val) = try_pow_value(&y, (x.clone(), y.clone(), z.clone())) {
645-
return val;
646-
}
647-
}
648-
649-
if !x.class().is(z.class()) && !y.class().is(z.class()) {
650-
if let Some(val) = try_pow_value(&z, (x.clone(), y.clone(), z.clone())) {
651-
return val;
652-
}
653-
}
654-
655-
Err(vm.new_unsupported_ternop_error(&x, &y, &z, "pow"))
656-
}
626+
None => vm._pow(&x, &y, &vm.ctx.none()),
627+
Some(z) => vm._pow(&x, &y, &z),
657628
}
658629
}
659630

vm/src/stdlib/operator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ mod _operator {
133133

134134
#[pyfunction]
135135
fn pow(a: PyObjectRef, b: PyObjectRef, vm: &VirtualMachine) -> PyResult {
136-
vm._pow(&a, &b)
136+
vm._pow(&a, &b, &vm.ctx.none())
137137
}
138138

139139
#[pyfunction]
@@ -292,7 +292,7 @@ mod _operator {
292292

293293
#[pyfunction]
294294
fn ipow(a: PyObjectRef, b: PyObjectRef, vm: &VirtualMachine) -> PyResult {
295-
vm._ipow(&a, &b)
295+
vm._ipow(&a, &b, &vm.ctx.none())
296296
}
297297

298298
#[pyfunction]

0 commit comments

Comments
 (0)