views:

510

answers:

4

I started working with ActionScript 3 / Flash 9 fairly recently, coming from a "real" programming background, and I have become a bit curious as to exactly what kind of machine code it ends up with at the end of the day. I would like to know what kind of optimizations the compiler makes when putting together the SWF with the optimize flag (like loop unrolling, const value resolution to an immediate, etc), as well as what sort of machine code the interpreters will generate (will a matrix multiply use the SSE instructions on capable processors, what FPU mode does it use, are the data structures auto-aligned, etc).

Does anybody have any links to documentation on this? Google just keeps sending me to third-party products.

+1  A: 

I would start check out Nicolas Cannasse's blog and work (the guy behind MTASC AS2 compiler and haXe) ... and everything that is related.

Also - but a bit more superficial - there was a quite interesting broadcast on the subject recently on Peter Elst blog :

http://www.peterelst.com/blog/2009/03/10/flash-player-internals/

Theo.T
A: 

I may be wrong, but I was under the impression that Actionscript is not compiled, it's rather interpreted, like php. The only difference is that Actionscript is encapsulated together with other assets into a .swf. I've seen while playing with some decompilers that you can view the code as some sort of byte code, too, but i wouldn't compare that to machine code by any means..

If you're looking for a performance boost, I would suggest you take a look at Alchemy. I've never worked with it, but this experimental Adobe product is supposed to allow you to port C/C++ code onto the Flash Player, with a minimum of performance loss.

evilpenguin
You are wrong. ActionScript is compiled to Flash bytecode (the "intermediate language") - that's what the SWF is. The Flash Player is a Flash bytecode interpreter for the SWF. A SWF does not contain ActionScript source - that is why tools like flasm are useful.
Not Sure
-1 for interpretted +1 for alchemy. lucky escape!
spender
A: 

Since AS3, there is new virtual machine which uses JIT.

Also, I'm not an expert in licenses but the Flex SDK compiler is also Open Source if I remember correctly.

Alas, it seems reading the source of the compiler is going to be my only option short of analyzing the IL disassembly.
Not Sure
+1  A: 

I have checked flash compiler recently. It's amazing! Here is simple class code:

    var A : Number = 0.0;
    A = A*2*4;

And here is disassembled code:

5       pushdouble      0
7       convert_d
8       setlocal1
9       getlocal1
10      pushbyte        2
12      multiply
13      pushbyte        4
15      multiply
16      convert_d
17      setlocal1

Wow! In 21th century we have compiler on level of 1980th.

datacompboy