是否有用于 JavaScript 的本机机器代码编译器? [英] Is there a native machine code compiler for JavaScript?

查看:32
本文介绍了是否有用于 JavaScript 的本机机器代码编译器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有适用于 JavaScript 的本机机器代码编译器?我不是在谈论虚拟机.如果它不存在,可以做到吗?
我想知道由于语言的动态特性,它是否可以编译为二进制文件.

Is there a native machine code compiler for JavaScript? I'm not talking about a VM. If it doesn't exist can it be done?
I am wondering if it can be compiled to binary due to the dynamic nature of the language.

推荐答案

据我所知,JavaScript 没有静态编译器.这在理论上当然是可能的;然而,JavaScript 的静态编译需要一个非常重量级的运行时来支持其所有功能(例如动态类型和 eval).顺便说一句,当需要静态编译 Python(另一种动态语言)时,PyPy 开发人员最终创建了一种语言,该语言是 Python(称为 RPython)的一个非常受限制的子集,没有 Python 的一些更动态的特性,能够进行静态编译.

As far as I know, there are no static compilers for JavaScript. It is certainly theoretically possible; however, a static compilation of JavaScript would need a very heavyweight runtime to support all of its features (such as dynamic typing and eval). As a small aside, when presented with the need to statically compile Python (another dynamic language), the PyPy developers ended up creating a language which was a very restricted subset of Python (called RPython), void of some of Python's more dynamic features, that was capable of being statically compiled.

如果你问这个是为了从 JavaScript 代码创建一个独立的可执行文件,我确信必须有包装器,它们本质上会创建一个包含你的脚本和嵌入式 JavaScript VM 的可执行文件(遗憾的是,我没有知道任何副手).

If you're asking this for the purpose of creating a standalone executable from JavaScript code, I'm sure there must be wrappers which essentially would create an executable containing your script and an embedded JavaScript VM (sadly, I don't know any offhand).

这篇关于是否有用于 JavaScript 的本机机器代码编译器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆