Portable assembler on the night train to Cologne
I was on the last night train from Gotenberg to Cologne, in a couchette with six seats and six fold down beds.
There were three of us and we had one of those conversations where you feel you solved all the worlds problems
in the evening and can't remember any details in the morning.
One of the guys worked at a language lab and had his own personal programming language for rule based reasoning
written in C. Much to my surprise he had compiled his C into Javascript.
The conventional way of things is to you wrote an dynamically typed language like Javascript in C,
then you compiled C in assembler language and then assembler into a machine language, using Javascript as the machine language.
I believe he was using clang a C compiler that generates LLVM.
Traditionally, an assembler language was a "simple" language specific to a particular typeof microprocessor hardware.
Typically an assember maps one to one to a special "binary instruction" format held in memory that hardware can execute directly.
LLVM looks mostly like an assembler language is not tied to any hardware, a portable assembler language.
One can compile C, C++, Rust, Go and so on the LLVM but then you need another translator to convert the LLVM to the underlying hardware assembler language.
However, someone wrote a translator from LLVM to Javascript.
Now this is very convenient as it means one can run traditional programs in a web browser.
C, C++ and Rust are very much designed to be "fast" languages, that is they are designed to map straight to the hardware assembler language
without loss of efficiency. Languages like LISP, Python, Jasvscript and so on are more designed to make efficient use of a programmers time,
and one can typically knock out (smallish) programs much more quickly than in C and so on.
Having said that,
I have the impression an awful lot of work has been put into optimizing Javascript in the browser so it can be surprisingly.
Nonetheless, Javascript is not an ideal assembler language, it was never designed to map directly to hardware.
So Web assember is a binary instruction format that runs in various browsers
and has an associated assembler language.
So one can write programs in C, C++, Rust and Go and run them in a web browser rather than having to write everything in Javasscript.
It is not just a case of efficiency, the lack of strong type checking means that you don't find out about errors until run time
whereas the others won't even compile, lt alone run until you have sorted out these issues.
My experience with Rust is that once you do manage to get it to compile, it's pretty much correct.
Portable assembler languages are hardly new, the JVM has been around since the 1990's
and was integrated with the browser as Java Applets and Java Web Start, though there never seemed to catch on.
JVM is kind of optimized for Java, whereas WASM is designed more for other langauges (C, C++, Rust and so on).
Also, WebAssembly is designed for streaming compilation, so it is compiled and run as a page download.