Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does the dart javascript compiler (dart2js) work?

Dart runs in its own Dart VM, but you can compile it to modern optimized JavaScript. But how does that work? Are there any articles or papers online which explain that process?

I am wondering if that is an easy straight forward matching element to element, only time consuming to develop, process or are there some elements/aspects of Dart which could not be compiled to JavaScript.

http://www.dartlang.org

EDIT:thx for your 2 answers. The point is, that i told a collegue of mine about dart and that dart can be compiled to JavaScript. He accepted that it could be compiled to JavaScript but it would result in mumbojumba code and will only work for simple stuff. In the end he said: '''ok, explain me. how is this compiling going to work on nontrivial code?'''

That's why i am asking. I was hoping that there is some material online i could link him.

like image 358
Gero Avatar asked May 12 '12 11:05

Gero


People also ask

What is dart2js?

Contents. Version note: Dart 2.18 removes the dart2js command-line tool from the Dart package, but retains the dart2js compiler. Use dart compile js to compile Dart code to deployable JavaScript.

How is Dart code compiled?

The dart code both SDK's and ours are compiled through AOT (Ahead-of-Time) compilation process to native ARM libraries. After successful compilation, the IPA (iOS extension same as APK) file is generated. Any widget rendering, input-output, event handling and so on is done by compiled app code.

What is Dartdevc?

The Dart development compiler (dartdevc) compiles Dart as JavaScript AMD modules. These modules work for web app development in modern browsers. Note: Dart 2.18 removes the dartdevc command-line tool from the Dart package, but retains the dartdevc compiler. Use webdev serve to compile Dart code to modular JavaScript.


1 Answers

The Dart Editor will now compile your Dart code to JavaScript with dart2js.

As for the second part of your question, the dart:io libraries are only for the server/command-line, so they can't be compiled with dart2js.

I realize now I think you are asking "how did the engineers design and implement the dart2js compiler", not "how do you run dart2js"

Here's a blog post on the announcement of dart2js: http://news.dartlang.org/2012/05/new-dart-to-javascript-compiler-ready.html

Kasper Lund, one of the engineers, adds "For the technically interested, I can tell you that the new compiler uses an internal representation in SSA form (static single assignment) and that the compiler is implemented entirely in Dart."

The source code is at http://code.google.com/p/dart/source/browse/#svn%2Fbranches%2Fbleeding_edge%2Fdart%2Flib%2Fcompiler%2Fimplementation

like image 84
Seth Ladd Avatar answered Sep 18 '22 23:09

Seth Ladd