I am interested in delving into Erlang's C source code and try to understand what is going on under the hood. Where can I find info on the design and structure of the code?
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?
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.
A little late to the party here. If you just download the source from GitHub the internal documentation is really good. You have to generate some of it using make.
Get the documentation built and most of the relevant source is under /erts (Erlang Run Time System)
Edit: BEAM Wisdoms is also a really good guide but it may or may not be what you're after.
发布评论
评论(5)
首先,您可能想看看乔·阿姆斯特朗的论文,高层次地介绍了 Erlang。了解该语言背后的想法将很有用。然后,您可以关注 Erlang 运行时系统 (erts)。 erlang.erl 模块可能是一个好的开始。然后,我将重点关注构成所谓的最小版本、内核和stdlib的应用程序。在 stdlib 中,查看行为是如何实现的。我可以建议从 gen_server.erl 模块开始吗?
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?
Erlang 源代码指南
http://www.trapexit.org/A_Guide_To_The_Erlang_Source
A Guide To The Erlang Source
http://www.trapexit.org/A_Guide_To_The_Erlang_Source
简而言之,没有好的指南。而且代码没有很好的文档记录。
我建议在你的邻居中找到一个对代码相当了解的人,并请他们吃晚饭以换取一点闲聊。
如果您无法做到这一点,那么我建议从加载程序开始。
通过漂亮地打印光束表示也可以找到一些有用的信息。我不知道 OTP 是否提供了任何方法可以做到这一点,但 HiPE 项目有一些作弊。
应该让你开始。
(我还推荐乔的书。)
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.
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.
Should get you started.
(And I also recommend Joe's book.)
漂亮的beam打印机可以通过'erlc -S'来完成,相当于Daniel提到的hipe:c(M, [pp_beam])。
我还使用 erts_debug:df(Module). 来反汇编加载的梁代码,这些代码实际上是由虚拟机解释的指令。
有时我会使用调试器。 OTP 提供了很好地支持 gdb 的工具。请参阅示例用法 http://www.erlang.org/pipermail /erlang-questions/2008-September/037793.html
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 are 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/037793.html
这里的聚会有点晚了。如果您只是从 GitHub 下载源代码,则内部文档是真的很好。您必须使用
make
生成其中的一些内容。构建文档,大部分相关源位于
/erts
(Erlang 运行时系统)下编辑:BEAM Wisdoms 也是一个非常好的指南,但它可能是也可能不是您所追求的。
A little late to the party here. If you just download the source from GitHub the internal documentation is really good. You have to generate some of it using
make
.Get the documentation built and most of the relevant source is under
/erts
(Erlang Run Time System)Edit: BEAM Wisdoms is also a really good guide but it may or may not be what you're after.