Bonsai-c: C to asm.js compilation for humans
github.com
github.com
Two comments on this bit:
> Wait, what's wrong with Emscripten? [..] It's perfect if you've got a great big POSIX C + SDL codebase that you want to run in its own self-contained environment in a browser, but it's not very helpful for writing idiomatic Javascript code that just needs to drop into optimised asm.js occasionally for some heavy lifting.
First, I think this correctly describes some important use cases. But more generally, I think the main use cases I see in this space are
1. Complete C or C++ programs, like a 3D game engine. Emscripten mainly focuses on this.
2. A C or C++ library that people want to use from JS, like Box2D or Bullet. Emscripten focuses on this quite a bit as well. You can disable filesystem support and other unnecessary features for such pure computational code, and then for a library the size of Box2D or Bullet, Emscripten's runtime isn't a significant code size issue. And it provides tools to make C++ objects look like JS objects, so using such libraries is convenient (see ammo.js and box2d.js for examples).
3. Small amounts of C that are to be "embedded" in JS. lljs and Bonsai-c focus on this.
A second comment: The third use case here is easy to get wrong. There is often a cost to calling from JS to asm.js and back. Writing a little asm.js function that adds two numbers and calling that in a loop will generally not be efficient, both because such functions are often optimized to asm.js-like speed anyhow, and because of the JS<->asm.js overhead. To make it worth it, the asm.js needs to do a more serious amount of work. Just mentioning this because it seems like a common pitfall.
[1] http://lljs.org/
Very promising, however it could easily become a crappy version of emscripten by adding e.g. C++ support or full C standard library support.
That's not really true -- it's pretty easy to call into an Emscripten module from javascript. You have to do some data marshalling, but that's true of any dynamic language -> c binding.
Will follow the progress of this project!