WevAssembly on MDN

WebAssembly concept

The official documentation

Is a new specification specified by the W3C with a complete set of semantics

Binary format, small size, fast loading,

The goal is to maximize hardware capabilities to achieve native execution efficiency.

Goal:

  • Fast, efficient and portable
  • Readable and debuggable
  • Keep a safe
  • Don’t break the network

Integrating into the Web Platform

Related technologies

LLVM (Low Level Virtual MAchine underlying VIRTUAL machine)

To compile to WebAssembly, you need to compile LLVM first. This is a prerequisite for running subsequent tools

At the heart of LLVM is Intermediate Representation (IR), an assembly-like low-level language.

LLVM supports three representations: human-readable assembly, object form in C++, and serialized bitcode form.

IR

Reduced Instruction Set Computing (RISC) is a strongly typed Reduced Instruction Set (RISC) that abstracts the target Instruction Set.

For example, the function call convention of the target instruction set is abstracted into call and RET instructions with explicit arguments.

In addition, IR uses an infinite number of registers, such as %0, %1 and other forms of expression.

Asm.js

Asm.js includes a strict subset of JavaScript that can be used as a low-level, efficient compiler target language.

Code is translated using a source-to-source compiler (such as LLVM-based Emscripten), which translates THE VM bytecode generated by some native code (such as C) into JS code that runs on the Web using a VM (such as Emscripten). And through the browser support, the performance is optimized.

C/C ++---->Emscripten(VM)---->asm.jsCopy the code

Rust

Rust can be compiled into WASM and invoked in the Serverless function woven into the Internet structure.

Automatically generate binding code between Rust, WebAssembly, and JavaScript apis. Take advantage of libraries like Web-sys to provide pre-packaged bindings for the entire Web platform.

Development tutorial

Webassembly.org.cn/getting-sta…

loading

In future plans, WebAssembly modules can be loaded using ES6 modules (using

  • To obtain.wasmBinary file, convert it to a type array orArrayBuffer
  • Compile binary data into oneWebAssembly.Module
  • Instantiate this with importsWebAssembly.Module, acquired exports.