1. 11

Just a little mad science project I’ve been tinkering with.

  1. 2

    I’m very happy more experiments are trying to bridge the chasm between different programming languages and the web but I’m curious about the duct tape between webassembly and JS that is required to get interactions. Is there a reference implementation for exposing the DOM to webassembly that we can reuse from many languages or everything is custom made?

    1. 2

      My current proof of concept returns JSON to JS land, which is then applied to the dom via snabbdom.

      I’m quite interested in seeing if I can make use of asm-dom to minimize the need for JS glue code.

      I think in much the same as way as Mozilla recently attempted to standardize a syscall interface for Wasm (WASI), the web would benefit a lot from having a standardized interface for React style components that are written in WebAssembly.

      I think this will be no mean feat however, as it requires exposing effectively all the browser APIs in a way that makes sense across languages.

      This problem is pretty much why I’ve started looking into this, as I think that if we nail down what a reasonable standard might look like, we can drastically accelerate the uptake of components written in different languages.

    2. 1

      Translating compiled languages like Rust into WASM makes sense to me, because you just need to generate a different output. But I don’t understand at all how a dynamic, VM-based language could possibly be ported to WASM. Are you directly translating the iseq?

      1. 5

        I’m using mruby, which is a lightweight Ruby implementation targeted at embedded usecases. mruby comes with a compiler that can turn a Ruby program into an intermediate bytecode representation, and there’s a C API that allows you to then interpret that bytecode.

        So this project does require you to compile the mruby interpreter and your application bytecode to Wasm, which isn’t ideal compared to a language like Rust, but a naive take produces a 500kb bundle, which isn’t too bad.

        With emscripten optimisations turned all the way up, gzipped assets and caching of the interpreter, it should actually be quite viable.

        1. 1

          Interesting. I had completely forgotten about mruby! Thanks for the clarification.