简体   繁体   中英

Is Dart statically compiled, or is code interpetted at runtime as it's parsed and loaded into the VM?

我试图理解为什么向Dart添加特征会导致内存中对象的形状发生变化,因此很好奇它现在如何在代码中加载。

Dart is a dynamically typed language that generates its own machine language equivalents straight from source code with no intermediate byte-code step. There is no generic bytecode (like the JVM or llvm) and instead it is directly compiled into machine code.

I would add that despite compiling straight to machine code, the language itself is not designed in a way that would allow a C/C++ style compiler to effectively generate fast efficient code. This is by design as Dart seems to be an attempt to fill the gap between JavaScript and Java rather than the gap between Java and C/C++. Dart addresses many issues that make JavaScript hard to optimize most importantly typing of numeric variables.

There are some efforts to port the Dart environment to various platforms beyond Windows/Mac/Linux but I have yet to see an actual straight to machine language compiler for Dart. That doesn't mean they don't exist, I just haven't seen anything other than ports of the Linux Dart environment onto Beagleboard and other small Linux distros.

From the Dart FAQ

Q. Why didn't Google build a bytecode VM targetable by multiple languages including Dart? Each approach has advantages and disadvantages, but we feel that in the context of Dart it made sense to build a language-specific VM for the following reasons:

Google already works on a multi-language bytecode: LLVM bitcode in PNaCl.

Even if a bytecode VM is specialized for Dart, a language VM will be simpler and faster because it can work under stronger assumptions—for instance, a structured control flow. These assumptions make the implementation cleaner and optimizations easier.

A general-purpose bytecode VM would be even larger and slower, as it generalizes assumptions and adds functionality that for Dart is dead code: for example, multithreading with a shared heap.

No bytecode VM is truly general-purpose; they all make assumptions that privilege some class of languages. A language VM leaves more room to improve the VM and make deep changes to optimization of the language. Some Dart engineers wrote an article talking about the VM question in more detail.

A pretty good presentation on Compiling Dart to Efficient Machine Code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM