4 ms·
As someone who is not at all familiar with Shen, or transpiling in general...why not create a WASM compiler for Shen instead?
by tenaciousDaniel 6y ago
As someone who is not at all familiar with Shen, or transpiling in general...why not create a WASM compiler for Shen instead?
- uryga 6y ago[caveat emptor: my knowledge of WASM stuff is mostly based on blog posts and HN comments, and may be outdated. corrections welcome] in general transpiling to JS lets you reuse the JS runtime (if your language is similar enough), e.g. the garbage collector. also, DOM/window APIs, which are likely why you'd want your language to run in a browser. with WASM, you have to ship a runtime/interpreter for your language, often adding more than a few MB of overhead to any page using your wasm-compiled-language, and interop with the DOM and other browser stuff is (afaik) still in a pretty rough state. i think C# with Blazor managed to work around it, but it's tough
- eyelidlessness 6y ago> also, DOM/window APIs And Node/Deno APIs as well.
- aidenn0 6y agoI dunt know about Shen, but I looked into doing a wasm implementation of common lisp, and wasm is far too static. You can't, e.g. compile a single function to wasm and then call it from your already existing wasm. On top of that, its stack implementation makes it hard to do GC and any nonlocal transfers if control that aren't anticipated by its C++ support.
- sitkack 6y agoTrampolines can enable all you seek.
- aidenn0 6y agoCan you explain more? Trampolines can help with non-local returns, but at a significant cost to performance in the case where returns are all local. I don't see how they help with allowing you to arbitrarily (re)define functions, which is something that both Javascript and real world assembly languages allow just fine, but WASM struggles with.
- shortercode 6y agoIn an ideal world it probably would! WebAssembly only provides very minimal capabilities, anything more complicated than basic arithmetic and linear memory access require the features to be built. malloc, closures, arrays, error throwing, GC etc. all must be implemented. Some language features like console logs and visual output physically aren't possible, and must call out to the host ( normally JS ). Requiring the compiler to emit 2 languages. In comparison JS has analogues to many common language features, making it easy to transpile to. There are other advantages to JS as well, but probably not worth listing. It's complicated, and emitting JS is easier.