WebAssembly

From Wikipedia, the free encyclopedia
Jump to: navigation, search
WebAssembly
Paradigm Expression-oriented
Typing discipline Static
Platform Platform independent
License Apache License
Filename extensions .wast, .wasm
Website webassembly.org
Influenced by
asm.js, PNaCl

WebAssembly or wasm is an experimental efficient low-level programming language for in-browser client-side scripting, which is currently in development. Its initial aim is to support compilation from C and C++,[1] though other source languages such as Rust are also supported.[2]

Design[edit]

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[edit]

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[edit]

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] 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[edit]

It is still early days and the standard is still in flux. However a minimum viable product has been defined ( https://github.com/WebAssembly/design/blob/master/MVP.md ).

It defines a WebAssembly binary format in human unfriendly binary format, as well as a slightly more human friendly "Linear Assembly Bytecode" format that looks like more 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 format, then to wasm binary.

C (Input Source) text "linear assembly bytecode" (Intermediate Representation) WASM binary encoding (Binary shown below in Hexidecimal)
int factorial(int n) {
  if (n == 0)
    return 1;
  else
    return n * fac(n-1);
}
get_local 0
i64.const 0
i64.eq
if i64
    i64.const 1
else
    get_local 0
    get_local 0
    i64.const 1
    i64.sub
    call 0
    i64.mul
end
20 00
42 00
51
04 7e
42 01
05
20 00
20 00
42 01
7d
10 00
7e
0b

(Source for above example in https://github.com/WebAssembly/design/blob/master/TextFormat.md )

Internally at the moment the tooling of the wasm compiler system 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:

(module
  (memory 256 256)
  (export "memory" memory)
  (type $FUNCSIG$dd (func (param f64) (result f64)))
  (import $exp "global.Math" "exp" (param f64) (result f64))
  (export "doubleExp" $doubleExp)
  (func $doubleExp (param $0 f64) (result f64)
    (f64.mul
      (call_import $exp
        (get_local $0)
      )
      (f64.const 2)
    )
  )
)

(Source for above in http://cultureofdevelopment.com/blog/build-your-first-thing-with-web-assembly/ )

See also[edit]

References[edit]

  1. ^ a b "WebAssembly High-Level Goals". GitHub / WebAssembly / design. 11 December 2015. 
  2. ^ "Announcing Rust 1.14". The Rust Programming Language Blog. 22 December 2016. 
  3. ^ "Design Rationale". GitHub / WebAssembly / design. 1 October 2016. 
  4. ^ "Launch bug". GitHub / WebAssembly / design. 11 June 2015. 
  5. ^ Wagner, Luke (14 March 2016). "A WebAssembly Milestone: Experimental Support in Multiple Browsers". Mozilla Hacks. 
  6. ^ Thompson, Seth (15 March 2016). "Experimental support for WebAssembly in V8". V8 Blog. 
  7. ^ Zhu, Limin (15 March 2016). "Previewing WebAssembly experiments in Microsoft Edge". Microsoft Edge dev blog. 
  8. ^ "WebAssembly: a binary format for the web". ②ality – JavaScript and more. 18 June 2015. 
  9. ^ a b Bright, Peter (18 June 2015). "The Web is getting its bytecode: WebAssembly". Ars Technica. Condé Nast. 
  10. ^ "WebAssembly/design". GitHub. Retrieved 28 December 2015. 

External links[edit]