Skip to content

Commit 561eb8e

Browse files
committed
Use call_or_unsupported for operators.
1 parent 328f81a commit 561eb8e

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ __pycache__
55
**/*.pytest_cache
66
.*sw*
77
.repl_history.txt
8+
.vscode
89
wasm-pack.log

vm/src/vm.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -549,27 +549,27 @@ impl VirtualMachine {
549549
}
550550

551551
pub fn _add(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
552-
self.call_method(&a, "__add__", vec![b])
552+
self.call_or_unsupported(a, b, "__add__", "__radd__", "+")
553553
}
554554

555555
pub fn _mul(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
556-
self.call_method(&a, "__mul__", vec![b])
556+
self.call_or_unsupported(a, b, "__mul__", "__rmul__", "*")
557557
}
558558

559559
pub fn _div(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
560-
self.call_method(&a, "__truediv__", vec![b])
560+
self.call_or_unsupported(a, b, "__truediv__", "__truediv__", "/")
561561
}
562562

563563
pub fn _pow(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
564-
self.call_method(&a, "__pow__", vec![b])
564+
self.call_or_unsupported(a, b, "__pow__", "__rpow__", "**")
565565
}
566566

567567
pub fn _modulo(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
568-
self.call_method(&a, "__mod__", vec![b])
568+
self.call_or_unsupported(a, b, "__mod__", "__rmod__", "%")
569569
}
570570

571571
pub fn _xor(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
572-
self.call_method(&a, "__xor__", vec![b])
572+
self.call_or_unsupported(a, b, "__xor__", "__rxor__", "^")
573573
}
574574

575575
pub fn _or(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {

0 commit comments

Comments
 (0)