Skip to content

Commit 9f28643

Browse files
committed
Fix inplace_power in number slots
Signed-off-by: snowapril <sinjihng@gmail.com>
1 parent 9135d29 commit 9f28643

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

vm/src/types/slot.rs

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -210,21 +210,6 @@ macro_rules! number_binary_right_op_wrapper {
210210
|a, b, vm| vm.call_special_method(b, identifier!(vm, $name), (a.to_owned(),))
211211
};
212212
}
213-
macro_rules! number_ternary_op_wrapper {
214-
($name:ident) => {
215-
|a, b, c, vm| {
216-
vm.call_special_method(a, identifier!(vm, $name), (b.to_owned(), c.to_owned()))
217-
}
218-
};
219-
}
220-
macro_rules! number_ternary_right_op_wrapper {
221-
($name:ident) => {
222-
|a, b, c, vm| {
223-
vm.call_special_method(b, identifier!(vm, $name), (a.to_owned(), c.to_owned()))
224-
}
225-
};
226-
}
227-
228213
fn getitem_wrapper<K: ToPyObject>(obj: &PyObject, needle: K, vm: &VirtualMachine) -> PyResult {
229214
vm.call_special_method(obj, identifier!(vm, __getitem__), (needle,))
230215
}
@@ -581,21 +566,35 @@ impl PyType {
581566
);
582567
}
583568
_ if name == identifier!(ctx, __pow__) => {
584-
toggle_subslot!(as_number, power, number_ternary_op_wrapper!(__pow__));
569+
toggle_subslot!(as_number, power, |a, b, c, vm| {
570+
if vm.is_none(c) {
571+
vm.call_special_method(a, identifier!(vm, __pow__), (b.to_owned(),))
572+
} else {
573+
vm.call_special_method(
574+
a,
575+
identifier!(vm, __pow__),
576+
(b.to_owned(), c.to_owned()),
577+
)
578+
}
579+
});
585580
}
586581
_ if name == identifier!(ctx, __rpow__) => {
587-
toggle_subslot!(
588-
as_number,
589-
right_power,
590-
number_ternary_right_op_wrapper!(__rpow__)
591-
);
582+
toggle_subslot!(as_number, right_power, |a, b, c, vm| {
583+
if vm.is_none(c) {
584+
vm.call_special_method(b, identifier!(vm, __rpow__), (a.to_owned(),))
585+
} else {
586+
vm.call_special_method(
587+
b,
588+
identifier!(vm, __rpow__),
589+
(a.to_owned(), c.to_owned()),
590+
)
591+
}
592+
});
592593
}
593594
_ if name == identifier!(ctx, __ipow__) => {
594-
toggle_subslot!(
595-
as_number,
596-
inplace_power,
597-
number_ternary_op_wrapper!(__ipow__)
598-
);
595+
toggle_subslot!(as_number, inplace_power, |a, b, _, vm| {
596+
vm.call_special_method(a, identifier!(vm, __ipow__), (b.to_owned(),))
597+
});
599598
}
600599
_ if name == identifier!(ctx, __lshift__) => {
601600
toggle_subslot!(as_number, lshift, number_binary_op_wrapper!(__lshift__));

0 commit comments

Comments
 (0)