Thursday, January 7, 2010

Cross-Compiling Java/C#/Ruby to iPhone

[Cross-posted at http://blogs.4point.com/taylor.bastien]

Cross-Compiling C/C++ to Actionscript using Alchemy

As you may well know, Adobe Labs has developed an exciting tool called Alchemy that leverages the LLVM open source project to cross-compile C/C++ code to a common run-time byte code. This byte-code is then cross-compiled to Actionscript code which is then compiled to Actionscript byte code (ABC). The earliest and most striking example of what can be accomplished with Alchemy was the port of Doom to Flash that Dave released on Newgrounds within a week of Alchemy's launch. He has now released the Doom Triple Pack which includes the bad boys Doom, Heretic and Hexen.

The good people of Automata Studios helped Adobe develop one of the first projects for demonstrating how Alchemy works. Here is their write-up on the subject.

Cross-Compiling to Objective-C (and more!) Using XML-VM

overview.jpg
Another development that has come down the pipe is some research done by Arno Puder and his colleagues at San Fancisco State University. Their work involves using open-source tools to transform code from one language (e.g. Java, C#) to an intermediate XML format which can then be transformed to another language (in this example, Objective-C). The project is called XMLVM.

Prof. Puder presented how all of this works at the Google offices and the video of this presentation is available on YouTube. It is a very cool idea and demonstrates once again (as all software does, really) the potential aggregate power of using many small, simple constructs. Byte code statements are converted to an XML format which can then be transformed to Objective-C. While the final code might not be as optimal as the original, it will do the same thing. My guess is that the toughest part would probably be handling language elements that don't exist in both the source and target languages (i.e. garbage collection, loose typing/auto-boxing, annotations). Perhaps you'd have to do away with overly "native" parts of a language language when writing the "from" code. The good professor covers part of this challenge in his presentation.

While the target language discussed is Objective-C, as you can see from the diagram above, the XMLVM project allows you to cross-compile to and from a number of different languages.Enjoy the video. (Hat tip to DiamondTears for bringing this to my attention.)






Compiling Flash Apps to Native iPhone Apps in Flash CS5 (in Windows!)

At AdobeMAX 2009, new functionality for the Flash Professional CS5 was demoed showing that this upcoming version will allow Flash (and Flex) applications to be compiled directly to an iPhone application (i.e. an IPA). In fact, some apps developed using this functionality are already available in the AppStore. Info, video and more can be found here.

From what I've been told, this functionality is implemented using cross-compilation and therefore necessarily leads to somewhat bloated/un-optimal apps. Frankly, I think that should be expected. With time this can surely be improved, but for now, I think we'll take what we can get.

I'm sure I'm not the only person who has thought to themselves: Will I finally be able to develop for iPhone/iPod Touch without having to shell out for a Mac!?!

Adobe plans to launch a public Beta of Flash CS5 later this year. Once I get to try it out, I'll let you know what I think.

Final Thoughts

One thing's for sure: watching these videos and reading the documentation gives me flashbacks of the more interesting classes from studying Computer Science in university. The beauty of working in this field is that even the coolest, most complex technology is not only within your grasp to use and understand, but also to implement.

As a developer, I have discussed with my brother what platform is most attractive: iPhone or Android? I own an iPod Touch already, but am unable to develop native apps since I don't have a couple grand to put down on a Mac (much higher priorities: student loan, big screen HDTV, next gen console). Android will support Java and (from what I've been told) Flash, but I don't want or need a cell phone. The jury's still out but it will be fun either way.

As always, I invite you to post any comments you might have on this subject.