Erlang bytecode

[url]http://mryufeng.iteye.com[/url]

yufeng在一篇文章中提到可以从erlang源码生成中间码,下来想想对理解VM的机制是大有帮助的,记一下,在此,对yufeng在Erlang方面的丰功伟绩表示感谢 :idea: 。


-module(tut1).
-export([fac/1]).

fac(0) -> 1;
fac(N) -> N * fac(N-1).


erlc +"'S'" tut1.erl


{module, tut1}. %% version = 0

{exports, [{fac,1},{module_info,0},{module_info,1}]}.

{attributes, []}.

{labels, 8}.


{function, fac, 1, 2}.
{label,1}.
{func_info,{atom,tut1},{atom,fac},1}.
{label,2}.
{test,is_eq_exact,{f,3},[{x,0},{integer,0}]}.
{move,{integer,1},{x,0}}.
return.
{label,3}.
{allocate_zero,1,1}.
{gc_bif,'-',{f,0},1,[{x,0},{integer,1}],{x,1}}.
{move,{x,0},{y,0}}.
{move,{x,1},{x,0}}.
{call,1,{f,2}}.
{gc_bif,'*',{f,0},1,[{y,0},{x,0}],{x,0}}.
{deallocate,1}.
return.


{function, module_info, 0, 5}.
{label,4}.
{func_info,{atom,tut1},{atom,module_info},0}.
{label,5}.
{move,{atom,tut1},{x,0}}.
{call_ext_only,1,{extfunc,erlang,get_module_info,1}}.


{function, module_info, 1, 7}.
{label,6}.
{func_info,{atom,tut1},{atom,module_info},1}.
{label,7}.
{move,{x,0},{x,1}}.
{move,{atom,tut1},{x,0}}.
{call_ext_only,2,{extfunc,erlang,get_module_info,2}}.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值