A CoreImp AST for transpiling into dynamically typed languages

Hi. This is my first post.
Recently I tried remaking a CoreImp AST for dynamically typed languages (transpiling into Lua, Dart, JavaScript) just for my interest.

I think it will be eventually stale…, but now It’s new!
If you are interested, take a look and give it a try.

7 Likes

This is really, really cool. Thanks a lot!

I see that you are encoding Sum and Product using tagged records:

  • I can now experiment with zero cost JSON serialization easily.
  • It would be interesting to compare the performance against current instance based codegen on node and in browsers (I know that @garyb made some benchmarking in the past). And even try something like { tag: "Left", values: [ 8 ]} so we have constant shape and possibly fast (ICs) based access to the tag when doing pattern matching… or even { tag: 1, values: [ 8 ]} (so we have Smi in nodejs and chrome) if it is possible to do this.

If I find some time I’m going to check these… because it is now possible to do this kind of experiments using just PS :slight_smile:

3 Likes

I think Bucklescript uses records with tags too, so it’s probably not that bad. Unfortunately the test case I had was purescript-in-purescript back in the day, which is way out of date now. It was great for stress tests. It was there that I made the discovery that led to our most effective optimisation so far… erasing {} values. :smile:

The instance method PS uses currently is targeting the “hidden class” optimisation in v8. I’m not totally sure, but I think nowadays the hidden class optimisation works on arbitrary record values also.

4 Likes

Thanks! That will be helpful for the next thing.

1 Like

Thank you for the past I don’t know. Informative!

1 Like

@garyb Could you please tell me if benchmarking examples for purescript-in-purescript are somewhere public (I wasn’t able to find them after a quick look at the repo)? Maybe we can take some inspiration or clone them and provide simple, generic infrastructure for codegen benchmarks (aka “benchmark yourself”) in psimp.

1 Like

I tried this out with luatex, which I don’t really know at all, but it seems to work (Nix 20.03):

$ nix-shell -p lua nodejs yarn "texlive.combine { inherit (texlive) scheme-small luatex; }"
# Steps to generate Lua omitted

[nix-shell:~/workspace/psimp/lua/outlua]$ cp ../main.lua ./

[nix-shell:~/workspace/psimp/lua/outlua]$ luatex --lua=main.lua
odd
even
5040
This is LuaTeX, Version 1.10.0 (Web2C 2019/NixOS.org)
 restricted system commands enabled.
**^C