

Discover more from hrbrmstr's Daily Drop
We continue our periodic focus on WebAssembly (Wasm) today with a resource that will introduce tools for and also help you learn how to compile C, Rust, Go, and AssemblyScript into Wasm for use, well, anywhere! We'll then take a look at a project that aims to make my second favorite programming language a first-class Wasm citizen. Finally, we'll decompress, vintage style.
Wasm By Example
Previously, we introduced Wasm and looked at a resource that built a complete Wasm example. Today, we'll get some more practice (as the Peloton folks say, "practice makes progress") via Wasm By Example, a "concise, hands-on introduction to WebAssembly using code snippets and annotated WebAssembly example programs." (Note: if you need a Wasm refresher, this same site has a short one which should help you jump back into the fray).
If you like or know Go, Rust, C/C++, or strongly-typed versions of javascript (in this case TypeScript), then wading into the Wasm ecosystem will be somewhat straightforward to you. Wasm By Example has complete walk-throughs, so I'll just cover the basics from a C/C++ perspective.
To get going with Wasm/C, you'll need to become a bit familiar with emscripten. Emscripten is a complete Wasm toolchain based on LLVM that can compile C/C++ code (really, any other language that uses LLVM) into WebAssembly for any Wasm runtime; or compile the C/C++ runtimes of other languages (like Python — as seen in the previous Wasm newsletter — and even R, which we'll cover in a bit).
It is amazing to see what's been ported to Wasm via emscripten.
Wasm By Example shows how to install emscripten (it went super quick on my M1 MacBook Pro), then compile a simple "Hello, world!" example C program. The compilation process outputs HTML, javascript, and .wasm
files so you can run it in a browser:
from Node.js (which just emits "Hello, world!"); or, a wasm runtime. The browser and Node need the javascript glue code for things like input/output shims.
I highly suggest tossing the "hello.wasm
" up to wasm2wat so you can see what the Wasm instructions and program flow look like for this small example, then expanding upon the examples to see what you can build with Wasm.
webR
Python ain't the only game in town when it comes to a Wasm runtime thanks to the Herculean efforts of George Stagg (@tegglington), a Teaching and Research Technical Officer at Newcastle University.
George set about to do what I might have considered the impossible: port R's runtime to Wasm. He used specific versions of Emscripten, LLVM, gfortran and Dragonegg. The FORTRAN component is key, since you may not realize just how much R depends on that language. Thankfully some other chap descended into the madness that is getting gFortran to work in Wasm, which helped George accomplish his amazing feat.
Here's an example of loading up some data in an webR REPL:
Yes, your eyes do not deceive you, the REPL supports loading up data and plots right in the browser.
As shown, each package is loaded from a custom webR repository, where even much of the {tidyverse} is available!
Give the REPL a go, read through George's journey, build your own local webR via the provided Dockerfile, and see what you can do with these new supeRpowers.
Vintage Synths
Wasm is cutting edge technology, and while I 💙 keeping current, it is also nice to decompress with some vintage tech, especially when said tech involves music.
I've never played a synthesizer, but do enjoy the unique sounds produced by those instruments when in the hands of capable wielders.
When I came across the memetune programme [👈🏼 promo link] — a video series featuring in-depth discussions about the history and development of the synthesiser over the years, including demonstrations and feature guides of many classic and iconic instruments — I shut down all the other tabs, closed RStudio & VS Code, and took in all that the host, Zack Dagoba, had to drop in episode 1.
I'm looking forward to the other episodes in the series, both for the music and to learn more about how the synth tech came about and evolved.
FIN
It's May already! Or, as @year_progress puts it:
▓▓▓▓▓░░░░░░░░░░ 33%.
As Summer approaches (or, Winter, in lesser hemispheres), I hope folks have plans to slow down, get outside, and de-screen for a bit. ☮