Unlike LLVM IR, which has a wildly different syntax from any other language, GCC's SSA IR was designed to look like a subset of C. There are some obvious benefits of doing it that way. Wasm can be even closer to a high level language because it has high level control flow...
WASM Text (WAT) is not really meant to be human-authored, it's an IR representation, like LLVM IR.
The one genuine use I could see out of this is the ability to go backwards, from WAT -> High-level language
> "Compilers usually run one way. The most interesting engineering in Wax is in the reverse arrow."It's not rust at all, it's a rust-like representation of wasm bytecode.
> WASM Text (WAT) is not really meant to be human-authored, it's an IR representation, like LLVM IR.
Which is exactly why TFA wrote an alternate representation, they're writing the runtime for a wasm target so they specifically want to craft their bytecode, and WAT is not a great thing to write.
I can't think of a single other production level VM with such an easy to read decompiled form.
Lisps are really handy, though, because it's basically textual representation of an AST. Code is data, data is code, and a tree walker with minimal lexing and parsing can interpret the thing through (eval ), compile it, or make transformations to the tree. There's not much hidden semantics in special syntax.
What I've been doing is making a simple library that can build WASM instructions in memory which closely follows the syntax and semantics, and using my programming language of choice as basically a preprocessor that provides high level abstractions over raw WAT/WASM. That method is VERY amenable to optimization, either by hand or via LLM. Because you can run your code generation, figure out how the bytecode should change, and work backwards. And if you take care while writing it, it can be very easy to follow the code.
The author claims it is so and wax can be converted back and forth with wat or wasm bytecode. Do you have evidence to the contrary?
> What I've been doing is making a simple library that can build WASM instructions in memory which closely follows the syntax and semantics, and using my programming language of choice as basically a preprocessor that provides high level abstractions over raw WAT/WASM.
That is a completely different purpose unrelated to the goals of wax.
What I mean is, you can't effectively steer a high level language to produce some exact sequence of bytecode. It's not "1:1" with what you end up with, it's the nature of the beast. To get that, you have to write in WAT or a higher level WAT generator that you CAN steer.
As a trivial example, `a = 1; a = a + 1` (note: I'm not using this exact language, just speaking in generalities). Will the compiler produce the naive bytecode:
```
(local $a i32)
i32.const 1
local.set $a
local.get $a
i32.const 1
i32.add
local.set $a
```
Or will it perform constant folding and give you:
```
(local $a i32)
i32.const 2
local.set $a
```
Maybe, maybe not. Who knows! Now that's a trivial example obviously, but there's plenty of places where there are optimizations you'd LIKE to happen but have no control over. Which no doubt WAX is susceptible to.
> That is a completely different purpose unrelated to the goals of wax.
But it's the only way to truly shape the end-result bytecode into EXACTLY what you want when starting from a higher level language.
Calling the external JavaScript Math functions adds an incredible amount of latency as far as I recall. Has that been fixed for Math functions in the mean time?
Having done a bit of staring-at-WASM while building a compiler, I never stopped being annoyed by the question of who came up with that terrible parentheses syntax. I could never see how it made any sense for any use-case.
Obviously the very top-level parser for the parenthesis stuff is simpler than a parser for a more complex syntax like Wax's. But that is a tiny part of the parser's job, and the savings are marginal. Just because you start by parsing the text into a simple node tree, you still have to check that tree against the implicit syntax that you're expecting it to conform to, and a lot of that checking could have been avoided by pushing it into the actual syntax of a nicer language. They already have a binary format, so the whole point of this text format is to be human-readable, which it absolutely isn't. So the compromise it makes to make the parser very slightly simpler just seems mad to me. Anyway, end of rant..
There’s a lot of people, myself included, who quite like s-expressions. And it’s not all that surprising that WAT is LISPy given JavaScript was originally intended to be a LISP too.
(func $add (export "add") (param $x i32) (param $y i32) (result i32)
(i32.add (local.get $x) (local.get $y)))
In clojure using native annotations, that would be along the lines of (defn add ^int [^int x ^int y]
(+ x y))The point is that while "WAT is just sexpr" it's not exactly a great lisp, or experience.
Isn't that basically just apocryphal handwaving? Javascript doesn't look like a lisp in any way, not syntactically obviously, but not behaviorally either. To say that he aimed for a lisp with C ish syntax either means he failed extremely bad, or that he thought lisp was shit.
- he was originally hired to "do scheme", management believed they needed to embed a programming language and he was sold / believed that was an option
- by the time he got moved to the client and could work on scripting, Netscape was trying to get Java in Navigator (for the browser components), and management mandated a java-ish language for frontend scripting
- Eich got first-class functions from Scheme, and Self prototypes as an implementation detail to get an object model, as well as java's Date API and the primitive/object split
I wonder if I could use wax to transpile back to zig, which is comparable to use friendliness of wax
It took a build system expert in that project to finally allow the build system to express the concept of compiling C++ to Bitcode which is then used by JIT.
Lua macroassembler for webassembly used to implement a Lua runtime. Now with microcode to synthesize interpreter eval & jit