Hacker News new | ask | show | jobs
by hkgumbs 2199 days ago
A few years ago, I tried to use Core Erlang as a compiler backend. It's fairly straightforward to learn even without thorough documentation. I wrote a bit about my process to try to help the next person [0]. For my particular project, I ended up abbandoning the approach and generating BEAM bytecode instead [1]. That was definitely more challenging, but it was neat to see Erlang's commitment to backwards compatibility in action. I believe that BEAM modules emitted by the first versions of Erlang are still valid on modern implementations. New functions are added and old ones are deprecated, but the actual file format version indicator hasn't changed.

[0]: https://8thlight.com/blog/kofi-gumbs/2017/05/02/core-erlang....

[1]: https://github.com/hkgumbs/codec-beam

2 comments

Neat! But please bear in mind that BEAM VM trusts the bytecode, so if your compiler emits buggy bytecode, it can crash the entire VM.
Nice. I added your codec-beam project to my Erlang resources gist: https://gist.github.com/macintux/6349828