erlang的abstract code

erlang的abstract code是编译的中间代码,很多工具如 erl_pp lint什么的都是根据这个做调整的。还有进一步的parse_transform也是基于它的。 所以,了解它非常重要。 erts user guide里面详细了描述了它的定义。我这里展示的是如何获取到某个模块的abstract code 以便进一步研究:

# erl -s hello
Erlang R13B02 (erts-5.7.3) [source] [64-bit] [smp:2:2] [rq:2] [async-threads:0] [hipe] [kernel-poll:false]

hello world
Eshell V5.7.3 (abort with ^G)
1>
BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
(v)ersion (k)ill (D)b-tables (d)istribution
# cat hello.erl
-module(hello).
-export([start/0]).

start()->
io:format("hello world~n",[]).
# erlc +debug_info hello.erl
# erl
Erlang R13B02 (erts-5.7.3) [source] [64-bit] [smp:2:2] [rq:2] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.7.3 (abort with ^G)
1> rp(beam_lib:chunks(hello, [abstract_code])).
{ok,{hello,[{abstract_code,{raw_abstract_v1,[{attribute,1,
file,
{"./hello.erl",1}},
{attribute,1,module,hello},
{attribute,2,export,[{start,0}]},
{function,4,start,0,
[{clause,4,[],[],
[{call,5,
{remote,5,{atom,5,io},{atom,5,format}},
[{string,5,"hello world~n"},{nil,5}]}]}]},
{eof,6}]}}]}}
ok
2>

对着文档开始好好分析吧。 Have fun!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值