Alon Zakai, creator of Emscripten, writes about compiling C and C++ projects to JavaScript, including Python, eSpeak, and a game engine.
HN links it for working demos of Emscripten, such as CPython running in the browser and eSpeak text-to-speech compiled to JavaScript.
I think JavaScript will stick around for quite awhile. However, the viability and popularity of languages that compile to JavaScript will probably continue to increase.
Besides CoffeeScript, which mostly only offers syntactic improvements to JavaScript, there are several projects which compile very different languages to JS, including:
* Emscripten (http://emscripten.org/) compiles arbitrary LLVM bitcode to JavaScript. Since clang and GCC can both target LLVM, a whole lot can be compiled to JavaScript. The Python interpreter (http://syntensity.com/static/python.html) and the Bullet physics engine (http://www.syntensity.com/static/bullet.html) are both particularly impressive.
* Google Web Toolkit (http://code.google.com/webtoolkit/) compiles Java to JavaScript. It's used in many real projects. Scala+GWT (http://scalagwt.gogoego.com/) aims to use this toolchain to compile Scala code, though it's not yet production-ready.
* The reductio ad absurdum of this approach is http://bellard.org/jslinux/, a x86 PC emulator written in JavaScript. You can run almost any language in the web browser with that!
See https://github.com/jashkenas/coffee-script/wiki/List-of-languages-that-compile-to-JS for a (possibly exhaustive) list of languages like this.
Whether these approaches can deliver passable performance for legacy browsers is an open question. However, for newer browsers it's safe to assume this general approach holds a lot of promise.
It's kind of fascinating to peruse the generated js, if you are at all familiar with the CPython code:
http://syntensity.com/static/python.js
Also geeky fun to try to recognize what constants like 4294967295 correspond to -- it's all over the place!
And lots of literal char* strings encoded as integer sequences:
>>> s = [111,98,106,101,99,116,46,95,95,102,111,114,109,97,116,95,95,32,119,105,116,104,32,97,32,110,111,110,45,101,109,112,116,121,32,102,111,114,109,97,116,32,115,116,114,105,110,103,32,105,115,32,100,101,112,114,101,99,97,116,101,100,0]
>>> ''.join(map(chr,s))
'object.__format__ with a non-empty format string is deprecated\x00'
> An interesting post on the state of the port of Sauerbraten to WebGL (from C++/OpenGL) by Alon Zakai — no new demos, but worth reading if you’re interested in what you can do with Emscripten.
There is a new demo there since last week,
http://www.syntensity.com/static/bb/client_6.html
is the latest (includes models with bumpmapping, FPS arms, some other stuff).
It looks like this project is part of a goal similar to that. According to a blog post, Emscripten is an attempt to port a 3D game engine to the web:
http://syntensity.blogspot.com/2010/08/emscripten.html
The game engine's website is here:
http://www.syntensity.com/
Hopefully this experiment works out - both of these projects looks very interesting!
NaCl is not needed for that. Embedding CPython into the browser has been done for some time now with Emscripten. Here's a demo: http://syntensity.com/static/python.html
This has the advantage over NaCl that it works in all browsers, not just Chrome. It's also portable.
We do have that VM. It just happens that this VM's "bytecode" looks like JavaScript.
Here is Python running in the browser:
http://syntensity.com/static/python.html