Dart is an open-source, scalable programming language, with robust libraries and runtimes, for building web, server, and mobile apps.

Wednesday, May 9, 2012

New Dart to JavaScript compiler ready for testing

Posted by Kasper Lund

We're getting close to replacing our old friend "frog"—the currentDart-to-JavaScript compiler—with a new version called "dart2js". We'vebuilt the new version with an emphasis on correctness andcompatibility with the Dart VM. This means that you can now takeadvantage of some of the niceties of closures and code like this:

will no longer print 88888888 when compiled to JavaScript, but01234567 just like on the VM.

The new compiler is available in the latest continuous builds of theDart Editor and SDK. If you click on [Tools > Generate JavaScript] inthe editor menu, you'll see that we're automatically compiling yourcode with both frog and dart2js allowing you to easily compare theoutput:

Generating JavaScript using frog... Wrote ...Sunflower.dart.js [103.0kb written in 1.9 seconds] Generating JavaScript using dart2js... Wrote ...Sunflower.dart.js_ [126.0kb written in 2.6 seconds]

We're actively working on making the output smaller and faster, soexpect improvements over the next weeks. If you want to try to use thedart2js output in your web app, you need to change the <script> tag inthe HTML file to include the data-compiler="dart2js" attribute likethis:

Writing a new compiler isn't completely trivial, and we're not done yet.There are a few features remaining before we are at parity with the VM,such as "support continue in switch statement" and"support closures in initializer lists".As always we appreciate any feedback youmight be able to provide us with in the form of bug reports or e-mailssent to the mailing list (http://www.dartlang.org/support/). If youfind that your project doesn't work when compiled with dart2js, wereally want to work with you to fix that.

For the technically interested, I can tell you that the new compileruses an internal representation in SSA form (static single assignment)and that the compiler is implemented entirely in Dart.Performance-wise it isn't highly tuned yet, but we feel like we have agood infrastructure in place for interesting and effectiveoptimizations. We will keep you posted on our progress!