@@ -8,13 +8,18 @@ use error::HANDLE_ERROR;
88use self :: libc:: { c_int} ;
99use data:: { constant, tile} ;
1010use self :: num:: Complex ;
11+ use index:: { Indexer , assign_gen} ;
12+ use seq:: Seq ;
13+ use std:: mem;
1114
1215type MutAfArray = * mut self :: libc:: c_longlong ;
1316type MutDouble = * mut self :: libc:: c_double ;
1417type MutUint = * mut self :: libc:: c_uint ;
1518type AfArray = self :: libc:: c_longlong ;
1619
1720use std:: ops:: { Add , Sub , Div , Mul , BitAnd , BitOr , BitXor , Not , Rem , Shl , Shr } ;
21+ use std:: ops:: { AddAssign , SubAssign , DivAssign , MulAssign , BitAndAssign , BitOrAssign , BitXorAssign ,
22+ RemAssign , ShlAssign , ShrAssign } ;
1823
1924#[ allow( dead_code) ]
2025extern {
@@ -311,10 +316,10 @@ arith_scalar_spec!(u8);
311316
312317macro_rules! arith_func {
313318 ( $op_name: ident, $fn_name: ident, $ffi_fn: ident) => (
314- impl < ' f> $op_name<& ' f Array > for & ' f Array {
319+ impl $op_name<Array > for Array {
315320 type Output = Array ;
316321
317- fn $fn_name( self , rhs: & ' f Array ) -> Array {
322+ fn $fn_name( self , rhs: Array ) -> Array {
318323 unsafe {
319324 let mut temp: i64 = 0 ;
320325 let err_val = $ffi_fn( & mut temp as MutAfArray ,
@@ -336,4 +341,49 @@ arith_func!(BitAnd, bitand, af_bitand);
336341arith_func ! ( BitOr , bitor, af_bitor) ;
337342arith_func ! ( BitXor , bitxor, af_bitxor) ;
338343arith_func ! ( Shl , shl, af_bitshiftl) ;
339- arith_func ! ( Shr , shr, af_bitshiftr) ;
344+ arith_func ! ( Shr , shr, af_bitshiftr) ;
345+
346+ macro_rules! arith_assign_func {
347+ ( $op_name: ident, $fn_name: ident, $func: ident) => (
348+ impl $op_name<Array > for Array {
349+
350+ #[ allow( unused_variables) ]
351+ fn $fn_name( & mut self , rhs: Array ) {
352+ let mut idxrs = Indexer :: new( ) ;
353+ idxrs. set_index( & Seq :: <f32 >:: default ( ) , 0 , Some ( false ) ) ;
354+ idxrs. set_index( & Seq :: <f32 >:: default ( ) , 1 , Some ( false ) ) ;
355+ let tmp = assign_gen( self as & Array , & idxrs,
356+ & $func( self as & Array , & rhs, false ) ) ;
357+ mem:: replace( self , tmp) ;
358+ }
359+ }
360+ )
361+ }
362+
363+ arith_assign_func ! ( AddAssign , add_assign, add) ;
364+ arith_assign_func ! ( SubAssign , sub_assign, sub) ;
365+ arith_assign_func ! ( MulAssign , mul_assign, mul) ;
366+ arith_assign_func ! ( DivAssign , div_assign, div) ;
367+ arith_assign_func ! ( RemAssign , rem_assign, rem) ;
368+ arith_assign_func ! ( ShlAssign , shl_assign, shiftl) ;
369+ arith_assign_func ! ( ShrAssign , shr_assign, shiftr) ;
370+
371+ macro_rules! bit_assign_func {
372+ ( $op_name: ident, $fn_name: ident, $func: ident) => (
373+ impl $op_name<Array > for Array {
374+
375+ #[ allow( unused_variables) ]
376+ fn $fn_name( & mut self , rhs: Array ) {
377+ let mut idxrs = Indexer :: new( ) ;
378+ idxrs. set_index( & Seq :: <f32 >:: default ( ) , 0 , Some ( false ) ) ;
379+ idxrs. set_index( & Seq :: <f32 >:: default ( ) , 1 , Some ( false ) ) ;
380+ let tmp = assign_gen( self as & Array , & idxrs, & $func( self as & Array , & rhs) ) ;
381+ mem:: replace( self , tmp) ;
382+ }
383+ }
384+ )
385+ }
386+
387+ bit_assign_func ! ( BitAndAssign , bitand_assign, bitand) ;
388+ bit_assign_func ! ( BitOrAssign , bitor_assign, bitor) ;
389+ bit_assign_func ! ( BitXorAssign , bitxor_assign, bitxor) ;
0 commit comments