Blocking operations in the WASM version (JavaScript expertise needed)

Nobody is blaming Guillermo (at least I’m not). As I see it, the history is roughly this:

  • CiaoWASM was apparently started 6 years ago.
  • @rla started a WASM port of SWI-Prolog in 2018. I assume he had no knowledge about CiaoWASM. The project stalled for various reasons, immaturity of Emscripten surely being one of them. Still, it ran and @rla produced a little demo that is the basis of the current shell at https://dev.swi-prolorg.org/wasm.
  • @dmchurch got interested in this a couple of years ago, considering to use it as a replacement for the server side for SWISH. That work improved the build process, but again stalled for similar reasons.
  • @josderoo started using the WASM version for EYE. As he started complaining each time the build broke the build process has become a bit more mature. Still, it allows running SWI-Prolog on node.js which is not very useful. There is no good interface to call Prolog from JavaScript, none at all to call the other way and no browser integration.

That was up to some days ago. Inspired by the Ciao Playground I took a second look at the status to check how hard it would be to turn it into something good enough to show its potential. I integrated @rla’s initial Prolog shell code with the current (modularized) WASM build and extended it minimally to the current demo.

If you want to get anywhere you need to handle asynchronous behavior, so I used Google Scolar to find the thesis by Guillermo which claims using web workers. That looks like an option, but so is the ability to yield from the VM. Yield got to SWI-Prolog through @ptarau’s engine design while I worked with @ptarau at Kyndi. @matthijs asked for a foreign language API for this to be used with Rust, so all the building blocks are there. I’m investigating the low-level plumbing required have a proper JavaScript interface to be used (primarily) in the browser.

I’m happy to have a discussion on exchanging code and ideas between our projects. I think a telco is a better medium for that than here. Just drop me a personal message. I don’t think that should be too hard to resolve as our aims are quite complementary (I think).

3 Likes