These are the technical skills you must achieve to create a compilation target for Haxe:
- Deep knowledge of Haxe language (of course!)
- Deep knowledge of the target platform
- Learn Ocaml
- Understand Haxe compiler sources
Assuming that the final user of this document is a superskilled Haxe developer we start directly with the second point:
So you want Haxe to create software to be executed or linked in a new platform. The first decision is to find out which language runs in that platform: If you want to target Mono/.NET, CLI is your target language. For Java, you'll use Java bytecode, PHP for PHP, etc.
When you select a platform you must ask yourself some questions:
- Is it an object oriented language?
- What about its type system? If it's dynamically typed, it will probably be an easier task. Statically typed targets are more complicated but not impossible.
- Is it an open source platform or open format? Make sure it's compatible with Haxe's license.
Haxe has been designed to simplify interactions and compatibility between platforms. It's not easy to maintain homogeneity between all different targets. Have it in mind: use Haxe's "way of doing things" and as much multiplatform libraries as you can and your project will achieve community success easily.
Ocaml is the language in which Haxe compiler is written.
Ocaml is a functional language. Functional Programming is a paradigm based on Lambda Calculus, treating computation as the evaluation of mathematical functions and avoiding state and mutable data. In fact, Ocaml is not a pure functional language but a mix of Functional and Object Oriented language.
You know nothing about ocaml and functional programming? Don't worry. Here's some good documentation to start with:
- http://www.ocaml-tutorial.org: A very nice tutorial to start with OCaml
- http://caml.inria.fr/pub/docs/manual-ocaml/index.html: Ocaml's Bible
- http://caml.inria.fr/pub/docs/manual-ocaml/libref/index.html: Ocaml standard library reference. Keep it open all time.
Ocaml syntax looks very complicated in the first view, but don't fear it. In a couple of days you'll understand a lot of tricks. Learning Ocaml will make you a better programmer.
One tip: the type of "variables" (in fact, Ocaml doesn't have true variables) and parameters are not declared but always inferred as it's in Haxe. Therefore at the beginning it's complicated to understand what parameters mean in functions like this:
let s_path ctx stat path p = ...
Fortunately Nicolas Cannasse followed a consistent programming style, using prefixes and the same letters for the same types:
let rec gen_call ctx e el = ...
Although the type of the parameters is not declared in this definition, if you're familiar with Haxe sources you'll probably know that ctx is of type "context", e has the "expression" type (e is always used for expressions) and el is probably a list of expressions (l as suffix for lists).
Learning Ocaml is important, but it's much more important to understand how the compiler is written. Next part covers all about Haxe sources.