Rayscript: Erlang Abstract format to JavaScript

In my Lonestar Elixir presentation on Elixirscript I mentioned compiling from Beam files. About a 2 weeks ago, I started to play around with getting the Erlang Abstract Format from beam files. From there, I started thinking about turning that format into JavaScript. That project is rayscript

There are a couple of big advantages to doing so over Elixirscript’s implementation. The biggest one is that it could enable all languages on the Beam to convert code to JavaScript. Another is that compile time features, such as macros in Elixir, would not be a concern. Yet another would be that OTP should be easier to support as long as the beam files are available. I did some tests and was able to retrieve the format from beam files in both the Erlang and Elixir standard libs and convert to JavaScript. A question I get asked about a lot with Elixirscript are around processes. The problem isn’t that there is not an implementation for processes. One exists. The problem was one of integrating it within what already exists in Elixirscript. Starting from the beginning means that it will be a simpler task of adding it in.

The work done in Elixirscript helps a lot here. Most of what is there now is modified from Elixirscript. There are a few new problems. The biggest one being around how to handle NIFs. Also, an old one around JavaScript interoperability.

Long story short, if we can implement all of the forms there, we might be in business. I’m currently looking for any help on the project. Especially from anyone who can help with implementation, may have experience with other Beam languages, or who would be interested in helping with whatever underlying JavaScript that would be needed.

7 Likes

Looks fascinating!

Well NIF’s and Ports sound like great integration points between Rayscript and javascript at least. ^.^

If you are curious in Elixir AST -> Javascript compilation, there is an old project that did most of it at https://github.com/synrc/shen if you are curious about any code to swipe or so since that project is long-dead. :slight_smile:

Shen worked based on a parse_transform though, much different method.

2 Likes

Thanks! I’ve seen shen before, but I think I will look to see how they implemented tail recursion.

I started looking into the idea after looking more and more into bucklescript recently since I see that both Ocaml and Reason can both use it. I’ve been interested in OCaml for a while now for some things and started taking the dive into it.

2 Likes