I know that Haxe compiler is written in OCaml programming language, which is a quite good choice for compiler developer. However recently I found Luaxe project, that seems to be a full-featured Lua backend for Haxe and was developed as pure Haxe library. I looked at the code of the project and it is using some kind of macro magic to generate Lua source code at compile time. So I would like to ask is it possible to implement a full-featured backend in pure Haxe without digging into OCaml and rebuilding the compiler? If so is there any limitations? Is there any good article on how to implement a backend in pure Haxe?
It looks like the Luaxe project is using the setCustomJSGenerator API.
Basically, this runs as a macro, using --macro "setCustomJSGenerator(luaxe.LuaGenerator.use)"
or something similar.
I've never built a custom backend myself, but you can use it either to do custom Javascript, or, to generate source code for a different language, which is done in each of these:
You can look at each of these to get an idea of how the APIs work, they all have a fairly similar structure by the looks of things.
In terms of limitations, you would have to ask someone who has used this. I know the Python generator ended up being moved into the standard Haxe compiler, so is presumably in OCaml now - perhaps they found it too limiting? I'm not sure.
If you would like to know more about specific limitations of this approach, I would either ask on the Haxe mailing list, or contact the developers of the targets above and ask for them to share their wisdom.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With