Use call_or_unsupported for operators.

This commit is contained in:
Yu Wu
2019-02-02 21:45:24 -08:00
parent 328f81a28e
commit 561eb8ed4f
2 changed files with 7 additions and 6 deletions

1
.gitignore vendored
View File

@@ -5,4 +5,5 @@ __pycache__
**/*.pytest_cache
.*sw*
.repl_history.txt
.vscode
wasm-pack.log

View File

@@ -549,27 +549,27 @@ impl VirtualMachine {
}
pub fn _add(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
self.call_method(&a, "__add__", vec![b])
self.call_or_unsupported(a, b, "__add__", "__radd__", "+")
}
pub fn _mul(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
self.call_method(&a, "__mul__", vec![b])
self.call_or_unsupported(a, b, "__mul__", "__rmul__", "*")
}
pub fn _div(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
self.call_method(&a, "__truediv__", vec![b])
self.call_or_unsupported(a, b, "__truediv__", "__truediv__", "/")
}
pub fn _pow(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
self.call_method(&a, "__pow__", vec![b])
self.call_or_unsupported(a, b, "__pow__", "__rpow__", "**")
}
pub fn _modulo(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
self.call_method(&a, "__mod__", vec![b])
self.call_or_unsupported(a, b, "__mod__", "__rmod__", "%")
}
pub fn _xor(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
self.call_method(&a, "__xor__", vec![b])
self.call_or_unsupported(a, b, "__xor__", "__rxor__", "^")
}
pub fn _or(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {