I thought I'd sent this to the list but I put the wrong address and I've only just realised!
Basile STARYNKEVITCH wrote:
Does PolyML provide facilities to generate (machine) code at runtime (on Linux/AMD64 or Linux/x86), either in a type safe way (in the spirit of MetaML or MetaOcaml) or in a more low level unsafe way (e.g. like LLVM, Libjit, GNU lightning, ....)
No, the best solution is certainly to generate ML code and then run that through the compiler.
It might be possible to interact with the compiler at a different level if an interface were provided to do that and there are really two levels where that might be possible. The compiler first parses the source into an abstract syntax tree and then runs over that to do type-checking. After that it generates a second "code tree" from the parse tree. The code tree goes through the optimiser which generates a new, optimised version and feeds this into the machine-dependent code-generator. You can see the results of the various phases by turning on the parsetree, codetree, codetreeAfterOpt and assemblyCode flags in PolyML.Compiler.
There's little advantage in generating the abstract syntax tree (parse tree) compared with feeding in ML source directly. Generating the code tree is a possible route in and might be a way to make use of the back-end of the compiler if you had a programming language with a different type system from ML's. Since there's no checking of code tree for type-safety or validity you would be very much on your own. Actually, that was the way the original Poly/ML compiler was developed. Originally, Poly was a compiler for the Poly language written in Poly and the ML part was a separate front end that took Standard ML and generated the code tree. Only much later was the whole thing translated into ML and the Poly compiler removed.
David.