At the end of my Leaving the Sandbox session I showed two projects I have been working on without telling anyone. The first was a compiler that could compile C# to SWF. The second was another compiling being able to compile Java to SWF. First of all I have to say that both tools are far from being finished. They are a so called proof-of-concept. For me it is enough to know that this is possible. I am also not sure if I will finish one of those tools.
So how does this work? Because I am now working on the AudioTool backend for our highly anticipated launch I had to switch to fulltime Java development. In order to understand the JVM better I started to search for the optimizations that the HotSpot VM performs and stumbled upon a framework called Soot. Voilà. Reading about Soot made me question why nobody is working on such a framework for ActionScript. Probably because universities see Flash just as a toy. For us developers being dependent on the Flash Platform it is of course more than that.
I will quickly explain what Soot does. It reads compiled Java class files and converts the machine code they contain into a three address code representaiton. This code is then heavily optimized. TAAS is basically doing the same. I also want to note that Soot is by far more complex and complete than TAAS right now. It would be megalomania saying that TAAS is Soot for ActionScript. But you get the idea. The one framework converts Java to three address code and the other framework converts ActionScript to three address code. Maybe it is possible to connect them.
This is what I did for the Java compiler. The whole pipeline looks like this:
- Compile Java sourcecode with the Java compiler of your choise
- Use Soot to get the three address code representation of a compiled binary
- Create TAAS expressions for the expressions that Soot uses
- Connect the TAAS graph the same way the Soot graph is connected
- Compile the TAAS graph to a SWF
This is about it. There is some glue-code involved here and there and I did not implement all Java expressions yet. I did also not bother about threads. Basically one could do what Scott has done for Alchemy. The cool thing is that we get highly optimized Java code because of the Java compiler and Soot. Then the TAAS compiler can run a second time after linking is done and perform platform specific optimizations like inlining and loop invariant code motion for certain expressions.
I already wrote a couple of classes and packed them in a SWC. Those mimic the behaviour of the Java classes like java.lang.System or java.util.LinkedList. On the Java side I implemented the Flash classes like flash.display.Sprite and flash.events.EventDispatcher. The interesting part is that all the methods those classes contain are marked native which means they have no implementation since they are native to the Flash Player.
This is also a great advantage. It is slow in Alchemy to call Flash methods and to communicate with Flash classes. The Java approach does not have this tradeoff. I also do not have to trigger the ActionScript compiler. The conversion form class to swf is entirely done using Soot and TAAS.
So far for the Java compiler. But in order to show a little bit more of the potential I wanted to have a C# compiler working as well. The great thing about advanced languages and a large community is that people have already built a lot of tools. It did not take too long to find an advanced framework that converts C# to Java. Actually this is not be the best approach. But I could not find the “Soot for C#” the evening before my FOTB session.
So I am using net2java to convert .NET code like C# or VisualBasic to Java. That code is then compiled using the Java compiler and I am using Soot again to convert the code to TAAS without much stress.
For me the most important part is to know that it is possible to compile .NET source code and Java binaries to SWF. To complete those tools one just has to implement all the missing expressions and the standard Java library in Flash. Everything could also work the other way around. Compiling from TAAS to .NET, Silverlight and Java is another option.

As usual : Excellent.
You are amazing, i don’t know where you find the time to sleep!
I think http://en.wikipedia.org/wiki/Phoenix_%28compiler_framework%29 is what you’re looking for.
This IS want we are all longing for!
Come on! You can make it :)
I hoped to see the swf demo’s here too. The ones you demo’ed at FOTB. Would’ve loved to see that 500fps swf running…
Very hi-end stuff. Really looking forward to how Adobe is going to react to this, and what other amazing stuff you’re going to pull off!
Awesome stuff, man! Keep it up!
I hope that you will find a way to use C# without having to convert it to Java first. Compiling a SWF directly from the Microsoft CLR would open Flash to the announced 40 languages supported by the MS CLR.
@Tek: Exactly. There is so much potential. Right now I could support only VisualBasic and C# but being able to convert on the CIL level directly would be just awesome.
I will have a look at Phoneix and some parts of the Mono project like Cecil could be a good help as well.
That’s very interestning. I actually made a quick try at doing a CIL->SWF converter, but I just made an incomplete SWF decompiler and don’t work on this project anymore. The main reason why I wanted to do this is the upcoming C# 4.0 specifications (the beta implementation is already available) that specifies dynamic types, just like AS3 does. I though that was a great opportunity to develop a pure CIL -> ABC compiler, because this new feature it a great step to language interoperability.
But I don’t work on it any more now :x
Man you are a genius! Thanks a lot for pushing flash so much forward. Doesn´t adobe knock on your door once a day? if not, they are really missing how much you have already contributed to the flash platform! thumbs up!
Hi,
Just in case, are you aware of this project http://code.google.com/p/j2avm/ ?
Cheers
Cool stuff Joa, cant wait to see your java and c# tools.
First of all. Thanks very much for your useful post.
I just came across your blog and wanted to drop you a note telling you how impressed I was with the
information you have posted here.
Please let me introduce you some info related to this post and I hope that it is useful for community.
There is a good C# resource site, Have alook
http://CSharpTalk.com
Thanks again
Rahul
I think if you would like to wirte a software which can transfer Java code to Flash code or can transfer class file to swf files it’s a great job for java programmer!
since,we can develop beautiful page use java language