From f4b0195643453e398d8bca1b22311e7f60e1d559 Mon Sep 17 00:00:00 2001 From: ChJR Date: Thu, 15 Aug 2019 18:51:09 +0900 Subject: [PATCH] Add int.__rlshift__, int.__rrshift__ methods. --- vm/src/obj/objint.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/vm/src/obj/objint.rs b/vm/src/obj/objint.rs index ccdf208da..9a2a892a3 100644 --- a/vm/src/obj/objint.rs +++ b/vm/src/obj/objint.rs @@ -345,6 +345,16 @@ impl PyInt { inner_lshift(self, other, vm) } + #[pymethod(name = "__rlshift__")] + fn rlshift(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult { + if !objtype::isinstance(&other, &vm.ctx.int_type()) { + return Ok(vm.ctx.not_implemented()); + } + + let other = other.payload::().unwrap(); + inner_lshift(other, self, vm) + } + #[pymethod(name = "__rshift__")] fn rshift(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult { if !objtype::isinstance(&other, &vm.ctx.int_type()) { @@ -355,6 +365,16 @@ impl PyInt { inner_rshift(self, other, vm) } + #[pymethod(name = "__rrshift__")] + fn rrshift(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult { + if !objtype::isinstance(&other, &vm.ctx.int_type()) { + return Ok(vm.ctx.not_implemented()); + } + + let other = other.payload::().unwrap(); + inner_rshift(other, self, vm) + } + #[pymethod(name = "__xor__")] pub fn xor(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef { if objtype::isinstance(&other, &vm.ctx.int_type()) {