asdlGen Reference Manual : Views : Choosing a Different Representation : Examples
Previous: Choosing a Different Representation
Next: Pickles

5.4.1. Examples

Need more examples

module Slp {

 real = (int mantissa, int exp)
...
  exp = Id(identifier id)
      | Num(int v)
      | Op(exp lexp,binop?,exp rexp)
       attributes (real? value)	
...

}

view C {

-- represent reals as a double

  Slp.exp <= {
   natural_type : my_real
   wrapper      : real2my_real
   unwrapper    : my_real2real
  }
  
  module Slp <= {
  interface_epilogue : typedef double my_real_ty
  
  implementation_prologue
%%
  my_real_ty real2my_real(Slp_real_ty x) {
    /* hairy code to actually do this */
  }

  Slp_real_ty my_real2real(my_real_ty x) {
    /* hairy code to actually do this */
  }
%% 
  } 
}

view SML {
   -- unpickle exp trees as a mutable type
    Slp.exp <= {
       natural_type_con : ref
       wrapper          : !
       unwrapper        : ref
    }

}


asdlGen Reference Manual : Views : Choosing a Different Representation : Examples
Previous: Choosing a Different Representation
Next: Pickles