Back

Notes on elixir compilation

Elixir is not a self-hosted language. The compiler is implemented in erlang. It is organized into various modules in lib/elixir/src.

The elixir and elixirc commands are shell scripts that run the erl command, giving it the compiled elixir erlang module, and executing its start_cli function.

Because the elixir compiler is written in erlang, bootstraping is straightforward. The makefile:

  1. Compiles the elixir compiler written in erlang into erlang bytecode.
  2. Starts the now-compiled elixir compiler application, and uses it to compile the standard library that is written in Elixir

Put simply, the elixir compiler is erlang code that recognizes elixir syntax, and transforms it into the erlang Abstract Format. Don't let the name scare you though, this "Abstract Format" is very concrete and is essentially erlang data-structures representing the AST of erlang code.

The elixir compiler then feeds this Abstract Format into the erlang compile module.

I think it's pretty neat that erlang exposes a function to compile erlang AST into bytecode that can run on the erlang VM. This is probably a big reason why the elixir compiler can be maintained by a single person.