3 ms·
Bonsai-c: C to asm.js compilation for humans
- KenanSulayman 11y agoReally great, like it. I'd also love to see the examples get more complex as the engine gets more capable. I mean the engine is pretty cool already: https://github.com/gasman/bonsai-c/blob/master/examples/add.c https://github.com/gasman/bonsai-c/blob/master/examples/add.... - but it doesn't give any impression about what it currently is capable of. (e.g. in the README it tells about the lack of string support, et al.) Will follow the progress of this project!
- azakai 11y agoI like this a lot. It's similar to lljs [1] in allowing small amounts of asm.js to be generated, using a familiar syntax (C). That's an important use case and indeed Emscripten doesn't really support it. 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/ http://lljs.org/
- yoklov 11y agoAs someone who has worked extensively with emscripten, and asm.js, something like this is great and needed. Very promising, however it could easily become a crappy version of emscripten by adding e.g. C++ support or full C standard library support.
- overgard 11y ago> 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. 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.