2013 Jul 19 06:55 PM MDT | ActionScript2 ActionScript-21 Assembly2 Flash2 Programming18 Web13 [2013]3

[Flasm](https://nowrap.de/flasm) allows people to disassemble flash files (.swf) into human-readable bytecode. I have discovered some of the Flash compiler techniques and other interesting things.

ActionScript // Flasm

Number.POSITIVE_INFINITY // POSITIVE_INFINITY or POSITIVE_INFINITYF
Number.NAN // _NAN or _NANF
return; // push UNDEF / return
trace(x) // push x / trace
// operators: push a / push b / [op]
| // bitwiseOr
^ // bitwiseXor
& // bitwiseAnd
<< // shiftLeft
>> // shiftRight
+ // add
- // subtract
* // multiply
/ // divide
% // modulo

What I find the most interesting is how it compiles logical expressions:

(a && b) or (_a   b_)
push [a]
dup
not ; only for &&
branchIfTrue label1
pop
push [b]
label1:
not
branchIfTrue label2
>>[body if true]<<
branch label3 ; only if else is present
label2:
>>[body if false]<<
label3: ; only if else is present

Now, how does it compile a compound expression?

Let’s start with (a [op1] b [op2] c), special case: (_[op1] ≠   ), ([op2] ≠ &&_)
push [a]
dup
not ; only for [op1] == &&
branchIfTrue label1 ; special case: branchIfTrue label2
pop
push [b]
label1: ; not in special case
{dup}
not ; only for [op2] == &&
branchIfTrue {new_label
pop
push [c]
new_label:
not
branchIfTrue label2}
>>[body if true]<<
branch label3 ; only if else is present
label2:
>>[body if false]<<
label3: ; only if else is present
In the special case, operator precedence will cause (b && c) to be evaluated together. After testing (_a && (b   c)_), I have discovered that the same thing as the special case occurs above.

I’m still not so sure about why they compile the conditionals like this. But it is interesting how an *OR* operator can become an *AND* operator with one *not* instruction.