Skip to content

hchiam/learning-wasm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 

Repository files navigation

Learning Web Assembly (WASM)

Just one of the things I'm learning. https://github.com/hchiam/learning

WASM basically enables writing web apps in languages other than JavaScript, with near native performance. Compilation target for performance.

WASM in 100 seconds: https://www.youtube.com/watch?v=cbB3QEwWMlA

Quick start: triple click the following to select all, and then run it in CLI:

git clone https://github.com/hchiam/learning-wasm.git && cd learning-wasm/assembly-script-example && npm i && npm run go

Run Wasm in localhost:

Very high-level summary: Wasm <-- can be built from AssemblyScript (which looks very much like TypeScript/JavaScript).

Conceptual code "flow": index.html <-- demo.js <-- build/optimized.wasm <-- (built from assembly/index.ts using asc).

Just run this one line of code in CLI: (triple click to select all)

git clone https://github.com/hchiam/learning-wasm.git && cd learning-wasm/assembly-script-example && yarn && yarn go

(You might need to refresh http://localhost:9080/. Don't forget to hit Ctrl+C in CLI to shutdown the server.)

If you don't have yarn, run this one-liner instead:

git clone https://github.com/hchiam/learning-wasm.git && cd learning-wasm/assembly-script-example && npm i && npm run go

Or starting from scratch:

mkdir example-assemblyscript
cd example-assemblyscript
npm init -y
yarn add @assemblyscript/loader
yarn --dev add assemblyscript static-server
npx asinit .
# add "start": "open http://localhost:9080; static-server" in package.json
# (edit /assembly/index.ts and in asconfig.json and then continue:)
touch demo.js index.html
# fill in demo.js and index.html with something like that in this repo sub-folder

and then from then on:

yarn asbuild
yarn start # open http://localhost:9080; static-server

More info on AssemblyScript --> Wasm:

(click to expand)

example.wasm (when you use a VS Code extension to convert from binary):

(module
  (type $t0 (func (param i32 i32) (result i32)))
  (func $_Z3addii (type $t0) (param $p0 i32) (param $p1 i32) (result i32)
    local.get $p1
    local.get $p0
    i32.add)
  (table $T0 0 funcref)
  (memory $memory 1)
  (export "memory" (memory 0))
  (export "_Z3addii" (func $_Z3addii)))

More links to general resources:

(click to expand)

About

Learning Web Assembly (WASM)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published