1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
macro_rules! uniop {
    ( impl $trait:ident, $method:ident for Var, $dmethod:ident for Real,
      chain Fn = $chain_fn:expr ) => {
        // {

        pub trait $trait {
            fn $method(&self) -> Self;
        }

        impl $trait for Real {
            fn $method(&self) -> Real {
                self.clone().$dmethod()
            }
        }

        impl $trait for Var {
            fn $method(&self) -> Var {
                let vi = self.get_vari_refmut();
                let mem = vi.mem();
                let operand = Operand::Vari(self.vi_.clone());
                let new_vi_ptr = mem.borrow_mut().alloc(Vari::new(
                    self.val().$dmethod(),
                    operand,
                    Operand::None,
                    Box::new($chain_fn),
                    mem.clone()
                ));
                Var::new(new_vi_ptr)
            }
        }

        pub fn $method<T: $trait>(v: &T) -> T {
            $trait::$method(v)
        }

        // }
    };

}