bzar / wasm-intro

WASM examples

Home Page:https://bzar.github.io/wasm-intro

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WASM-Intro

A scratchpad of stuff in WebAssembly. All examples are written for simplicity, not good code style nor performance. Please do not use anything here in important stuff.

Much of the toolchain is based on yurydelendik's "Using WebAssembly in LLVM" gist.

Build environment

Run make build and make install in tools. This builds LLVM, clang, binaryen and WABT with correct stuff for WebAssembly compiling.

Examples

Build by running make in each directory. Test using python3 by running make serve and browsing to localhost:8000.

To build intermediate results from the C -> WASM compilation, try make main.s and make main.wat

Add

Simple function export example. Adds two numbers together and prints to console

Import/Export

Same as Add, now with an added step of delegating the addition back to JavaScript.

Memory

Poking an exported linear memory from JS and C.

Strings

Manipulating JS strings in C.

Malloc

Implementing a simple toy dynamic memory allocation scheme.

Animation

Some canvas functions imported to WASM, shows bouncing particles.

WebGL

Wraps a portion of WebGL API for importing to WASM, draws a moving triangle.

Pong

Wraps a little more of WebGL API for importing to WASM, plays Pong.

About

WASM examples

https://bzar.github.io/wasm-intro

License:MIT License


Languages

Language:C 59.4%Language:HTML 38.2%Language:Makefile 2.3%