Flex sdk 3.5.0 problem with ternary operators

I’ve got problems to isolate the problem into a very big project with many linked sources. After hours inspecting and commenting lines of code trying to figure out the reason why flex gave me an “internal error” I found the problem.
This very simple script was crashing the flex compiler if using the 3.5.0 sdk ( revision 3.5.0.12683 ).
Fortunately the 4.0.0 compiler works fine. At the end it seems to be the combination of “+” and “-” and the ternary operator.
package
{
   import flash.display.Sprite;
   public class ternary_test extends Sprite
   {
      public function ternary_test()
      {
         var n: Number = 0;
         var d: int = 3;
         var k: int = 5;
         var j: int = 10;
         n = 1 + ( -( d == 0 ? k : j ) );
         trace( "n=" + n );
      }
   }
}

will cause the compiler to crash with the following stack trace:

compile:

    [mxmlc] Loading configuration file /Applications/Adobe Flash Builder 4 Plug-in/sdks/3.5.0/frameworks/flex-config.xml

    [mxmlc] Error: null

    [mxmlc] java.lang.NullPointerException

    [mxmlc] 	at macromedia.asc.semantics.ConstantEvaluator.evaluate(ConstantEvaluator.java:1290)

    [mxmlc] 	at macromedia.asc.parser.UnaryExpressionNode.evaluate(UnaryExpressionNode.java:51)

    [mxmlc] 	at macromedia.asc.semantics.ConstantEvaluator.evaluate(ConstantEvaluator.java:2153)

    [mxmlc] 	at macromedia.asc.parser.ListNode.evaluate(ListNode.java:44)

    [mxmlc] 	at macromedia.asc.semantics.ConstantEvaluator.evaluate(ConstantEvaluator.java:1497)

    [mxmlc] 	at macromedia.asc.parser.BinaryExpressionNode.evaluate(BinaryExpressionNode.java:56)

    [mxmlc] 	at macromedia.asc.semantics.ConstantEvaluator.evaluate(ConstantEvaluator.java:2124)

    [mxmlc] 	at macromedia.asc.parser.ArgumentListNode.evaluate(ArgumentListNode.java:45)...

AsYacc – first alpha release

Before going further with discussing how to add runtime scripting support to a Flash applications, I’d like to share with you the source code of a porting of Yacc I did a while ago. I did some simple modification to make Yacc able to generate ActionScript 3.0 source code instead of C. It works quite well and supports a lot standard Yacc features. There might be some issues – report them to me and I’ll try to fix them 🙂

You can easilly find documentation about Yacc searching Google (you can start here for example).

Usually Yacc is used in conjunction with a Scanner generator (like Lex/Flex), but I didn’t to any porting of commonly used Scanner generators yet.

Here you can download the sources. The source code should be portable and compilable on all the most common platform, but I didn’t tested it on Windows yet. To compile the source code on Mac or Linux, cd to the source code directory and type use:

gcc *.c -o AsYacc

Once you have the compiled binary file, you can run the Parser generator using:

./AsYacc -Hpackage=it.sephiroth.test grammar.y

Where grammar.y is a text file that contains the grammar of a language defined using the proper syntax (see the docs online for all the detailed information you may need).

Here you can download a simple calculator example that uses the RegexLexer described previously to implement the Scanner. For the ones who might be interested, here is the grammar used:
/* Infix notation calculator. */
%{
%}
%token NUM
%left '-' '+'
%left '*' '/'
%left NEG
%right '^' /* exponentiation */
%%
input:
exp { trace( $1 ); }
;
exp:
NUM { $$ = $1; }
| exp '+' exp { $$ = $1 + $3; }
| exp '-' exp { $$ = $1 - $3; }
| exp '*' exp { $$ = $1 * $3; }
| exp '/' exp { $$ = $1 / $3; }
| '-' exp %prec NEG { $$ = -$2; }
| exp '^' exp { $$ = Math.pow( $1, $3 ); }
| '(' exp ')' { $$ = $2; }
;
%%

Java 6 Update 10 breaks Flex compiler!

I just want to share this problem I found so maybe someone can save some time..

Today while surfing the net I received a notification of an update of my Java installation to the Update 10 in order to see correctly the contents of that site.. bla bla bla..

Sometime later I switched to Flex and at the first execution of my ant script for compiling a flex project I suddenly received this beautiful error:
[exec] Error: java/security/MessageDigest
[exec] java.lang.NoClassDefFoundError: java/security/MessageDigest
[exec] at java.io.ObjectStreamClass.computeDefaultSUID(Unknown Source)
[exec] at java.io.ObjectStreamClass.access$100(Unknown Source)
[exec] at java.io.ObjectStreamClass$1.run(Unknown Source)
[exec] at java.security.AccessController.doPrivileged(Native Method)
[exec] at java.io.ObjectStreamClass.getSerialVersionUID(Unknown Source)
[exec] at java.io.ObjectStreamClass.initNonProxy(Unknown Source)
[exec] at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
[exec] at java.io.ObjectInputStream.readClassDesc(Unknown Source)
[exec] at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
[exec] at java.io.ObjectInputStream.readClassDesc(Unknown Source)
[exec] at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
[exec] at java.io.ObjectInputStream.readObject0(Unknown Source)
[exec] at java.io.ObjectInputStream.readObject(Unknown Source)
[exec] at flex.util.SerializedTemplateFactory.load(SerializedTemplateFactory.java:30)
[exec] at flex2.compiler.util.VelocityManager.getTemplate(VelocityManager.java:162)
[exec] at flex2.compiler.util.VelocityManager.getTemplate(VelocityManager.java:151)
[exec] at flex2.compiler.util.VelocityManager.getTemplate(VelocityManager.java:137)
[exec] at flex2.compiler.as3.genext.GenerativeSecondPassEvaluator.generateSupportCode(GenerativeSecondPassEvaluator.java:256)
[exec] at flex2.compiler.as3.genext.GenerativeSecondPassEvaluator.modifySyntaxTree(GenerativeSecondPassEvaluator.java:355)
[exec] at flex2.compiler.as3.binding.BindableSecondPassEvaluator.evaluate(BindableSecondPassEvaluator.java:102)
[exec] at macromedia.asc.parser.ClassDefinitionNode.evaluate(ClassDefinitionNode.java:106)
[exec] at flash.swf.tools.as3.EvaluatorAdapter.evaluate(EvaluatorAdapter.java:338)
[exec] at macromedia.asc.parser.StatementListNode.evaluate(StatementListNode.java:60)
[exec] at flash.swf.tools.as3.EvaluatorAdapter.evaluate(EvaluatorAdapter.java:923)
[exec] at macromedia.asc.parser.ProgramNode.evaluate(ProgramNode.java:80)
[exec] at flex2.compiler.as3.genext.GenerativeExtension.parse2(GenerativeExtension.java:114)
[exec] at flex2.compiler.as3.Compiler.parse2(Compiler.java:386)
[exec] at flex2.compiler.API.parse2(API.java:2390)
[exec] at flex2.compiler.API.parse2(API.java:2348)
[exec] at flex2.compiler.API.batch2(API.java:375)
[exec] at flex2.compiler.API.batch(API.java:1117)
[exec] at flex2.compiler.API.compile(API.java:1290)
[exec] at flex2.compiler.API.compile(API.java:1210)
[exec] at flex2.tools.Compc.compc(Compc.java:158)
[exec] at flex2.tools.Compc.main(Compc.java:41)

so I tried also to compile another project before go crazy, but I got this another java funny error, which was more or less unreadable as the previous one!

Fortunately I remembered the update I did of Java! And in fact after remove that update everything worked again!

Expressions evaluation at (almost) native speed

Finally I found a bit of time this weekend to do some other tests with expressions evaluation.

The results are pretty interesting, even if obvious from some point of view. I took the ExpressionEvaluator I wrote as example for the first post about this topic, and then I edited a bit the code adding just in time AS Bytecode compilation.
Thanks to that, expressions evaluation is much more fast and always safe because it runs in its own ApplicationDomain.

You can download the sources here, that includes the edited code and a test file. The test file runs 1 milion of iterations and may hang your browser or at worst case your system. Reduce the value of the ITERATIONS constant if you are not sure about the power of you machine.

If you want to read a bit more details about that, click on the link below to continue reading.

Continue reading

mxmlc NullPointerException crash

Today I was getting crazy to find out why Flex didn’t want to compile my application.. Clicking on compile it started suddenly to give me an internal compile error and nothing else. So i tried to compile with the mxmlc from a console just to see the error log and the outpuw was:
java.lang.NullPointerException
at macromedia.asc.semantics.FlowAnalyzer.evaluate(FlowAnalyzer.java:891)
at macromedia.asc.parser.BinaryExpressionNode.evaluate(BinaryExpressionNode.java:38)
at macromedia.asc.semantics.FlowAnalyzer.evaluate(FlowAnalyzer.java:890)
at macromedia.asc.parser.BinaryExpressionNode.evaluate(BinaryExpressionNode.java:38)
at macromedia.asc.semantics.FlowAnalyzer.evaluate(FlowAnalyzer.java:891)
at macromedia.asc.parser.BinaryExpressionNode.evaluate(BinaryExpressionNode.java:38)
at macromedia.asc.semantics.FlowAnalyzer.evaluate(FlowAnalyzer.java:890)
at macromedia.asc.parser.BinaryExpressionNode.evaluate(BinaryExpressionNode.java:38)
at macromedia.asc.semantics.FlowAnalyzer.evaluate(FlowAnalyzer.java:962)
at macromedia.asc.parser.ListNode.evaluate(ListNode.java:27)
at macromedia.asc.semantics.FlowAnalyzer.evaluate(FlowAnalyzer.java:5859)
at macromedia.asc.parser.LiteralXMLNode.evaluate(LiteralXMLNode.java:28)
at macromedia.asc.semantics.FlowAnalyzer.evaluate(FlowAnalyzer.java:3087)
at macromedia.asc.parser.VariableBindingNode.evaluate(VariableBindingNode.java:48)
at macromedia.asc.semantics.FlowAnalyzer.evaluate(FlowAnalyzer.java:962)
at macromedia.asc.parser.ListNode.evaluate(ListNode.java:27)
at macromedia.asc.semantics.FlowAnalyzer.evaluate(FlowAnalyzer.java:2897)
at macromedia.asc.parser.VariableDefinitionNode.evaluate(VariableDefinitionNode.java:32)
at macromedia.asc.semantics.FlowAnalyzer.evaluate(FlowAnalyzer.java:4629)
at macromedia.asc.parser.ClassDefinitionNode.evaluate(ClassDefinitionNode.java:86)
at macromedia.asc.semantics.FlowAnalyzer.evaluate(FlowAnalyzer.java:938)
at macromedia.asc.parser.ArgumentListNode.evaluate(ArgumentListNode.java:28)
at macromedia.asc.semantics.FlowAnalyzer.evaluate(FlowAnalyzer.java:750)
at macromedia.asc.parser.SetExpressionNode.evaluate(SetExpressionNode.java:39)
at macromedia.asc.semantics.FlowAnalyzer.evaluate(FlowAnalyzer.java:580)
at macromedia.asc.parser.MemberExpressionNode.evaluate(MemberExpressionNode.java:31)
at macromedia.asc.semantics.FlowAnalyzer.evaluate(FlowAnalyzer.java:1273)
at macromedia.asc.parser.ExpressionStatementNode.evaluate(ExpressionStatementNode.java:33)
at macromedia.asc.semantics.FlowAnalyzer.evaluate(FlowAnalyzer.java:4407)
at macromedia.asc.parser.ClassDefinitionNode.evaluate(ClassDefinitionNode.java:86)
at macromedia.asc.semantics.FlowAnalyzer.evaluate(FlowAnalyzer.java:2577)
at macromedia.asc.parser.ProgramNode.evaluate(ProgramNode.java:63)
at flex2.compiler.as3.Compiler.analyze2(Compiler.java:436)
at flex2.compiler.mxml.InterfaceCompiler.analyze2(InterfaceCompiler.java:337)
at flex2.compiler.mxml.Compiler.analyze2(Compiler.java:130)
at flex2.compiler.API.analyze(API.java:2360)
at flex2.compiler.API.analyze(API.java:2275)
at flex2.compiler.API.batch2(API.java:337)
at flex2.compiler.API.batch(API.java:1025)
at flex2.compiler.API.compile(API.java:1211)
at flex2.compiler.API.compile(API.java:1114)
at flex2.tools.Compiler.main(Compiler.java:222)

Wow!!
So, how can I find the problem? I can’t find any useful information from this log..
For this reason I had to remove portion of code from my mxml and from all the imported packages.. 2 hours of “debugging” gave me the solution!

A syntax error in a declaration of an XMLList was the problem!  Fixed the line also the compiler started to run again with no problems.

This is a portion of mxml code to reproduce the problem:
;

< ![CDATA[ private var uuid:String = ""; private var menubarXML:XMLList = <>
<>;
]]>

Flex2 and namespaces extending components

I took 2 hours to find a solution for that and I decided to blog it..
I was creating my new Flex2 component extending the UIComponent class and I need to define new custom styles for my own component…
Ok, i opened the “create and extend components” PDF guide and found that I need to put this code to accomplish it:
private static function classConstruct():Boolean
{
if (!StyleManager.getStyleDeclaration("ResizeManager"))
{
var newStyleDeclaration:CSSStyleDeclaration = new CSSStyleDeclaration();
newStyleDeclaration.setStyle("boxSize", 4);
StyleManager.setStyleDeclaration("ResizeManager", newStyleDeclaration, true);
}
return true;
}

That’s all, but at this time the compiler die with that error message “1000: Riferimento ambiguo a setStyle”, which in english should be: “1000: Ambiguous reference to setStyle“.
I google for some time but without finding a solution, then I discovered the problem. I was using in my component the mx_internal namespace, that was the problem. Once changed namespace everything was ok.

Flash Player 9, Flex 2, ActionScript 3.0: A Survey of the New Landscape

Colin has posted an interesting article on flash9, flex2, actionscript3.
Why ActionScript 2 coders should start learning ActionScript3 as soon as possible and why timeline coders and flash designers shouldn’t…
Colin underlined a significant aspect of this new flash release: the free flex2 command line compiler. (I asked for it since so much time!)

Read the full entry here:
http://www.moock.org/blog/archives/000189.html

SWF server side compiler with MTASC

I never thought at this before but it was so obvious!! …put the mtasc binary on remote server and let it create swf on the fly!
HOSHI Tetsuya put toghether a server side swf compiler using mtasc (http://hossy.net, Everything is unreadable… just click on ENTER 🙂 ).
He also published the source code (php files): http://hossy.net/sssc.zip
http://hossy.net/