Skip to content

Commit 2c41580

Browse files
committed
Add rationale and flow docs
1 parent ec33bfc commit 2c41580

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ Shortcuts for wasm
2020

2121
## [Introduction](doc/intro.md)
2222

23+
## [Flow](doc/flow.md)
24+
25+
## [Rationale](doc/rationale.md)
26+
2327
## [Planning](doc/planning.md)
2428

2529
## Contributing & open source

doc/flow.txt

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
┌─────────────────┐
3+
┌──│ wah source │
4+
│ └─────────────────┘
5+
│ is parsed as
6+
│ ┌───────────────────────────────┐
7+
├──│edn (extensible data notation) │
8+
│ └───────────────────────────────┘
9+
│ by the
10+
│ ┌───────────────┐
11+
├──│ wah compiler │────────────┐
12+
│ └───────────────┘ │
13+
│ written in │
14+
│ ┌──────────┐ │
15+
├──│ clojure │ │
16+
│ └──────────┘ │
17+
│ which runs in the │
18+
│ ┌──────────────────────┐ │
19+
└─▶│ Java Virtual Machine │ │
20+
└──────────────────────┘ │
21+
22+
23+
generates │
24+
┌─────────────────────────┐ │
25+
┌──│ WebAssembly Text (WAST) │◀─┘
26+
│ └─────────────────────────┘
27+
│ is compiled by
28+
│ ┌─────────────────────────────┐
29+
├──│ wabt (wast2wasm) │
30+
│ └─────────────────────────────┘
31+
│ into
32+
│ ┌─────────────────────────────┐
33+
└─▶│ WebAssembly Binary (wasm) │──┐
34+
└─────────────────────────────┘ │
35+
36+
and links with │
37+
┌─────────────────────────────┐ │
38+
│ JavaScript │◀─┘
39+
└─────────────────────────────┘

doc/intro.md

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ and
3939
(%0 + %1)
4040
```
4141

42+
See [the rationale explanation](./rationale.md) for more details about why this
43+
might be useful and why I built it.
44+
4245
## The stack
4346

4447
The complete flow of using wah is:
@@ -48,6 +51,8 @@ The complete flow of using wah is:
4851
* Compile WAST to WASM using [wabt](https://github.com/webassembly/wabt)'s `wast2wasm`
4952
* Load and run in a browser using the instantiation code like:
5053

54+
See [the flow diagram](./flow.txt) for a graphical explanation.
55+
5156
```js
5257
fetch('./output.wasm').then(response =>
5358
response.arrayBuffer()

doc/rationale.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Why wah?
2+
3+
Well, WebAssembly text isn't _designed_ to be written from scratch, but it's
4+
still writable, and really isn't that bad. wah makes WebAssembly text just
5+
a little more humane, so that people with a need for extreme simplicity and
6+
low-level access can get it.
7+
8+
WebAssembly will definitely, primarily, be a compilation target for things
9+
like emscripten. But why not have some low-level mathematical code written in,
10+
and purely written in, WebAssembly?
11+
12+
# Why is the compiler implemented in Clojure?
13+
14+
Clojure _looks_ a lot like WebAssembly text format because they both use S-Expressions,
15+
but, obviously, WebAssembly text format is not a lisp and has very little else
16+
in common. The compiler is implemented in Clojure because of Clojure's excellent
17+
support for the [edn format](https://github.com/edn-format/edn), which fortunately
18+
is a superset of WebAssembly text syntax. Clojure is also a very nice, functional
19+
language with efficient and direct ways of expressing the kind of data-transformation
20+
logic required for wah.
21+
22+
# Could it be implemented in ClojureScript?
23+
24+
Sure! It might even already work in ClojureScript, I just haven't tried yet. PRs welcome!

0 commit comments

Comments
 (0)