Live data from Hacker News

I Wrote a WebAssembly VM in C

irreducible.io

61–70 of 104 posts

Re: I Wrote a WebAssembly VM in C

#61

Here is a more controversial point: Are you interested in adding a preliminary tail-call instruction? The WASM spec people rejected it for being too "high-level". But the C committee also rejected proposals from Dennis Ritchie. My money is still on Ritchie. Rob Pike's money seems to be on Ritchie direction as well. Otherwise, why create Golang? Tail-calls are only high-level if calls are high-level.

The WebAssembly tail call proposal has been accepted, finished, and implemented for over two years now. https://github.com/WebAssembly/meetings/blob/main/main/2023/...

Re: I Wrote a WebAssembly VM in C

#62

Earlier quoted context omitted.

Well, if you want to just-in-time compile, then it seems like a compiler is one way to go. They are now in the size realm of Lisp and Smalltalk. Forth may lean towards the lighter side.

Lisp and Smalltalk are 266 MB? tcc is 100KB https://www.bellard.org/tcc/

TCC doesn't do much optimization in turn, while commercial implementations of Lisp and Smalltalk are surely much larger than that.

Re: I Wrote a WebAssembly VM in C

#63
post #2

This is great! The WebAssembly Core Specification is actually quite readable, although some of the language can be a bit intimidating if you're not used to reading programming language papers. If anyone is looking for a slightly more accessible way to learn WebAssembly, you might enjoy WebAssembly from the Ground Up: https://wasmgroundup.com (Disclaimer: I'm one of the authors)

I bought the early access of your book a while ago and completed the first few chapters which were available. I found it a fantastic resource, and I was keen to continue but other responsibilities have gotten in the way since. I recommend it!

Re: I Wrote a WebAssembly VM in C

#64
post #2

This is great! The WebAssembly Core Specification is actually quite readable, although some of the language can be a bit intimidating if you're not used to reading programming language papers. If anyone is looking for a slightly more accessible way to learn WebAssembly, you might enjoy WebAssembly from the Ground Up: https://wasmgroundup.com (Disclaimer: I'm one of the authors)

I bought the early access of your book a while ago and completed the first few chapters which were available. I found it a fantastic resource, and I was keen to continue but other responsibilities have gotten in the way since. I recommend it!

Glad to hear!

If you haven't looked at it in a while — we just published a draft of the final technical chapter, and are planning an official launch on March 4. So, might be a good time to dig back in :-)

Re: I Wrote a WebAssembly VM in C

#65
post #61

Here is a more controversial point: Are you interested in adding a preliminary tail-call instruction? The WASM spec people rejected it for being too "high-level". But the C committee also rejected proposals from Dennis Ritchie. My money is still on Ritchie. Rob Pike's money seems to be on Ritchie direction as well. Otherwise, why create Golang? Tail-calls are only high-level if calls are high-level.

The WebAssembly tail call proposal has been accepted, finished, and implemented for over two years now. https://github.com/WebAssembly/meetings/blob/main/main/2023/...

And WebKit finally shipped it recently! Love return_call and friends.

Re: I Wrote a WebAssembly VM in C

#67

Earlier quoted context omitted.

Well, if you want to just-in-time compile, then it seems like a compiler is one way to go. They are now in the size realm of Lisp and Smalltalk. Forth may lean towards the lighter side.

Lisp and Smalltalk are 266 MB? tcc is 100KB https://www.bellard.org/tcc/

Squeak Smalltalk is 53 MB on Windows (excluding sources). 48 MB of that is the image with UI framework and so on, but it's not immediately easy to say which library/ui parts are core.

Re: I Wrote a WebAssembly VM in C

#68
post #9

Earlier quoted context omitted.

A JIT should be able to translate most arithmetic and binary instructions to single-opcodes, however anything involving memory and functions calls needs safety checks that becomes multi-instruction. branches could mostly be direct _unless_ the runtime has any kind of metering (it should) to stop eternal loops (if it also wants to be crash-safe even if it's exploit safe).

> anything involving memory [..] needs safety checks that becomes multi-instruction Not necessarily; on AMD64 you can do memory accesses in a single instruction relatively easily by using the CPU's paging machinery for safety checks plus some clever use of address space. > branches could mostly be direct _unless_ the runtime has any kind of metering (it should) to stop eternal loops Even with metering the branches wo…

How do you avoid branches in 64-bit WASM?

Re: I Wrote a WebAssembly VM in C

#69
post #10

Earlier quoted context omitted.

> actually quite readable, although some of the language can be a bit intimidating if you're not used to reading programming language papers You're more generous than me, I think it's rubbish. Would have been easier to read if they had written it more like an ISA manual.

You can understand the WASM spec in your sleep if you’ve ever worked through a type-system paper from the last two decades (or a logic paper from even earlier I guess). Granted, not many people have, but there’s a reason why it makes sense for it to be written in that style: they want it to be very clear that the verification (typechecking, really) algorithm doesn’t have any holes, and for that it’s reasonable to spe…

> You can understand the WASM spec in your sleep if you’ve ever worked through a type-system paper from the last two decades

Is there a lot of crossover between those people and people who work with assemblers or code generation? There's even more crossover with those people and understanding how to read a minimal ISA document.

Re: I Wrote a WebAssembly VM in C

#70
post #10

Earlier quoted context omitted.

> actually quite readable, although some of the language can be a bit intimidating if you're not used to reading programming language papers You're more generous than me, I think it's rubbish. Would have been easier to read if they had written it more like an ISA manual.

This is an opportunity to learn. The way WebAssembly is defined is the standard way PL semantics are defined.

WebAssembly isn't a programming language, it's an ISA or a bytecode VM. They've defined it in a very over-engineered way, with different representations all the way through. It has created issues for people working on assemblers and code generation because it's hard to choose a good representation for compilers to generate. This all could have been avoided.
Post reply on HN