Python 可以编译运行在 V8 引擎上吗?
大概 Javascript 被编译成某种字节码以在 V8 引擎上运行? Python 是否是一种足够相似的语言,以至于我们可以想象 Python 被编译为相同的字节码并在 V8 上运行?
有项目尝试这样做吗?
Presumably Javascript is compiled to some kind of byte-code to run on the V8 Engine? Is Python a similar enough language that we can imagine Python being compiled to the same byte-code and run on the V8?
Any projects trying to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
据我所知,还没有专门针对V8虚拟机的项目。然而,Pypy 和以前的 Unladen Swallow(现在合并到主 CPython 树的 py3k-jit 分支中)都尝试将 Python 即时编译为本机代码,类似于 V8 对 Javascript 所做的事情。
正如 @something 所说,pyjamas 允许您编写 Python 代码并将其转换为 Javascript,就像 GWT 对 Java 所做的那样。因此,任何翻译后的代码在 V8 下运行都将具有与任何其他 Javascript 代码相同的优势。
As far as I know, there are no projects that specifically target the V8 virtual machine. However, Pypy and the erstwhile Unladen Swallow (now merged into the py3k-jit branch of the main CPython tree), both attempt to just-in-time compile Python into native code, similar to what V8 does with Javascript.
As @something says, pyjamas allows you to write Python code and translate it into Javascript, much like GWT does with Java. Any code translated thus would have the same benefits to running under V8 as any other Javascript code.
V8 实际上没有通用字节码。有一个正则表达式字节代码,但通常不编译支持。有一个反序列化字节代码和一个重定位信息字节代码,但两者都是实现细节,您不能将它们用于任何用途。
所以你要找的是能编译成 JS 源代码的东西。
V8 doesn't actually have a general purpose bytecode. There's a regexp byte code, but support is not usually compiled in. There's a deserialization byte code and a relocation information byte code, but both are implemtation details and you can't use them for anything.
So what you are looking for is something that compiles to JS source code.
已经有三个项目提供了 Python 到 Javascript 编译器。生成的 Javascript 可以在包括 V8 在内的任何引擎上运行。寻找 Pyjamas、Skulpt 和 Py2JS。
这与将 Python 编译为 V8 字节码不同,但最终结果大致相同。
There are already three projects that provide a Python to Javascript compiler. The resulting Javascript can then be run on any engine including V8. Look for Pyjamas, Skulpt and Py2JS.
This is not the same as compiling Python to V8 bytecodes, but the end result is much the same.
有关在浏览器中运行 python 的方法,请参阅 python wiki 页面 WebBrowserProgramming。
For ways to run python inside browsers, see the python wiki page WebBrowserProgramming.
您是否正在寻找类似“睡衣”的东西?
http://pyjs.org/
Are you maybe looking for something like "Pyjamas"?
http://pyjs.org/
看看 http://repl.it/ - 这是一个编译为 JavaScript 的非常完整的 Python 解释器的示例。这是由于 Emscripten 实现的 - LLVM 字节码到 Javascript 的编译器。
Have a look at http://repl.it/ - it's an example of a pretty much complete Python interpreter compiled to JavaScript. This was achieved thanks to Emscripten - a compiler of LLVM bytecode to Javascript.
Python 已经编译为字节码并执行。这就是 CPython 中的 .pyc 文件。 Jython 同样编译为 Java 字节码(动态),IronPython for .NET 也是如此
Python is already compiled to bytecode and executed. This is what the .pyc files are in CPython. Jython likewise compiles to Java bytecode (dynamically), and so does IronPython for .NET