6

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.

Gero
  • 12,993
  • 25
  • 65
  • 106

3 Answers3

6

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

Seth Ladd
  • 112,095
  • 66
  • 196
  • 279
2

Kasper lund on the intermediate representation and the implemented optimizations. https://www.youtube.com/watch?v=GwBb_nqQLuc

Insidi0us
  • 1,088
  • 9
  • 17
1

Are there any articles or papers online which explain that process?

The front-end is your classic hand-rolled lexer and recursive descent parser. The back end is, I believe doing a bunch of type inference (since Dart's type annotations are too loose to let you do reliable static type analysis from them, and the runtime semantics don't let you take the type annotations seriously). If you look for papers on "concrete type inference", I believe you'll find some of the literature you're looking for. Also, any reference on compiling to SSA form (and doing code gen from that form, I assume) should help.

munificent
  • 11,946
  • 2
  • 38
  • 55
  • Where I can find the source code for the lexer and parser. I searched in dart github repo but I can't find any thing ? – E.Omar Nov 25 '19 at 11:07
  • The location is a little strange because we are in the process of unifying the front ends for our various compilers, but its current home is here: https://github.com/dart-lang/sdk/tree/master/pkg/_fe_analyzer_shared/lib/src – munificent Jan 21 '20 at 21:49
  • 1
    Thank you. but there is something I cant understand. How parser the parser for dart is implemented using dart? – E.Omar Jan 23 '20 at 05:20