add __rand__ __ror__

This commit is contained in:
JunMock
2019-08-15 12:07:02 +09:00
parent 49ed782098
commit 03df88729d
2 changed files with 24 additions and 0 deletions

View File

@@ -38,6 +38,20 @@ assert int(0).__invert__() == -1
assert int(-3).__invert__() == 2
assert int(4).__invert__() == -5
assert int(0).__ror__(0) == 0
assert int(1).__ror__(0) == 1
assert int(0).__ror__(1) == 1
assert int(1).__ror__(1) == 1
assert int(3).__ror__(-3) == -1
assert int(3).__ror__(4) == 7
assert int(0).__rand__(0) == 0
assert int(1).__rand__(0) == 0
assert int(0).__rand__(1) == 0
assert int(1).__rand__(1) == 1
assert int(3).__rand__(-3) == 1
assert int(3).__rand__(4) == 0
assert int(0).__rxor__(0) == 0
assert int(1).__rxor__(0) == 1
assert int(0).__rxor__(1) == 1

View File

@@ -368,6 +368,11 @@ impl PyInt {
}
}
#[pymethod(name = "__ror__")]
fn ror(&self,other: PyObjectRef,vm: &VirtualMachine) -> PyObjectRef{
self.or(other,vm)
}
#[pymethod(name = "__and__")]
pub fn and(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
if objtype::isinstance(&other, &vm.ctx.int_type()) {
@@ -377,6 +382,11 @@ impl PyInt {
vm.ctx.not_implemented()
}
}
#[pymethod(name = "__rand__")]
fn rand(&self, other: PyObjectRef,vm: &VirtualMachine) -> PyObjectRef{
self.and(other,vm)
}
#[pymethod(name = "__pow__")]
fn pow(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult {