Since I started the development of some other library I completly put AS3V aside because the Eclipse integration with FDT is currently not possible. But since AS3V is working already I decided to release a version really quick that allows you to use AS3V as an Ant Task or simply from command line.
I know it would be better to have it as an Eclipse Plug-in with nice little markers etc. but for that I need some more extension points in FDT. I do not know about FlexBuilder but it would be probably the same.
The file includes an example build and some test cases that show you how AS3V can detect common errors and mistakes. There is currently not that much documentation available for the rules and parameters you can specify. Putting a list online with all rules and nice descriptions is of course something I would like to do but currently the time for that is missing. I hope everything is self-explaining if you have a look at the readme and example files.
Update: The AS3V package has been updated with one bug fix and some modifications so that AS3V will produce a more interesting log output if it fails for some reason. Using AS3V with Eclipse works only if you specify fork="true" like in the Flex SDK example from the build file that comes with the zip.
I just want to share with you how Taas can actually optimize code and what happens behind the scenes. So in my last post I talked about stackless code and optimizations that are possible but how does it work at all?
Imagine you have got this ActionScript code:
var x: Number = 1.0;
var y: Number;
if(true)
{
y = 3.0;
}
else
{
y = 2.0;
}
x += y;
return x;
For the sake of simplicity I will not use local variables in the bytecode. But it will be easier to figure out what happens in the bytecode.
PushDouble 1.0
PushTrue
IfTrue L0
PushDouble 2.0
Jump L1
L0: PushDouble 3.0
L1: Add
ReturnValue
This bytecode is nearly the same as the method but without local variables. This should be fairly simple to understand.
When converting bytecode to Taas, its corresponding control flow graph is converted into a control flow graph of Taas expressions. I do not want to go into much detail how the stack based code is converted but here is the graph before and after the transformation from bytecode to Taas. It looks quite similar but there is a major difference. All those constant values in the Taas graph are not values pushed on a stack but assignments to virtual variables which exist only in theory. You can see also that the Add in the bytecode has known operands and type in the Taas version. Since it is currently not know if 2.0 or 3.0 has been used there is a Φ function that says “This value is either 2.0 or 3.0 depending on the path taken at runtime”.
So as I said this code can be optimized much better than stack based code. This graph is very redundant. There are three utilities to compact and simplify the current graph of Taas expressions. The algorithm has been developed for Java bytecode but works with ActionScript very well tool. The concept is quite simple. Perform copy propagation, constant folding and dead code elimination until the graph stops changing. Applying these techniques to the Taas graph yields the following results.
Most of the theoretical variables have been eliminated using copy propagation.
Known constants have been replaced. Even the if condition is no longer needed and the false branch has been removed. The dead code elimination will clean up this code afterwards.
Dead code elimination has removed the dead Jump statement and also the value 2.0 from the Φ expression. Afterwards constant folding replaced the Φ expression with its one constant value. Then another iteration of constant folding replaced the Add expression with the constant value 4.0. Afterwards copy propagation has put the result into the Return statement and voilá.
This result may have seemed quite obvious from the beginning and you may ask who writes such code. Probably nobody. But once you start inlining methods this makes a lot of sense. A lot of preconditions are known in that case and unnecessary branches can be removed. Since inlining methods bloats up the code it is very important to compact it afterwards as much as possible. I hope you see now how interesting all of this might be in the future.
Here is the first preview of what AS3V looks like in Eclipse. I have written about 30 rules which include cyclomatic complexity checks and unreachable code detection. Most of the time was getting AS3V to link against the asc.jar from the Flex SDK inside Eclipse which is a real nightmare if you ever tried that one for yourself. However — it works. And hopefully I can forget about all the code I had to write pretty soon.
You can see in the screenshot that AS3V places markers in your Eclipse code. It works as an incremental project builder which means it is pretty fast since it only evaluates all your sources that have changed independently. If you have any suggestions for possible rules, please tell me. The Flex SDK coding conventions could be interesting for instance. Right now the Eclipse plug-in has still some problems but I think that a first version might be released in the next few weeks.
In September 2008 I started working on a tool called AS3V. The goal of AS3V was to parse source code and to check the code against a set of rules. My main problem with the first attempt of AS3V was that I used ANTLR. ANTLR is a great tool to create a compiler but for ActionScript 3 and its various strange behaviours you have to do a lot of hacking. Parsing ActionScript, XML and regular expressions with the optional semicolon in ECMAScript is not really fun using such a tool. metaas went that path and unfortunately their parser fails very often.
This is the reason why I started writing a parser manually from scratch. But this is also not a good idea. What about Adobe changing the language or adding features? I would have to change my parser. This is for instance a problem you have with FDT. Adobe releases a feature and it will take a while until you can adopt that. Maybe that feature is only beta but you want to use it. So are you going to implement it or not? Since the Flex SDK is open source I decided to take a completly different approach. Option one is to modify the original ASC. I think this is a bad idea. On every update from the Adobe guys you would have to patch the compiler again, and release a compiled version of that. This is what flexcover does. But I do not want to replace core parts of the Flex SDK with a modified compiler. So this is the reason why AS3V links only against the ASC. This means basically I do not care about what Adobe does with the compiler as long as the API stays consistent. This means also AS3V knows only as much as the ASC. This is sometimes a problem but in most cases not so important. ASC drops for instance braces every time. AS3V does not know if you write if(true) trace('foo'); or if(true) { trace('foo'); }. But in the end AS3V is able to analyze the real compiler output which is huge; theoretically every implicit cast can be watched!
Now enough theory. Why bother using AS3V and what is it good for? Imagine a loop like this:
for( var y: int = 0; y < height; ++y )
for( var x: int = 0; x < width; ++x )
index = y * width + x;
AS3V is currently smart enough to analyze the statement y * width + x and to figure out that y and width do not change in the inner loop. AS3V is therefore able to warn you about unneccessary calculations. There are lot of other rules I have already implemented which help you writing better code. For instance the pattern if( expr0 ) { if( expr1 ) { foo(); } } can be reduced to if( expr0 && expr1 ) { foo(); }.
There is a lot of room for other rules. I am happy to see some progress and hope that other people will find AS3V as useful as I. In the current state I have to implement more rules and a little bit more complex ones like dead code detection with constant folding. A release is targeted once I am happy with the rule set.
Not to forget: An Eclipse plugin which will show you appropriate warnings as neat little icons is of course also planned.
PBDT has now support for semantic highlightning. Thanks to the FDT guys again for answering a lot of Eclipse releated questions. Semantic highlightning works currently with parameters, input and output declarations and for defined preprocessor directives. Just have a look at the screenshot. I have also integrated complete color preferences support. If you go to Preferences > PBDT > Colors you can change everything the way you like.
PBDT has a new feature which is basic refactoring. Simply select the variable you want to rename and press Alt+Shift+R or select “Rename” from the context menu. There are currently two issues with refactoring. If the refactoring entry in the context menu is disabled please select the variable and try again. The same for the shortcut. If you want to refactor something, just select it first in the text. Once I figure out how Eclipse handles changes of the caret position I will fix that.
The second is about scopes. If you redefine a variable in a different scope the refactoring is not correct. But I guess 99% of the developers will not get in touch with this issue.
In this example i would be refactored in the outer and inner scope which is not correct.
void evaluatePixel()
{
int i;
{
int i;
i;
}
i;
out = sampleNearest(src,outCoord());
}
I am proud to announce that we are finally able to release some of our frameworks as open source. It has been a while and we talked very often about this topic. Today at the FlashForum Conference in Cologne I had the honor to show our open source hub to the public for the first time.
We have currently the UIEvent framework including full source code online. I can think of a lot of other frameworks we could release in the near future. Including for instance our DOM, Pogo, Tween or Graph framework. I really hope that we get the go for all those other libraries in the next few days as well.
Here is a nice tutorial that explains how to get PixelBender to work on Linux systems. Adobe offers just a Mac and Windows version of the toolkit. But using PBDT in combination with Wine allows PixelBender to work on Linux systems. How cool is that?
I also updated the PBDT plug-in to get rid of some errors. I did not include all feature requests yet because the FFK in Cologne is currently eating up all my time.
I just released my PixelBender plug-in for Eclipse. It integrates for us very charming into the workflow and is a good help when developing PixelBender kernels. I have put up a tutorial and instructions at this page.
Features of the PBDT plug-in include code completion, syntax highlightning and some other nifty features. It can be integrated into existing projects in FDT or FlexBuilder. Let me know what you think and please report any bugs or issues back to me.
A special thanks goes to Arne Deutsch from the FDT team for helping me a lot and answering all my annoying questions.
We have release a small update of the AudioTool and included André’s ToneMatrix. Some features that have been implemented in the last weeks are online as well. Removing an effect for instance will not destroy the cables. The desktop scales now without interrupting the audio output and various other performance tweaks have been made.