Reputation: 1017
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?
Upvotes: 4
Views: 1016
Reputation: 3845
There are several threads on the Haxelang discussion group that might give you some info on this subject. Some examples:
Why is the Haxe compiler still in OCAML?
What is missing from Haxe to replace Ocaml as a compiler language?
Hope this helps!
Upvotes: 3
Reputation: 6008
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.
Upvotes: 5