Busy Developer's Guide to WebAssembly

ted.neward@newardassociates.com | Blog: http://blogs.newardassociates.com | Github: tedneward | LinkedIn: tedneward

Objectives

What are we going to do today?

WebAssembly: Overview

Assembly language... for the Web?!?

WebAssembly: Overview

WebAssembly is...

WebAssembly: Overview

Goals of WASM:

WebAssembly: A History

How did we get here?

WebAssembly: A History

In the beginning (1997), browsers ran Javascript

WebAssembly: A History

In the beginning (1997), browsers ran Javascript

... and we all hated it

WebAssembly: A History

In the beginning (1997), browsers ran Javascript

... and we all hated it

WebAssembly: A History

Around the same time (1997), browsers also ran Java applets

WebAssembly: A History

Emphasis shifted entirely to the server

WebAssembly: A History

2006: jQuery begins to change minds

WebAssembly: A History

2011: Erik Meijer suggests "Javascript is the assembly language of the browser"

WebAssembly: A History

2013: What if we had a JS library that mimicked a CPU?

WebAssembly: A History

2015: WASM Community Group started

WebAssembly: A History

2018: WASM 1.0 ships

Getting Started

Hello, WebAssembly

Getting Started

WebAssembly is generally a compiler target format

Getting Started

Pick a source language to use

Getting Started

Pick a runtime engine

Getting Started with Emscripten

From 0 to Hello, world!

Getting Started with Emscripten

Installation via package managers

Getting Started with Emscripten

Installation "by hand"

Getting Started with Emscripten

Installing Emscripten SDK "by hand"

$ git clone https://github.com/juj/emsdk.git
$ cd emsdk
$ ./emsdk install latest
$ ./emsdk activate latest

Getting Started with Emscripten

Write some C/C++!

#include <stdio.h>

int main(int argc, char ** argv) {
  printf("Hello, world!\n");
  return 0;
}
#include <iostream>
using namespace std;

int main(int argc, char ** argv) {
  cout << "Hello world" << endl;
  return 0;
}

Getting Started with Emscripten

Compile

$ emcc -s WASM=1 -o hello.html --emrun hello.c

... or ...

$ em++ -s WASM=1 -o hello.html --emrun hello.cpp

Then

$ emrun --no_browser --port 8080 .

Open a browser to http://localhost:8080/hello.html

Semantics

WebAssembly interpreter/VM concepts

Semantics

WebAssembly interpeters

Semantics

WebAssembly execution

Semantics

Phase 1: Decoding

Semantics

Phase 2: Validation

Semantics

Phase 3: Execution

Glossary

A collection of terms

Glossary

Module:

Glossary

Functions:

Glossary

Table

Glossary

Linear memory

Glossary

Traps

Glossary

Embedder

WASM Bytecode

Instruction set for the WebAssembly virtual ISA

WASM Bytecode

WASM bytecode categories:

WASM Bytecode

Module/structure definition

WASM Bytecode

An empty module

<</home/runner/work/Slides/Slides/Content/WebAssembly/code/wat/empty.wat NOT FOUND>>

WASM Bytecode

Module/structure definition

WASM Bytecode

Module/structure definition

WASM Bytecode

A more reasonable module (1/2)

<</home/runner/work/Slides/Slides/Content/WebAssembly/code/wat/adder.wat NOT FOUND>>

WASM Bytecode

A more reasonable module (2/2)

<</home/runner/work/Slides/Slides/Content/WebAssembly/code/wat/adder.wat NOT FOUND>>

WASM Bytecode

Numeric "bases" to operations

WASM Bytecode

Numeric unary operations

WASM Bytecode

Numeric binary operations

WASM Bytecode

Variable instructions

WASM Bytecode

Memory instructions

WASM Bytecode

Control instructions

WASM Bytecode

Control instructions

Hosting WASM

Hosting WASM in Javascript environments

Hosting WASM

WebAssembly global object

Hosting WASM

Various WebAssembly.-prefixed constructors

Hosting WASM

NodeJS-based hosting

<</home/runner/work/Slides/Slides/Content/WebAssembly/./code/wat/runwat.js NOT FOUND>>

Hosting WASM

NodeJS-based hosting

<</home/runner/work/Slides/Slides/Content/WebAssembly/./code/wat/runwat.js NOT FOUND>>

Hosting WASM

Browser-based hosting

<</home/runner/work/Slides/Slides/Content/WebAssembly/./code/wat/runwat.html NOT FOUND>>

WASM Tooling

An evolution in progress

WASM Tooling

WebAssembly maintains many tools

WASM Tooling

... including an IDE!

WASM Tooling

WABT tools

WASM Tooling

WABT tools

WASM Tooling

WABT tools

WASM Tooling

Binaryen

WASM Tooling

Binaryen tools

WASM Tooling

Binaryen tools

WASM Tooling

Binaryen tools

WASM Tooling

3rd-party Tooling

Summary

Wrapping up

Summary

WebAssembly...

WebAssembly Resources

Where to go to go get more

WebAssembly Resources

Web

WebAssembly Resources

Web

WebAssembly Resources

Languages

WebAssembly Resources

Runtimes

Credentials

Who is this guy?