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
40
41
42
43
44
extern crate proc_macro2;
#[macro_use]
extern crate quote;
extern crate syn;
#[macro_use]
extern crate synstructure;

decl_derive!([Trace] => derive_trace);

fn derive_trace(s: synstructure::Structure) -> quote::Tokens {
  let trace_body = s.each(|bi| quote!(mark(#bi)));

  let trace_impl = s.unsafe_bound_impl(
    quote!(eko_gc::Trace),
    quote! {
      #[inline] unsafe fn mark(&self) {
        #[allow(dead_code)]
        #[inline]
        unsafe fn mark<T: eko_gc::Trace>(it: &T) {
          eko_gc::Trace::mark(it);
        }
        match *self { #trace_body }
      }
      #[inline] unsafe fn root(&self) {
        #[allow(dead_code)]
        #[inline]
        unsafe fn mark<T: eko_gc::Trace>(it: &T) {
          eko_gc::Trace::root(it);
        }
        match *self { #trace_body }
      }
      #[inline] unsafe fn unroot(&self) {
        #[allow(dead_code)]
        #[inline]
        unsafe fn mark<T: eko_gc::Trace>(it: &T) {
          eko_gc::Trace::unroot(it);
        }
        match *self { #trace_body }
      }
    },
  );

  quote! { #trace_impl }
}