You can get Haxe sources from Github repository. Once Git is installed type the following:
git clone https://github.com/HaxeFoundation/haxe/
In this website you can find a script which automates the downloading and compiling of Haxe. We'll talk about it in the last part of this document, Development Environment. To get more information check the following pages:
Once the repository is downloaded you'll realize that there are a lot of files. Don't panic, you only have to understand a few of these.
common.ml contains some important definitions, including all platforms that the compiler supports. Therefore this is our first task: open it and in include the definition of the new platform at the end of platform enum:
type platform = | Cross | Flash | Js .... | MyPlatform
main.ml is the main entry point of the compiler executable.
In order to add information about the new target in main.ml follow this general rule: look for platform definitions (such as "js","flash" or "php") along the document and try to extrapolate that platform specific code to your new target. You'll actually just have to add a few lines.
args_spec stores compilation arguments. If you are writing a new myplatform target you must provide at least a new -mytarget argument that will look like this:
("-mytarget",Arg.String (set_platform MyPlatform "myplatform"),"<file> : compile code to myplatform")
After capturing arguments compilation begins. The compiler creates the Abstract Syntax Tree (AST) and passes that information to the "destination" code generator, which is responsible of creating the platform specific code:
Every platform has its code generator, named "genmyplatform.ml", and almost 99% of the work of adding support for a new target is done in this file.
Genmyplatform.generate with one argument,
com (with type
Common.context), which contains the AST (
types property) and some other compilation information. You must use this information to generate the platform specific code.
Use already existing generators as a guide to write a new generator.
genjs.ml are probably the easiest to understand, but it depends on the nature of your target. If you are targeting script languages like python those are good references, but to write bytecode or assembly
genswf9.ml will fit better with your proposal.
In order to understand how AST is stored you must understand the
type.ml file. This is covered by the next part of this document.