@@ -8,13 +8,18 @@ use error::HANDLE_ERROR;
8
8
use self :: libc:: { c_int} ;
9
9
use data:: { constant, tile} ;
10
10
use self :: num:: Complex ;
11
+ use index:: { Indexer , assign_gen} ;
12
+ use seq:: Seq ;
13
+ use std:: mem;
11
14
12
15
type MutAfArray = * mut self :: libc:: c_longlong ;
13
16
type MutDouble = * mut self :: libc:: c_double ;
14
17
type MutUint = * mut self :: libc:: c_uint ;
15
18
type AfArray = self :: libc:: c_longlong ;
16
19
17
20
use 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 } ;
18
23
19
24
#[ allow( dead_code) ]
20
25
extern {
@@ -311,10 +316,10 @@ arith_scalar_spec!(u8);
311
316
312
317
macro_rules! arith_func {
313
318
( $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 {
315
320
type Output = Array ;
316
321
317
- fn $fn_name( self , rhs: & ' f Array ) -> Array {
322
+ fn $fn_name( self , rhs: Array ) -> Array {
318
323
unsafe {
319
324
let mut temp: i64 = 0 ;
320
325
let err_val = $ffi_fn( & mut temp as MutAfArray ,
@@ -336,4 +341,49 @@ arith_func!(BitAnd, bitand, af_bitand);
336
341
arith_func ! ( BitOr , bitor, af_bitor) ;
337
342
arith_func ! ( BitXor , bitxor, af_bitxor) ;
338
343
arith_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