WebAssembly S-Expression and Cirru Syntax
WebAssembly will probably change the JavaScript ecosystem dramatically. By now Cirru is already capable of generating JavaScript with CirruScript, which brought me a lot of convenience. As WebAssembly arrives, it’s quite possible that we CoffeeScript developer stop writing code in which targets JavaScript, but write and compile to WebAssembly instead. That would be a huge change.
I hope there is still Cirru variants I can write in that day.
The nice thing I found was, WebAssembly actually with a text-based syntax in S-Expression, which looks very simple:
It first came with the extension name of “.wasm”, now I found it’s “.wast”, maybe it will change in the future. S-Expression is not bad, people like it for the intuitional layout. But also people make jokes on its trailing close parentheses, like “))))))”.
And here’s where Cirru Syntax comes. I found it looks much better writing in Cirru’s style:
Cirru represents a string of “even” with “:even” in case you did notice. It also makes the code shorter to write. Code written in Cirru is actually parsed into a JSON tree or arrays before further manipulations, and that’s why Cirru is always simple.
Now the problem is how to represent WebAssembly in bare JSON arrays, since JSON arrays are equal to Cirru code. It took my a while and at last I created my own library for that case:
Parsing S-Expressions is not hard. I tried to implement it in Parser Combinator’s method for fun, and it worked.
So now I can write in Cirru and generate WebAssembly with that, without writing lots of trailing parentheses! Hope you like it too.