WebAssembly, bytecode for browser

This joint project between browser vendors uses asm.js as a starting point for an IR of the Web.

Presented by Brendan Eich, creator of JavaScript and partly of Asm.js, WebAssembly or wasm, is a new intermediate representation language (IRL) compatible with all browsers. It will allow different high-level languages to run in browsers being compiled to wasm. The initial goal is to compile programs and libraries from C and C ++ to WebAssembly. Then other languages will follow.

In June 2015, the development has just begun. But it is facilitated by the use of Asm.js as a starting point. This subset of JavaScript is compatible with all browsers.

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.

WebAssembly diagram

Later, when all browsers will support the new WebAssembly language, both languages ​​may begin to differ. The second will be changed without modifying Asm.js, so JavaScript.

Wasm in particular receives the support of Google with the involvement of the NaCl team, so we can therefore anticipate the abandonment of the latter whose goal was close enough: to run native applications in the browser. Furthermore the V8 team announced the integration of wasm in the JavaScript compiler. So the wasm engine can produce IR code to be interpreted by the JS JIT engine.

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:

And some disadvantages:

Although compiled languages ​​in WebAssembly become a possible alternative to JavaScript, it will remain supported and privileged by browsers. Wasm will be a part of the JS compiler.

Quotes from Brendan Eich about WebAssembly

The continued evolution of ASM.js is wasm.

At first, WebAssembly starts out just like ASM.js, but with a compressed syntax, that’s a binary syntax. But once all the browsers support both wasm and ASM.js, and after a decent interval of browser updates, then wasm can start to grow extra semantics that need not be put into JavaScript.

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

A tutorial is provided on the site: Developer's guide to WebAssembly.

Tools to generate wasm code and run it are available on GitHub.