lunatic-solutions / lunatic

Lunatic is an Erlang-inspired runtime for WebAssembly
https://lunatic.solutions
Apache License 2.0
4.57k stars 136 forks source link

Guide for compiler-developers #225

Open emil14 opened 7 months ago

emil14 commented 7 months ago

Hey there! First of all thank you much for this awesome project.

I create my own programming language and the only reason why I don't choose wasm as a compilation target is because it lacks green threads. I found your project because found out grain uses it to implement concurrency. But I struggle to understand what I have to do in order to support lunatic API in my language. Documentation looks extremely small (only one "installation" section!). All I have is source code for Rust, AssemblyScript and Grain gindings on github - all 3 languages that I haven't use in my entire life :)

Looks like the most common use case is to write one of these to compile them to wasm but my case is to create language from scratch that compiles to wasm. How can I leverage your platform? Thanks!

marceline-cramer commented 7 months ago

So, the Rust, AssemblyScript, and Grain bindings each work by using WebAssembly function imports that the Lunatic runtime provides to each WebAssembly module.

The signatures for all of those function imports can be found here: https://github.com/lunatic-solutions/lunatic-rs/blob/main/src/host/api.rs

These are in Rust, but these are low-level ABI definitions, wrapped in an extern "C" block, meaning that these function signatures are similar to the signatures of those WebAssembly host imports.

If you wanted to target Lunatic as a runtime in your language for starters, you'd need to import these same host functions and integrate them into a higher-level Lunatic API in your language.