简体   繁体   English

Dart是静态编译的,还是在解析并加载到VM时在运行时插入代码?

[英]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. Dart是一种动态类型化的语言,可以直接从源代码生成自己的机器语言等效项,而无需中间字节代码步骤。 There is no generic bytecode (like the JVM or llvm) and instead it is directly compiled into machine code. 没有通用的字节码(如JVM或llvm),而是直接编译为机器代码。

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. 我要补充一点,尽管直接编译为机器代码,但语言本身的设计方式却不允许C / C ++样式的编译器有效地生成快速高效的代码。 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似乎是试图填补JavaScript和Java之间的空白,而不是Java和C / C ++之间的空白。 Dart addresses many issues that make JavaScript hard to optimize most importantly typing of numeric variables. Dart解决了许多使JavaScript难以最重要地优化数字变量键入的问题。

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. 尽管有一些努力将Dart环境移植到Windows / Mac / Linux以外的各种平台上,但是我还没有看到真正的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. 那并不意味着它们不存在,我只是没有看到Linux Dart环境移植到Beagleboard和其他小型Linux发行版的东西。

From the Dart FAQ 从Dart常见问题解答

Q. Why didn't Google build a bytecode VM targetable by multiple languages including Dart? 问:Google为什么不构建可被多种语言(包括Dart)定位的字节码VM? 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: 每种方法都有优点和缺点,但是我们认为,在Dart的背景下,出于以下原因,构建特定于语言的VM是有意义的:

Google already works on a multi-language bytecode: LLVM bitcode in PNaCl. Google已经可以使用多语言字节码:PNaCl中的LLVM位码。

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. 即使字节码VM专用于Dart,语言VM也将更加简单快捷,因为它可以在更强的假设(例如结构化的控制流)下工作。 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. 通用字节码VM可能会更大,更慢,因为它会概括各种假设并添加Dart死代码的功能:例如,具有共享堆的多线程。

No bytecode VM is truly general-purpose; 没有字节码VM真正是通用的。 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. 语言VM留有更多空间来改进VM,并对语言的优化进行深层更改。 Some Dart engineers wrote an article talking about the VM question in more detail. 一些Dart工程师写了一篇文章,详细讨论了VM问题。

A pretty good presentation on Compiling Dart to Efficient Machine Code 关于将Dart编译为高效机器代码的很好的演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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