WebAssembly, bytecode for browser
This joint project between browser vendors uses asm.js as a starting point for an IR of the Web.
The goal is to maintain compatibility between Asm.js and wasm for a few years. Not only for the support in browsers, but also because qu'Asm.js is also in development, and new features which will be include into it will be indispensable also to wasm. Eg threads with shared memory, support for multi-core processors.
The wasm code currently is that of Asm.js. When it begins to diverge, examples will be presented here. Experiments have shown a prototype of this new code that parsing time (not the speed of execution) can be multiplied by 20. It is therefore certain that the final code will be quite different. The size binary code generated will be three times more compact in Asm.js. The code is binary but a more readable text view is possible.
According to Brendan Eich, wasm is in fact a "compressed AST encoding" and not a true bytecode. AST for abstract syntax tree.
Some other advantage of wasm:
- It has a garbage collector.
- Two notations of the code are possible: binary for executing or text for reading. Like an assembly language - but it is not one.
- A wasm LLVM backend is proposed initially. We can generate wasm code with an option from C/C++. It will then be available for other languages.
And some disadvantages:
- The DOM of web pages can not be accessed from WebAssembly.
Quotes from Brendan Eich about WebAssembly
The continued evolution of ASM.js is wasm.
There are lots of languages you might compile to wasm.
Assuming stasis on the web — it’s not a good assumption, I think that was the mistake that happened long ago with projects like Portable Native Client and Dart, too
How to create and use WebAssembly code
Tools to generate wasm code and run it are available on GitHub.
- binaryen. Script to run wasm code on the command line.
- asm2wasm. Compile asm.js to WebAssembly.
- wasm2asm. Compile WebAssembly to asm.js.
- s2wasm.Compile the code specially produced by LLVM in WebAssembly. LLVM has its own format for this.
- Emscriptem. Compiles C and C ++ to asm.js and with BINARYEN option compiles then asm.js to wasm.
- Ilwasm. Converts the intermediate .NET code in wasm. Partly for now.
- WebAssembly Community Group. At the W3C, the group dedicated to the new language is open to new participants. Currently they are the team of V8 and NaCl of Google, the Emscriptem team from Mozilla, Microsoft and Apple's languages and runtim team.
- From Asm.js to WebAssembly. Presentation by Brendan Eich.
- Why we need WebAssembly. Interview of BE.
- FAQ of wasm. On GitHub.
- WebAssembly design. On GitHub, all details about wasm.
- Future Features. What the language will become.