News for hackers. Stuff that matters.
Re:Understanding every byte in a WASM module by danielvaughn on Saturday December 23, 2023 @10:45AM (#38745040)
A while back I ran through some exercises that had me writing WAT directly. It's a great way to understand what WASM is doing, and is surprisingly easy to pick up (though of course you wouldn't want to write an actual program with it). It's just system calls with s-expressions.
Re:Understanding every byte in a WASM module by eliben on Saturday December 23, 2023 @11:43AM (#38745521)
WAT is a fun format! I'm curating some readable samples here -- https://github.com/eliben/wasm-wat-samples/
Re:Understanding every byte in a WASM module by xscott on Saturday December 23, 2023 @12:23PM (#38745962)
I already had that bookmarked from using it several months ago to try and figure things out. It's been very helpful. Thank you for creating it!
Re:Understanding every byte in a WASM module by danielvaughn on Saturday December 23, 2023 @12:11PM (#38745833)
Bookmarking that for later, thanks for sharing!
Re:Understanding every byte in a WASM module by Jasper_ on Saturday December 23, 2023 @12:37PM (#38746121)
I have a hand-written BF interpreter in WAT, along with hand-written asm.js for comparison, over here https://github.com/magcius/bfasm
Re:Understanding every byte in a WASM module by lioeters on Saturday December 23, 2023 @11:45AM (#38745547)
For some time I've been fascinated by the codebase of a small WAT compiler written in JavaScript.

https://github.com/stagas/wat-compiler/blob/main/story.txt

And I mean "small" as a real complement to how readable and compact the entire compiler is. It's been a great way to appreciate the design of the WASM text format and WASM overall. It's not a Lisp but has a similar feel to it.

I've been meaning to get more fluent at writing WAT directly, not for any practical purpose but just for pleasure of it. I could see myself gradually building up some abstractions to help me deveolp larger programs, perhaps a slightly higher-level language.

Re:Understanding every byte in a WASM module by danielvaughn on Saturday December 23, 2023 @11:50AM (#38745606)
Very cool. You might be interested in AssemblyScript, if you haven't heard of them before. They did something very similar: https://www.assemblyscript.org/
Re:Understanding every byte in a WASM module by lioeters on Saturday December 23, 2023 @11:55AM (#38745657)
Ah yes, I'd love to get more familiar with AssemblyScript too. One thing I like about the afore-mentioned WAT compiler though, is that it's simple to run in the browser, which the AssemblyScript compiler doesn't support, if I understand correctly. That characteristic of the compiler would be useful if I want to build a higher-level language on top of it, for example with a web playground (code editor and runtime).
Re:Understanding every byte in a WASM module by circuit10 on Monday December 25, 2023 @01:50AM (#38760422)
The AssemblyScript compiler runs in a browser too, that’s how the demo on the homepage works
Re:Understanding every byte in a WASM module by lioeters on Monday December 25, 2023 @01:41PM (#38764924)
Thanks for mentioning it, I dug into the website of AssemblyScript and found that the compiler does indeed run in the browser. The demo loads a web-build like:

  <script src="https://cdn.jsdelivr.net/npm/assemblyscript@latest/dist/web.js"></script>
  <script type="module">
  
  import asc from "assemblyscript/asc";
And how they compile AssemblyScript to WAT/WASM/JS:

https://github.com/AssemblyScript/website/blob/main/src/.vue...

Here's how the compiler is built to target the web.

https://github.com/AssemblyScript/assemblyscript/blob/main/s...

How fun! This inspires me to explore further what I could build with it.