WebAssembly, browser bytecode
This collaborative project of browser editors offers an intermediate language for the Internet based on asm.js.
Introduced by Brendan Eich, creator of JavaScript and partly Asm.js, WebAssembly or Wasm, is a new intermediate presentation language (IRL) that is compatible with all browsers. It will allow various high-level languages to work in browsers, being compiled in Wasm. The initial goal is to compile C and C++ programs and libraries into WebAssembly. Then you will have to follow other languages.
In June 2015, development is just beginning. 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 keep Asm.js and wasm compatible for several years. Not only for support with browsers, but also because Asm.js is also in development, and the new features that are included in it will also be indispensable for wasm. For example, threads with shared memory, support for multi-core processors.
Subsequently, when all browsers support the new WebAssembly language, both languages may diverge. The second will be changed without touching Asm.js, which means JavaScript .
In particular, Wasm receives Google support with the NaCl team, so you can foresee abandoning the latter, whose goal was quite close: to make native applications work in the browser. The V8 team also announced the continued integration of wasm into the JavaScript compiler. Thus, the wasm engine can create IR (intermediate representation) code that is directly interpreted in JIT.
Experiments have shown that during the parsing of new code (not the execution speed) it can be 20 times faster than Asm.. js. The size of the binary code produced is also smaller than in Asm.js .
According to Brendon Eich, wasm is actually "compressed AST coding," not a real bytecode. AST for Abstract Syntax Tree - code tree.
A few more wasm benefits:
- In
- JavaScript programs (as is the case with asm.js) can use modules written in wasm. This will happen through the ES6 module system.
- It will have a collective garage and access to the DOM.
- Two representations of code are possible: binary for execution or text for reading. As for assembly language - but this is not one .
- Backend wasm is offered for LLVM initially. We will be able to generate wasm code on options from C/C + +. It will then be available for other languages .
- Polypill is a JavaScript program that converts wasm code to asm.js for older browsers that do not support the former .
And one drawback:
- It does not yet support compiling dynamic languages (for example, JavaScript ).
Even if languages compiled in WebAssembly become a possible alternative to JavaScript, it will remain supported and privileged by browsers. Wasm will become part of the JS compiler.
Why a new intermediate language
?Why don't you just use LLVM, Java bytecode, or .NET?
The main goal of wasm is to make source code written in C and C++ work in web applications. A huge number of functions have been written in these languages, the ability to reuse them with comparable runtime is really noticeable. 3D games are also mostly written in C++: they become portable with wasm.
Wasm wants to be to applications in the browser what Vulkan is in OpenGL and DirectX: a versatile and wearable intermediate code with close to native action speed.
LLVM
LLVM bit code was not saved because it is not portable. It contains meta data and is designed to create executable binaries, not to run managed on all systems.
By the way, Google has already tried to use LLVM in a browser with NaCL and this has not been accepted by other publishers.
However, to compile the intermediate LLVM language, wasm uses Emscribtem, so we retain the advantages of its tools.
.NET
Runtime .NET has intermediate code that can run on a virtual machine or be compiled. However, it is not suitable for C and C++ languages. Microsoft uses C + +/CLI, which is different from native C++.
JVM
The Java virtual machine is also not one of them, because although there were many languages on this platform, this is not so C and C++. Not even to mention Oracle's penchant for prosecution on such a futile motive as using its API. The whole Network could face an army of surly firm lawyers, which would be disastrous. WebAssembly will ensure peaceful development .
Brandon Eich quotes in WebAssembly
The continuation of ASM.js evolution is wasm.
At first, WebAssembly starts as ASM.js, but with compressed syntax it is a binary syntax. But as soon as all browsers support both wasm and ASM.js, and after a decent interval of browser updates, then wasm can start growing with extra semantics that do not need to be installed in JavaScript.
There are a number of languages that you could compile into wasm.
To suggest that the network is in stasis is not a good hypothesis, I think this is a mistake that has long happened with projects such as Portable Native Client, and Dart too.
WebAssembly vs Java
The creators of the language saw Lest much further than the browser when they determined its specification. In fact, it is divided into two layers:
- The core of a language that defines its syntax and instructions regardless of any environment. It is a compact language that is easy to integrate .
- API for defining interfaces between wasm and different environments. The first was made for JavaScript .
The language itself can be used in this way on all kinds of platforms: on the Web, on the desktop, and on any operating system. It depends on which APIs are added to the language, and developers are now multiplying them. There is even an operating system, Nebulet, where everything is written in wasm and compiled into a binary.
The goal of the WASI project is to create a standard interface for all operating systems so that the same wasm binary can be compiled once and used everywhere. You can then compare WebAssembly to Java. The former has the advantage of operating in isolation with its own memory, therefore allowing more secure applications. There is also no shadow of Oracle and its restrictions on "intellectual property."
Another advantage over Java is that when designed to run even on IoT miniprocessors, runtime is significantly easier than Java. However, it can be used on the desktop and on the server, where it will make containers redundant as a docker.
Creating and Using WebAssembly Code
You must install emsdk, and wasmer or wasmtime to create wasm programs.
You can then compile the C or C++ source into wasm with this command:
emcc demo.cpp -o demo.wasm
and execute the program with this command:
wasmtime demo.wasm
A complete textbook in French is available at: webassembly.fr.
Tools for generating code and running it are available on GitHub.
- binarized. Script for executing wasm code on the command line.
- asm2wasm. Compilation of asm.js in WebAssembly.
- wasm2asm. Compiling WebAssembly to asm.js.
- s2wasm. Compiles specially crafted LLVM code into WebAssembly. LLVM has its own format for this.
- wasm.js. binaryen JavaScript version: once included in a web page, it allows you to run wasm even if the browser does not yet support it .
- Emscript. Compiles C and C++ to asm.js and with the BINARYEN option then compiles asm.js to wasm .
- Ilvasm. Converts .NET intermediate code to wasm. Partly at the moment.
- Lucet is a Linux compiler for creating local applications from C code.
- Native. A wasm compiler that creates binary executables for Windows or Linux. Compatible with C.
Links
- WebAssembly.fr. A French language site offers textbooks and demonstrations.
- What is the programming language for WebAssembly?
- WebAssembly Community Group. On W3C, this new language group is open to new members. The authors are currently the Google V8 and NaCl team, the Mozilla Emscribtem team, Microsoft, and the Apple langings and runtime team.
- From Asm.js to WebAssembly. Brendon Eich's performance. (English).
- WebAssembly design. GitHub has all the details about wasm. (English).