dart-archive/wasm

Dart bindings via javascript transpilation/execution.

modulovalue opened this issue · 0 comments

I think it is safe to assume that all languages that have javascript as a compilation target will eventually support targeting wasm as a compilation target as well.

As part of the compilation pipeline of languages that target wasm today, it seems to be common to also generate bindings written in javascript to the generated wasm code (e.g. see Rust).

It would be very hard to convince all the languages that target wasm to also write bindings for Dart. What if we take the javascript that those compilation pipelines produce, and extract the wasm bindings out of them, and generate Dart bindings ourselves?

The open question here is whether this approach would be feasible. I can see the following levels of difficulty:

  • AST-based: Is it possible to extract enough information about the wasm bindings from the raw AST of javascript-based bindings?
  • Resolved-AST-based: Is it possible to extract enough information about the wasm bindings from the CST that had some simple transformations (such as name resolution) applied to it?
  • Type-flow-based: Is it possible to extract enough information about the wasm bindings from some resolved AST that had some types inferred using more complicated type flow based approaches?
  • Runtime-mirroring: Is it possible to extract enough information about the wasm bindings by simply executing the javascript bindings and using the prototype based nature of javascript and/or some other methods that allow reflection to extract enough information to generate Dart bindings?

I don't have enough insight into javascript to evaluate the Runtime-mirroring approach yet, but that would probably be the simplest.

To investigate this approach we should probably first collect some autogenerated javascript bindings and see if there's a common pattern there that we can make use of.