Sun Sep 28 12:11:36 CEST 2008

modifying MetaOcaml

Maybe the best way to understand a bit more about the internals of
MetaOcaml is to dive right in and make some modifications.  I.e. I'd
like to replace the "double" type with "float" which is more useful
for embedded development.

There are two occurences of the literal '"double"' in bytecomp/trx.ml
What happens if these are changed?  Nothing..

It looks like postprocessing the code is going to be simpler.  For
generating float code this dirty hack should work:

           #define double float

Now.. The clean way.  In cprint.ml there is a function called
"print_type_spec" which does support the Tfloat type.  Maybe changing
Tdouble by Tfloat should work then?

Test with:

# (.!{Trx.run_gcc}.<fun x -> x +. 1.0>.) 123. ;;
- : float = 124.

That seems to work.  The generated procedure has correct type
declarations, and the marshalling uses implicit float<->double
conversions based on the types of "Double_val" and "Store_Double_val".

float procedure(float x_1 )
  return x_1 + 1.0;

value procedure_marshall(value arg_list )
    float ret ;

    float x_1 = Double_val(arg_list);
    value store = alloc(Double_wosize, Abstract_tag) ;

    ret = procedure(x_1);
    Store_double_val(store, ret);
    return (store);

EDIT: some interesting extensions:
  - double vs. float
  - short ints
  - vectors