Is there a systematic approach to preprocess .ml containing toplevel directives so that the preprocessed .ml output file can be compiled with ocaml compilers?
Toplevel directives like #directory would require some commandline arguments to be added to the ocaml compiler, but we are willing to take the complexity.
The background is that we have a few big .ml files that contain top directives. They are supposed to be used with #use "x.ml";; in OCaml REPL, but as the ml files are getting larger, running #use is now taking a significant time (around a minute). To make loading it faster, I am looking for a method to compile x.ml into .cmo/.cmi/.cma and load it.
Does using the floating attribute generate new .ml files that can be compiled with ocamlopt or ocamlc, or am I understanding wrong?
Custom attributes are ignored by the compiler. You can put there whatever you want.
You may also want to have a look at ocamlscript (or b0caml, but it’s unreleased and again one of these projects I had that was assuming we were going towards a simplification of the notion of library and needs to be reviewed now that this did not happen).