Skip to content

Commit fe3f45f

Browse files
Implement remaining binop reverse fallbacks
1 parent 1af9cc0 commit fe3f45f

2 files changed

Lines changed: 32 additions & 12 deletions

File tree

vm/src/frame.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -900,18 +900,14 @@ impl Frame {
900900
bytecode::BinaryOperator::Subtract => vm._sub(a_ref, b_ref),
901901
bytecode::BinaryOperator::Add => vm._add(a_ref, b_ref),
902902
bytecode::BinaryOperator::Multiply => vm._mul(a_ref, b_ref),
903-
bytecode::BinaryOperator::MatrixMultiply => {
904-
vm.call_method(&a_ref, "__matmul__", vec![b_ref])
905-
}
903+
bytecode::BinaryOperator::MatrixMultiply => vm._matmul(a_ref, b_ref),
906904
bytecode::BinaryOperator::Power => vm._pow(a_ref, b_ref),
907-
bytecode::BinaryOperator::Divide => vm._div(a_ref, b_ref),
908-
bytecode::BinaryOperator::FloorDivide => {
909-
vm.call_method(&a_ref, "__floordiv__", vec![b_ref])
910-
}
905+
bytecode::BinaryOperator::Divide => vm._truediv(a_ref, b_ref),
906+
bytecode::BinaryOperator::FloorDivide => vm._floordiv(a_ref, b_ref),
911907
bytecode::BinaryOperator::Subscript => self.subscript(vm, a_ref, b_ref),
912-
bytecode::BinaryOperator::Modulo => vm._modulo(a_ref, b_ref),
913-
bytecode::BinaryOperator::Lshift => vm.call_method(&a_ref, "__lshift__", vec![b_ref]),
914-
bytecode::BinaryOperator::Rshift => vm.call_method(&a_ref, "__rshift__", vec![b_ref]),
908+
bytecode::BinaryOperator::Modulo => vm._mod(a_ref, b_ref),
909+
bytecode::BinaryOperator::Lshift => vm._lshift(a_ref, b_ref),
910+
bytecode::BinaryOperator::Rshift => vm._rshift(a_ref, b_ref),
915911
bytecode::BinaryOperator::Xor => vm._xor(a_ref, b_ref),
916912
bytecode::BinaryOperator::Or => vm._or(a_ref, b_ref),
917913
bytecode::BinaryOperator::And => vm._and(a_ref, b_ref),

vm/src/vm.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,24 +571,48 @@ impl VirtualMachine {
571571
})
572572
}
573573

574-
pub fn _div(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
574+
pub fn _matmul(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
575+
self.call_or_unsupported(a, b, "__matmul__", "__rmatmul__", |vm, a, b| {
576+
Err(vm.new_unsupported_operand_error(a, b, "@"))
577+
})
578+
}
579+
580+
pub fn _truediv(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
575581
self.call_or_unsupported(a, b, "__truediv__", "__rtruediv__", |vm, a, b| {
576582
Err(vm.new_unsupported_operand_error(a, b, "/"))
577583
})
578584
}
579585

586+
pub fn _floordiv(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
587+
self.call_or_unsupported(a, b, "__floordiv__", "__rfloordiv__", |vm, a, b| {
588+
Err(vm.new_unsupported_operand_error(a, b, "//"))
589+
})
590+
}
591+
580592
pub fn _pow(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
581593
self.call_or_unsupported(a, b, "__pow__", "__rpow__", |vm, a, b| {
582594
Err(vm.new_unsupported_operand_error(a, b, "**"))
583595
})
584596
}
585597

586-
pub fn _modulo(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
598+
pub fn _mod(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
587599
self.call_or_unsupported(a, b, "__mod__", "__rmod__", |vm, a, b| {
588600
Err(vm.new_unsupported_operand_error(a, b, "%"))
589601
})
590602
}
591603

604+
pub fn _lshift(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
605+
self.call_or_unsupported(a, b, "__lshift__", "__rlshift__", |vm, a, b| {
606+
Err(vm.new_unsupported_operand_error(a, b, "<<"))
607+
})
608+
}
609+
610+
pub fn _rshift(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
611+
self.call_or_unsupported(a, b, "__rshift__", "__rrshift__", |vm, a, b| {
612+
Err(vm.new_unsupported_operand_error(a, b, ">>"))
613+
})
614+
}
615+
592616
pub fn _xor(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
593617
self.call_or_unsupported(a, b, "__xor__", "__rxor__", |vm, a, b| {
594618
Err(vm.new_unsupported_operand_error(a, b, "^"))

0 commit comments

Comments
 (0)