3 ms·
Wait what? WASM is a vm and JS is a language. Are you asking about the pro and con of a transpiler over a vm solution? For one thing BEAM is the Erlang VM wh
by anthony_doan 7y ago
Wait what?
WASM is a vm and JS is a language.
Are you asking about the pro and con of a transpiler over a vm solution?
For one thing BEAM is the Erlang VM which Elixir and many other languages run on. Why would anybody want to implement it in Javascript? BEAM does a lot of crazy things, including a preemptive scheduler. Also BEAM GC isn't some generic GC, there's tons of crazy work going on with it to work with the Actor concurrency model.
- pron 7y ago> WASM is a vm and JS is a language. I'm talking about compiling to WASM vs. compiling to JS. Calling something a VM or a language is mostly a matter of convention. x86 machine code can also be viewed as a language, and compilers certainly don't care. A compiler translates code in one language into code in another (there is no precise definition for "transpile", which is why compiler people hate that word; colloquially "transpile" just means that the compilation's target language is considered to be at a similar abstraction level to the source). > Why would anybody want to implement it in Javascript? Why would anybody want to implement it in WASM? If it's so that it could run in the browser, then compiling BEAM bytecode to JS would achieve the same goal, be easier to write and would likely result in a smaller and faster deliverable. > Also BEAM GC isn't some generic GC, there's tons of crazy work going on with it to work with the Actor concurrency model. There's nothing crazy going on in BEAM. As far as VMs go, it's near the bottom in terms of sophistication.
- ohyes 7y agoExactly true! C, for example is a VM!
- toast0 7y ago> Also BEAM GC isn't some generic GC, there's tons of crazy work going on with it to work with the Actor concurrency model. BEAM GC isn't very crazy, it (like a lot of other parts of BEAM) is delightfully simple. Each process gets it's own stack and heap, and because if immutability, any references are always to older things, so BEAM GC is based on copy collectors: copy everything that's reachable from the current stack frame, then copy and adjust the references; when you're done throw away the old heap/stack. It's a smidge more complicated because BEAM uses two generations for the collection, and has reference counted binaries that are shared among all processes and require cleanup; but all of that is pretty straightforward too. Because of the language design, there's no need for advanced GC like in other languages; but if you transpiled to other languages, their GC would work fine.