Hello everyone,
I have just created an ML compiler to experiment with some ideas. The compiler is missing native compilation and a proper REPL, so I'm thinking of reusing the existing backend and runtime system of PolyML to build a complete compiler system. I believe the design of PolyML is modular enough for new frontends to be attached to the existing backend, but I have no idea where to start. Could someone point me in the right direction please?
Shuhan HE
On 25/09/2025 09:49, bloop36@protonmail.com wrote:
I have just created an ML compiler to experiment with some ideas. The compiler is missing native compilation and a proper REPL, so I'm thinking of reusing the existing backend and runtime system of PolyML to build a complete compiler system. I believe the design of PolyML is modular enough for new frontends to be attached to the existing backend, but I have no idea where to start. Could someone point me in the right direction please?
You should be able to use the PolyML.CodeTree structure to produce code and compile and run it. This structure is a slightly cut-down version of what the Poly/ML front-end uses. You need to be very careful when using it since there is no checking and it is very easy to crash the system either immediately or at a subsequent garbage collection.
As an example this is Hello World: open PolyML.CodeTree;
val printFn = PolyML.NameSpace.Values.code(valOf( #lookupVal PolyML.globalNameSpace "print"));
val hello = mkConstant(RunCall.unsafeCast "Hello World\n");
val code = genCode(mkCall(printFn, [hello]), 0); code();
David