Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-visit codegen from Erlang compiler files #48

Open
kofigumbs opened this issue Jul 6, 2018 · 0 comments
Open

Re-visit codegen from Erlang compiler files #48

kofigumbs opened this issue Jul 6, 2018 · 0 comments

Comments

@kofigumbs
Copy link
Owner

kofigumbs commented Jul 6, 2018

I think this would be a really fun project for anyone interested in BEAM internals. It would make this library more future-proof and eliminate sneaky bugs. I don't have time to do it myself though, so please continue the conversation if you'd want to help out!

The general idea

Codec.Beam.Instructions is a manually curated list of functions that mirrors the BEAM instruction set. However, this entire file could be generated from canonical files in the Erlang compiler. Specifically genop.tab and ops.tab. I think we can do this and maintain type safety, which would allow us to easily update the library with new OTP releases.

EDIT: This section of the documentation a most comprehensive overview of these tab files.

Prior attempt

I actually tried this before, but ran into issues. I backed out in this commit. Specifically, the ops.tab file was not complete — some type annotations were missing, so I could not complete the inference graph.

However, I met @jhogberg at CodeBeam STO, and they went through and added the missing type information. Apparently it will prevent bugs in the Erlang compiler too! Their work can be found on this branch.

Open questions

  • Ergonomics — currently, the library makes some concessions by standardizing on Source, Register, SourceF, and RegisterF. I think this makes things easy to remember, but I'm not 100% certain that it's truthful. I'm interested to know how often things don't fit into this model. Can we do comprehensive codegen without an explosion of types or classes (I would call my previous attempt "an explosion")?
  • How would we document these functions? I think most of the current documentation is iffy since it just mirrors The Beam Book. Perhaps we forego the attempt to add inline documentation?
  • Can we similarly improve Codec.Beam.Bifs by parsing bif.tab?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant