我有兴趣深入研究 Erlang 的 C源代码,并尝试了解幕后发生的事情。我在哪里可以找到有关代码设计和结构的信息?
5 回答
首先,您可能想看看Joe Armstrong 的论文,从高层次介绍 Erlang。了解语言背后的想法是有用的。然后,您可以专注于 Erlang 运行时系统(erts)。erlang.erl模块可能是一个好的开始。然后,我将重点介绍构成所谓的最小版本、内核和标准库的应用程序。在标准库中,看看行为是如何实现的。我可以建议gen_server.erl模块作为开始吗?
简短的回答是没有好的指南。并且代码没有很好的记录。
我建议在你附近找一个相当了解代码的人,然后请他们吃饭以换取一点聊天。
如果您没有可能这样做,那么我建议从加载程序开始。
./erts/emulator/beam/beam_load.c
通过漂亮地打印光束表示也可以找到一些有用的信息。我不知道 OTP 是否提供了任何方法,但 HiPE 项目有一些作弊。
hipe:c(MODULE, [pp_beam]).
应该让你开始。
(我也推荐乔的书。)
漂亮的光束打印机可以通过 'erlc -S' 完成,相当于 Daniel 提到的 hipe:c(M, [pp_beam])。
我还erts_debug:df(Module).
用来反汇编加载的梁代码,这些代码实际上是由 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
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.