views:

166

answers:

4

I am interested in delving into Erlang's C source code and try to understand (at least at a moderate level) what is going on under the hood. Where can I find info on the design and structure of the code?

+4  A: 

A Guide To The Erlang Source
http://www.trapexit.org/A_Guide_To_The_Erlang_Source

Robert Harvey
Thanks. Good place for me to start. This is really really short guide though..
bugspy.net
+4  A: 

First of all, you might want to have a look to Joe Armstrong's thesis, introducing Erlang at a high level. It will be useful to get an idea of what was the idea behind the language. Then, you could focus on the Erlang Run Time System (erts). The erlang.erl module could be a good start. Then, I would focus on the applications who constitutes the so-called minimal release, kernel and stdlib. Within the stdlib, have a look on how behaviours are implemented. May I suggest the gen_server.erl module as a start?

Roberto Aloi
This thesis is a fascinating reading. Thanks for this
bugspy.net
+1  A: 

The short answer is that there is no good guide. And the code is not very well documented.

I recommend finding someone in your neighbourhood that knows the code reasonably well, and buy them dinner in exchange for a little chat.

If you don't have the possibility to do that, then I recommend starting with the loader.

./erts/emulator/beam/beam_load.c

Some useful information can also be found by pretty printing the beam representation. I don't know whether there is any way to do so supplied by OTP, but the HiPE project has some cheats.

hipe:c(MODULE, [pp_beam]).

Should get you started.

(And I also recommend Joe's book.)

Daniel Luna
+1  A: 

Pretty printer of beam can be done by 'erlc -S', which is equivalent with hipe:c(M, [pp_beam]) mentioned by Daniel.

I also use erts_debug:df(Module). to disassemble the loaded beam code, which is instructions actually been interpreted by the VM.

Sometimes I use a debugger. OTP delivers tools supporting gdb very well. See example usage at http://www.erlang.org/pipermail/erlang-questions/2008-September/037792.html

lht