1. 程式人生 > >系統技術非業餘研究 » erlang的abstract code

系統技術非業餘研究 » erlang的abstract code

erlang的abstract code是編譯的中間程式碼,很多工具如 erl_pp lint什麼的都是根據這個做調整的。還有進一步的parse_transform也是基於它的。 所以,瞭解它非常重要。 erts user guide裡面詳細了描述了它的定義。我這裡展示的是如何獲取到某個模組的abstract code 以便進一步研究:

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

hello world
[
[email protected]
~]# cat hello.erl
-module(hello).
-export([start/0]).

start()->
    io:format("hello world~n",[]).
[[email protected] ~]# erlc +debug_info hello.erl
[[email protected] ~]# erl
Erlang R13B02 (erts-5.7.3)  [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!

Post Footer automatically generated by wp-posturl plugin for wordpress.