[1]: https://news.ycombinator.com/submitted?id=gurjeet [2]: https://news.ycombinator.com/pool
Over the course of the book, we also build up a small library for creating Wasm modules and emitting bytecode; that's available as an NPM package (https://www.npmjs.com/package/@wasmgroundup/emit) and the code is here: https://github.com/wasmgroundup/emit
Beyond the sample chapters which are linked from the landing page, we also have a couple blog posts which may be interesting:
- A WebAssembly Interpreter: https://wasmgroundup.com/blog/wasm-vm-part-1/
- An older blog post, "A WebAssembly compiler that fits in a tweet" (https://wasmgroundup.com/blog/wasm-compiler-in-a-tweet), was also on HN earlier this year: https://news.ycombinator.com/item?id=42814948
Either way, I’ll likely buy a copy to support the hard work on a piece of tech that I am very fond of
I would 100% agree that the spec is quite readable. At the top of our Minimum Viable Compiler chapter, we say:
> The binary module format is defined in the WebAssembly Core Specification. You’ll notice that we back up many of our explanations with reference to the relevant part of the spec. One of our goals with this book is to convince you that the spec is a valuable resource that’s worth getting familiar with.
I think the spec is great as reference material, but we wrote the book to be more of a tutorial. We've talked to many people who say they've looked at the spec, but find it too overwhelming. For those people, we hope the book provides a good structure that ultimately helps them become comfortable with the spec!
Disclaimer: I'm one of the guys whose face is advertising this book, as someone who bought the early access version and loved it enough to help a bit with proofreading.
I'm a self-taught programmer who essentially started from the lowest level with Z80 assembly on the TI-83+. I just wanted to know how to fit the bytes together directly without dealing with the rest of the toolchain.
I've tried reading the spec multiple times and what it revealed to me is that my lack of formal training in the subject matter is really holding me back here. I feel like I can follow 90% of it, but that doesn't matter really. It's the remaining 10% I don't understand that does.
The spec is written as a reference and gives you all the pieces, but doesn't really do a great job at fitting all the pieces together.
Everyone I know who does have some relevant background to compiler writing agrees with you though. So I think that for them it's obvious how to fit the pieces together.
Speaking for myself though, this is the first book that made the bytecode "click" as a whole.
Having said that, I think this book and the spec together are the real combo to go for. The book covers the core, and understanding that foundation makes all the extensions easy to grasp from spec alone.
No, it doesn't — not this version of the book at least. We only cover WebAssembly 1.0.
That said, as my co-author says below, there's really not much to tail calls. Once you've worked through the book, you'd be able to grok tail calls pretty quickly.
As an aside — 2.0 was announced just a few weeks after we launched the book, and 3.0 a few months ago. And with 3.0 (which added tail calls), the spec has more than doubled in size vs 1.0, so it would be hard to cover everything.
We've talked about doing a new chapter to cover some of the interesting parts of 2.0 (e.g. SIMD), but covering everything in 3.0 (garbage collection, typed reference, exception handling, tail calls…) feels almost like an entire 2nd book!
if you are interested in tail calls you just need to understand the call instruction which we cover in the book and then replace it with either:
- return_call <funcidx>, the tail-call version of call
- return_call_indirect <tableidx> <typeidx>, the tail-call version of call_indirect
More info here: https://github.com/WebAssembly/tail-call/blob/main/proposals...
I can't help but notice that in the editor screenshots there's type information in *.js files.
I want to run something that execs a command line tool, both in the browser. Doable yet?
More specifically for command line tools:
wasi 1.0 feels like when it will take off after all these years of dev
timeline at the bottom of this page: https://wasi.dev/roadmap
If it's not possible from Javascript, it's also not possible from WASM, it's as easy as that.
If your command line tool can be compiled to WASM and works within the restrictions of the browser sandbox, it's trivial. But if you want to start a native command line tool from within the browser, it's pretty much impossible (and for good readons).
There's also a grey zone if you need it to work in a specific runtime environment. For instance VSCode extensions allow to run POSIX command line tools compiled to WASI, and those can safely access parts of the filesystem (like reading and writing files in the current project directory).
Right now the call is through an exec system call, but that can be changed.
https://github.com/floooh/vscode-kcide/blob/main/src/wasi.ts
...and this is how you run it:
https://github.com/floooh/vscode-kcide/blob/2dfc621aade4a2be...
The asmx.wasm file is a vanilla POSIX cmdline tool which loads and saves files via fopen/fread/frwrite/fclose, and the tool has been compiled with the WASI SDK: https://github.com/WebAssembly/wasi-sdk
The resulting VSCode extension (https://marketplace.visualstudio.com/items?itemName=floooh.v...) then even runs in the VSCode browser version (https://vscode.dev/)
But AFAIK there's currently no easy way to get a similar easy to use WASI wrapper in browsers (it's definitely possible though because the VSCode browser version does it - VSCode basically has a filesystem abstraction which works for native filesystems as well as virtualized web filesystems like github repositories).
It's experimental, but there is a toolchain that can compile most C/Posix programs and run them on the prototype implemented in the WAMR engine. And yes, exec works! In fact, we are able to run bash and Lua and memcached, among other things.
I'm in a process where application-level programming isn't cutting it anymore (I still have a lot to learn, but it's in the diminishing returns).
I've been looking to understand the entire stack at a deeper level (from how requests are made to how they're parsed), and this seems like the next natural step!
Thanks a bunch!
Let us know how it goes! You can find us in the book Discord, or email us at hello@wasmgroundup.com.
For whatever reason, Wasm loves OCaml. This wouldn't really be a bad thing if they didn't come up with their own custom language to denote syntactic elements of both formats instead of using EBNF or similar. I discussed this with them (because before this change they were using raw MathML for all the productions, and screen readers and MathML are... Erm... Hit and miss) and they noted that they needed an attribute grammar instead of just either BNF or an extension of it. So what they have now (SpecTec) is better than what they did have, and I like that I can now just open the raw grammar files and dive in. The problem is the way they chose to express it. And it could just be me, because ML languages (and functional languages in general) don't really come all that easy to me. (they're just... Really difficult for me to mentally follow, which is odd since I can follow most others just fine.)
Maybe there's an intersection between PL nerdery and interpreter authoring, and I fall into that bucket and am biased.
Their SpecTec system is fancy and neat but I don't think that auto-generated specifications produce something worth reading. Perhaps in the future when there's less churn, there might be a hand-written specification? In the mean time I've needed to jump into their Discord to ask clarification questions about the high-level stuff. Once understanding that and the grammar conventions and the like, the specification becomes much more readable, though still not great.
Certainly nothing like an RFC. But maybe I have too high standards...
Also because it uses Ohm.js to write the Parser/Lexer from a BNF definition, almost 100% of the focus is on WebAssembly and how to compile it, instead of flexing and parsing.
Go buy it.
Oddly enough, Zig is the nicest C to WebAssembly compiler I've used so far.
What the Zig toolchain provides that neither the wasi-sdk nor emsdk have is a package manager and build system which are both much nicer than what the c/c++ ecosystem offers.
Unless by high performance you mean something more specific.
With wasm-gc you get the GC "for free" (from the host), you can still write your own if you want but you loose the interoperability that wasm-gc solves.
chasil•2mo ago
I see runtime interpreters as constraining when a system call is needed, but proscribed.
haykuro•2mo ago
folkhack•2mo ago
moron4hire•2mo ago
vbezhenar•2mo ago
xpe•2mo ago
To be charitable, yes — PHP has access to low-level system details like the file system, sockets, and processes.
> I know a person who wrote Linux X Desktop Environment using PHP. Worked for them.
However: (a) "Worked for them" is an anecdote, not evidence of comparative suitability; (b) Don't confuse possibility with empirical fitness for purpose. Virtually all decisions are relative to alternatives [1]; (c) Even PHP describes itself as only a "general purpose scripting programming language" [2].
Note that "scripting language" itself can hide important differences. PHP 8 introduced JIT compilation [3] which helps.
[1] In negotiation terms, your BATNA (Best Alternative to a Negotiated Agreement). When evaluating technologies, don't forget the human cost, so consider your BATSHIT: Best Alternative To Shackling Humans In Tedium (or whatever expansion you prefer).
[2] https://www.php.net/
[3] https://upsun.com/blog/php-just-in-time-compiler/
boomskats•2mo ago
Lots of people _love_ PHP precisely because of the size of its attack surface.
Do you have any examples of something you've built in PHP which benefitted from direct syscall access?
dilawar•2mo ago