Enabling Haxe to target a new platform: Intro
"Deploy everywhere" is an interesant idea but there are some other reasons to make Haxe support a new target:
- Use of developer tools of the new language: testing, profiling, ...
- Reuse of existing libraries
- Enable Haxe to work in a different environment. Haxe is a web language, but being able to create real-time applications would be nice.
A compiler essentialy is an application that translates source code from one "origin" language to another "destination" language. Haxe compiler can take this piece of code and transform it into a different language.
var x = 1; var y = x + arr; trace(y);
With an hypothetical Haxe -> Python compiler we'll obtain this compiled code:
x = 1 y = x + arr haxe_Log_trace y
But not all plataforms execute this kind of human-readable text script. Only interpreters do. For instance, Mono/.NET use an assembler-like language (CLI), and the compilation of the same code would produce this output :
ldc.i4 1 stloc x ldloc x ldloc arr ldc.i4 0 callvirt instance void class [mscorlib]System.Collections.ArrayList::get_Item(int32) unbox.any [mscorlib]System.Int32 add stloc y ldloc y box [mscorlib]System.Int32 [mscorlib]System.Console::WriteLine(object)
More complicated, isn't it? Well, not all platforms are equally difficult to implement. Nicolas Cannasse had much more problems to implement flash9 target than with flash8 because of its type system. Adding Java Bytecode as a target can be a painful job!