Hacker News new | ask | show | jobs
by trgv 2904 days ago
I thought wasm was going to have a human-readable equivalent, called wast. See: https://webassembly.org/getting-started/advanced-tools/

My understanding (maybe wrong) was that this was going to be available in the browser.

2 comments

It's only human-readable like disassembling a binary into assembly code. https://webassembly.github.io/spec/core/text/index.html Whether you can make heads or tails of the code in that format depends on how friendly the compiler was that produced the binary.
I'm not an expert, but my understanding is that WASM has two formats: a text-based format called WAT, and a binary format called WASM.

In order to run the code in the browser, the code will have to be compiled to the binary format.

So where WAT comes in is your methods for producing WASM files now become one of the following:

Source in <otherlang> -> WAT -> WASM

Source in <otherlang> -> WASM

WAT -> WASM

So the human-readable WAT can either be used as a compile target for another language, which can easily be compiled into WASM, or you can write the WAT manually and compile it. Alternatively other languages might be able to compile directly to the binary format, skipping WAT representation entirely.

Generally, WAT is produced from the binary format. Compilers don't go through WAT; they produce the binary output directly.

The translation between WAT and the binary format is lossless, so there's no advantage of producing WAT as an intermediate step.

Since WAT -> WASM is already easy to do, compiling <otherlanguage> to WAT makes it really easy for people to create their own abstractions for writing WebAssembly in nearly _any_ other programming language, not just those that can compile directly to the binary format.
I don't understand why that would be true.

It's also just as easy to get WASM from WAT as it is WAT from WASM. I don't know of any languages that compile to WAT and then compile to WASM; as far as I know 100% of languages compile directly to WASM.