Introduction

There are many possible reasons to enable Haxe to target a new platform. Currently, the supported platforms are Neko, PHP, Javascript (and NodeJS, V8 etc..), Flash6/7/8, Flash9 and above and Actionscript 3.0, Tamarin and also soon Java, and C#, they are working but still underdevelopment, and some work has been done on Lua. Originally, the only available server platform was Neko, a powerful but not so easy platform to deploy. During a long time many people asked for PHP support as it's the easiest and cheaper platform to run web applications. Thanks to Franco Ponticelli's work, Haxe2 lets us deploy our Haxe applications on PHP servers. Then Hugh brought us C++ and was instrumental in remaping flash API to c++ to NME, and with Haxe3 Caue hopes to bring full Java and C# target.

"Deploy everywhere" is an interesting 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.

Compilers

A compiler essentially is an application that translates source code from one "origin" language to another "destination" language. The Haxe compiler can take this piece of code and transform it into a different language.

var x = 1; 
var y = x + arr[0];
trace(y);

With an hypothetical Haxe -> Python compiler we'll obtain this compiled code:

x = 1
y = x + arr[0]
haxe_Log_trace y

But not all platforms 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!

What is needed to develop a compilation target? »»

version #15133, modified 2012-07-20 16:02:47 by JLM