26 ms·
Okay then define a subset of java opcodes supported and then modify the open source hotspot. Look I'm trying to implement a wasm backend into an existing langu
by iammisc 5y ago
Okay then define a subset of java opcodes supported and then modify the open source hotspot.
Look I'm trying to implement a wasm backend into an existing language right now and it could be a lot easier by either making wasm into a real architecture (with registers) or using an existing stack based vm isa.
- UncleEntity 5y agoCouldn’t wasm be compiled down to either a stack or register based VM equally well? The text version is basically an ast (with the binary form being a desugared version of that) so you could do whatever you want to transform into something executable.
- iammisc 5y agoNo. WASM is fundamentally a stack machine. That's how its semantics are defined.
- sitkack 5y agoIt is a mechanical transformation from stack to registers. In other parts of the thread you mentioned TCO, one can also convert recursion into iteration, tail calls can be handled by the compiler or with a trampoline. The universe is much more flexible than you give it credit for.
- iammisc 5y agoRecursion can be converted to iteration very easily but then you lose all benefits of web assembly (dynamic linking, for example(. The conversion from recursion to iteration mandates that all recursive entry points be known ahead of time so you can build a loop/conditional tree. If you want to dynamically load code, this creates two tiers of languages on the runtime. You really think I haven't thought of this?
- infogulch 5y agoWA can be transformed into native machine code in linear time, directly executed at (near) native speed, while retaining the VM memory protection barrier. No other VM can come close in these three properties at once. If you're trying to integrate WA into a host language the easiest, fastest, and safest way would be to pick up one of the established well-polished compilers or interpreters and calling into it with a standard FFI interface.
- iammisc 5y agoFirstly... Any stock vm isa can be linearly compiled if you give up certain optimization. For example, if wa wanted to use a coloring allocator it wouldn't be linear time anymore. That's not a fundamental part of it, just an implenebtation choice.
- infogulch 5y agoFirefox's WA backend does streaming compilation (i.e. compiling bytecode directly to machine code while it's still coming off the wire) for Tier 1, right now, by default, today. Afaik, WA is the first mainstream vm isa that it's even possible to do this. Do you know of any other VM that can compile its bytecode in one pass that is on by default? I'm genuinely interested. https://wingolog.org/archives/2020/03/25/firefoxs-low-latency-webassembly-compiler https://wingolog.org/archives/2020/03/25/firefoxs-low-latenc... But this whole discussion is out of scope for your use-case. If it's For Fun (tm) that's one thing, but (presumably) this is a practical integration into an existing language. Why are you implementing a VM instead of integrating an existing implementation? Certainly you wouldn't even consider implementing a custom from-scratch implementation of the JVM, the fact that it's even possible to attempt such a thing for WA is already telling about which VM has a better design. Take your pick: https://github.com/appcypher/awesome-wasm-runtimes https://github.com/appcypher/awesome-wasm-runtimes
- iammisc 5y agoFor some reason, it seems like you didn't read my comments. I'm not writing a WASM interpreter or JIT compiler... that would be quite straightforward. I'm attempting to implement a compiler backend for an existing programming language so that it can target WebAssembly. Since this is a functional language, it doesn't do things like have 'structured conditionals' (i.e., prodecural-like If/For/While statements and loops). Instead, it has recursion, which WebAssembly is terrible at. Not that other VMs are much better. You can make a claim this is about performance, but not in good faith. JMP is one instruction on X86_64 and B and friends on ARM are similar. All these VMs and runtimes want to force you into particular ways of thinking about programming. This is terrible for the community. You can say Web Assembly is meant to be an open standard and you can sing that till the cows come home, but leaving out basic support for things like TCO, direct jumps, etc that are vital for compiling any non-procedural language, is just inexcusable at this point.