WebAssembly or wasm is a low-level bytecode format for in-browser client-side scripting that is more efficient than JavaScript, from which it evolved. Its initial aim is to support compilation from C and C++,[1] though other source languages such as Rust are also supported.[2]
Design
WebAssembly is a portable stack machine[3] which is designed to be faster to parse than JavaScript, as well as faster to execute.[1]
History
WebAssembly was first announced on 17 June 2015[4] and on 15 March 2016 was demonstrated executing Unity‘s Angry Bots in Firefox,[5] Chromium, Google Chrome,[6] and Microsoft Edge.[7]
Development
The initial implementation of WebAssembly support in browsers will be based on asm.js[8] and PNaCl.[9] After the minimum viable product (MVP) release, there are plans to support garbage collection[10][11] which would make WebAssembly a compilation target for garbage collected programming languages like Java and C#. The team working on WebAssembly includes people from Mozilla, Microsoft, Google and Apple.[9]
Representation
In March 2017, the WebAssembly Community Group reached consensus on the initial (MVP) binary format, JavaScript API, and reference interpreter.[12] It defines a WebAssembly binary format, which is not designed to be used by humans, as well as a human-readable linear assembly bytecode format that resembles traditional assembly languages.
The table below represents 3 different views of the same source code input from the left, as it is converted to a wasm intermediate representation, then to wasm binary:[13]
| C (Input Source) | text “linear assembly bytecode” (intermediate representation) | WASM binary encoding (Binary shown below in hexadecimal) |
|---|---|---|
int factorial(int n) {
if (n == 0)
return 1;
else
return n * factorial(n-1);
}
|
get_local 0
i64.eqz
if i64
i64.const 1
else
get_local 0
get_local 0
i64.const 1
i64.sub
call 0
i64.mul
end
|
20 00
50
04 7e
42 01
05
20 00
20 00
42 01
7d
10 00
7e
0b
|
At the moment, the tooling of the wasm compiler system internally uses s-expressions (for parsing simplicity as well as extra information that “linear assembly bytecode” representation does not contain) to handle intermediate code. An example is shown below (updated to the current format):[14]
(module
(type $FUNCSIG$dd (func (param f64) (result f64)))
(import "global.Math" "exp" (func $exp (param f64) (result f64)))
(memory 256 256)
(export "memory" (memory 0))
(func $doubleExp (param $0 f64) (result f64)
(f64.mul
(call $exp
(get_local $0)
)
(f64.const 2)
)
)
(export "doubleExp" (func $doubleExp))
)
See also
References
- ^ a b “WebAssembly High-Level Goals”. GitHub / WebAssembly / design. 11 December 2015.
- ^ “Announcing Rust 1.14”. The Rust Programming Language Blog. 22 December 2016.
- ^ “Design Rationale”. GitHub / WebAssembly / design. 1 October 2016.
- ^ “Launch bug”. GitHub / WebAssembly / design. 11 June 2015.
- ^ Wagner, Luke (14 March 2016). “A WebAssembly Milestone: Experimental Support in Multiple Browsers”. Mozilla Hacks.
- ^ Thompson, Seth (15 March 2016). “Experimental support for WebAssembly in V8”. V8 Blog.
- ^ Zhu, Limin (15 March 2016). “Previewing WebAssembly experiments in Microsoft Edge”. Microsoft Edge dev blog.
- ^ “WebAssembly: a binary format for the web”. ②ality – JavaScript and more. 18 June 2015.
- ^ a b Bright, Peter (18 June 2015). “The Web is getting its bytecode: WebAssembly”. Ars Technica. Condé Nast.
- ^ “WebAssembly/design”. GitHub. Archived from the original on April 4, 2017. Retrieved 28 December 2015.
- ^ “WebAssembly/gc”. Github.
- ^ “Roadmap”. WebAssembly. March 2017.
- ^ jfbastien; rossberg-chromium; kripken; titzer; s3ththompson; sunfishcode; lukewagner; flagxor; enricobacis; c3d; binji; andrewosh (9 March 2017). “Text Format”. WebAssembly/design. GitHub.
- ^ Larsen, Nick (24 June 2016). “Build Your First Thing With WebAssembly”. Culture of Development: The Pit of Success.
| This article incorporates text from a free content work. Licensed under Apache License 2.0 Licence statement: Text Format, jfbastien; rossberg-chromium; kripken; titzer; s3ththompson; sunfishcode; lukewagner; flagxor; enricobacis; c3d; binji; andrewosh, GitHub. WebAssembly/design.
To learn how to add open-license text to Wikipedia articles, please see Wikipedia:Adding open license text to Wikipedia. |