
Clojure-flavored WASM text format - tosh
https://github.com/roman01la/clj-wasm
======
roman01la
Author here. The library is a toy project, it's far from being complete. Many
things including macros are missing. Implementation style is derived from
ClojureScript's compiler

~~~
microcolonel
It may be a toy, but I've been looking at doing very similar things at work.
We have an optimizing compiler for spreadsheets, and many of the better
optimizations are implemented as clojure syntax transforms (since Clojure was
our first working target), so lowering that representation rather than
selecting another is an attractive option, especially when compared to (for
example) generating LLVM IR or code for some high level language.

~~~
6Typos
Going offtopic, but...

>We have an optimizing compiler for spreadsheets

What is even a compiler for spreadsheets? In spreadsheets you still have an
AST, or is it a different structure? Is there any fundamental property of
spreadsheet code that enables specific optimizations?

~~~
microcolonel
It's more that it _necessitates_ certain optimizations, rather than _enabling_
them.

You need to figure out how and when to merge expressions, when it's worth it
to extract a loop where the same expression needs to be compiled as two or
three variants, because there are invariants between all but two or three of
the invocations. You also must decide which collections you want to create out
of the reference soup, when you can alias/discard collections and values, how
to hoist predicates (for IF and SWITCH), when you can avoid type coercion. For
small workbooks, just using tagged unions in a 2D array, plus a string pool,
will suffice, but our sheets are so big that we can't afford that.

------
arijun
I don't understand what this is, the readme is very sparse. Is it a compiler
of Clojure targeting WASM?

~~~
fulafel
Lets you emit text format of WASM from a Clojure style variation of the WASM
sexp syntax. So no, it's not compiling Clojure.

~~~
77544cec
It's a transpiler then, if my terminology is correct.

~~~
capableweb
It's a transpiler/compiler, yes.

But it's not a Clojure->WASM transpiler/compiler, but Clojure-like->WASM
transpiler/compiler, as only a subset of Clojure has been implemented and it's
not compiling the standard library of Clojure into WASM.

------
capableweb
This is lovely, was just looking for something like this the other day. Gonna
see if I can get this nicely integrated into a ClojureScript project and make
the transition when writing code between js/wasm seamless. Thanks roman01la!

~~~
reitzensteinm
Is there any lightweight library to turn the wasm text format in to binary in
the browser? I've seen emscripten compiled versions of the desktop compilers
but nothing else.

~~~
capableweb
wat2wasm can do that (part of
[https://github.com/webassembly/wabt](https://github.com/webassembly/wabt)).
Since it's C++, I guess you could compile to it (wat2wasm) to webassembly to
run in the browser as a library, and if it's works, no need for separate
web/desktop version.

You might be able to find something more lightweight over here though:
[https://github.com/xtuc/webassemblyjs](https://github.com/xtuc/webassemblyjs)
but I didn't find what you were looking for (but just did a quick look)

------
sitkack
Schism – A self-hosting Scheme to WebAssembly compiler
[https://news.ycombinator.com/item?id=16488605](https://news.ycombinator.com/item?id=16488605)

------
fithisux
Such a beauty.

------
fulafel
The implementation looks edicational too.

Would it be hard to add macros?

~~~
jaccarmac
Glancing over the implementation it looks like you would have to add list
manipulation ops to get macros to work, since there's no quote. So, not hard,
but not trivial.

~~~
roman01la
Shouldn't be too hard, implementation is derived from ClojureScript's
analyzer. I'll probably add macros at some point.

