Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could Python be compiled to run on the V8 Engine?

Tags:

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?

like image 988
interstar Avatar asked Mar 06 '11 23:03

interstar


People also ask

Why is V8 faster than Python?

V8 is fast due to the JIT, Crankshaft, the type inferencer and data-optimized code. Tagged pointers, NaN-tagging of doubles. And of course it does normal compiler optimizations in the middle. The plain ruby, python and perl engines don't do neither of the those, just minor basic optimizations.

Is V8 faster than Python?

The only scripting language which beats Javascript (v8) in speed is Lua AFAIK. And yes, it is faster than Python.

Can V8 compile C++?

The V8 API provides functions for compiling and executing scripts, accessing C++ methods and data structures, handling errors, and enabling security checks. Your application can use V8 just like any other C++ library.


2 Answers

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.

like image 176
Chinmay Kanchi Avatar answered Sep 28 '22 04:09

Chinmay Kanchi


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.

like image 37
Erik Corry Avatar answered Sep 28 '22 05:09

Erik Corry