@@ -316,7 +316,9 @@ impl Frame {
316
316
vm. call_method ( & dict_obj, "__setitem__" , vec ! [ key, value] ) ?;
317
317
Ok ( None )
318
318
}
319
- bytecode:: Instruction :: BinaryOperation { ref op } => self . execute_binop ( vm, op) ,
319
+ bytecode:: Instruction :: BinaryOperation { ref op, inplace } => {
320
+ self . execute_binop ( vm, op, * inplace)
321
+ }
320
322
bytecode:: Instruction :: LoadAttr { ref name } => self . load_attr ( vm, name) ,
321
323
bytecode:: Instruction :: StoreAttr { ref name } => self . store_attr ( vm, name) ,
322
324
bytecode:: Instruction :: DeleteAttr { ref name } => self . delete_attr ( vm, name) ,
@@ -893,27 +895,39 @@ impl Frame {
893
895
& mut self ,
894
896
vm : & mut VirtualMachine ,
895
897
op : & bytecode:: BinaryOperator ,
898
+ inplace : bool ,
896
899
) -> FrameResult {
897
900
let b_ref = self . pop_value ( ) ;
898
901
let a_ref = self . pop_value ( ) ;
899
902
let value = match * op {
903
+ bytecode:: BinaryOperator :: Subtract if inplace => vm. _isub ( a_ref, b_ref) ,
900
904
bytecode:: BinaryOperator :: Subtract => vm. _sub ( a_ref, b_ref) ,
905
+ bytecode:: BinaryOperator :: Add if inplace => vm. _iadd ( a_ref, b_ref) ,
901
906
bytecode:: BinaryOperator :: Add => vm. _add ( a_ref, b_ref) ,
907
+ bytecode:: BinaryOperator :: Multiply if inplace => vm. _imul ( a_ref, b_ref) ,
902
908
bytecode:: BinaryOperator :: Multiply => vm. _mul ( a_ref, b_ref) ,
903
- bytecode:: BinaryOperator :: MatrixMultiply => {
904
- vm. call_method ( & a_ref, "__matmul__" , vec ! [ b_ref] )
905
- }
909
+ bytecode:: BinaryOperator :: MatrixMultiply if inplace => vm . _imatmul ( a_ref , b_ref ) ,
910
+ bytecode :: BinaryOperator :: MatrixMultiply => vm. _matmul ( a_ref, b_ref) ,
911
+ bytecode :: BinaryOperator :: Power if inplace => vm . _ipow ( a_ref , b_ref ) ,
906
912
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
- }
913
+ bytecode:: BinaryOperator :: Divide if inplace => vm. _itruediv ( a_ref, b_ref) ,
914
+ bytecode:: BinaryOperator :: Divide => vm. _truediv ( a_ref, b_ref) ,
915
+ bytecode:: BinaryOperator :: FloorDivide if inplace => vm. _ifloordiv ( a_ref, b_ref) ,
916
+ bytecode:: BinaryOperator :: FloorDivide => vm. _floordiv ( a_ref, b_ref) ,
917
+ // TODO: Subscript should probably have its own op
918
+ bytecode:: BinaryOperator :: Subscript if inplace => unreachable ! ( ) ,
911
919
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] ) ,
920
+ bytecode:: BinaryOperator :: Modulo if inplace => vm. _imod ( a_ref, b_ref) ,
921
+ bytecode:: BinaryOperator :: Modulo => vm. _mod ( a_ref, b_ref) ,
922
+ bytecode:: BinaryOperator :: Lshift if inplace => vm. _ilshift ( a_ref, b_ref) ,
923
+ bytecode:: BinaryOperator :: Lshift => vm. _lshift ( a_ref, b_ref) ,
924
+ bytecode:: BinaryOperator :: Rshift if inplace => vm. _irshift ( a_ref, b_ref) ,
925
+ bytecode:: BinaryOperator :: Rshift => vm. _rshift ( a_ref, b_ref) ,
926
+ bytecode:: BinaryOperator :: Xor if inplace => vm. _ixor ( a_ref, b_ref) ,
915
927
bytecode:: BinaryOperator :: Xor => vm. _xor ( a_ref, b_ref) ,
928
+ bytecode:: BinaryOperator :: Or if inplace => vm. _ior ( a_ref, b_ref) ,
916
929
bytecode:: BinaryOperator :: Or => vm. _or ( a_ref, b_ref) ,
930
+ bytecode:: BinaryOperator :: And if inplace => vm. _iand ( a_ref, b_ref) ,
917
931
bytecode:: BinaryOperator :: And => vm. _and ( a_ref, b_ref) ,
918
932
} ?;
919
933
0 commit comments