Skip to content

Instantly share code, notes, and snippets.

@nox
Created November 9, 2012 13:05
Show Gist options
  • Save nox/4045582 to your computer and use it in GitHub Desktop.
Save nox/4045582 to your computer and use it in GitHub Desktop.
EEP37 example
module 'fact' ['fact'/0,
'module_info'/0,
'module_info'/1]
attributes []
'fact'/0 =
%% Line 4
fun () ->
letrec
'Fact'/1 =
( fun (_cor2) ->
let <Fact> = 'Fact'/1
in case _cor2 of
<1> when 'true' ->
1
<N>
when call 'erlang':'>'
(_cor2,
1) ->
let <_cor0> =
call 'erlang':'-'
(N, 1)
in let <_cor1> =
apply Fact
(_cor0)
in call 'erlang':'*'
(N, _cor1)
( <_cor3> when 'true' ->
( primop 'match_fail'
({'function_clause',_cor3})
-| [{'function_name',{'Fact',1}}] )
-| ['compiler_generated'] )
end
-| [{'id',{0,0,'Fact'}}] )
in 'Fact'/1
'module_info'/0 =
fun () ->
call 'erlang':'get_module_info'
('fact')
'module_info'/1 =
fun (_cor0) ->
call 'erlang':'get_module_info'
('fact', _cor0)
end
-module(fact).
-compile(export_all).
fact() -> fun Fact(1) -> 1; Fact(N) when N > 1 -> N * Fact(N - 1) end.
module 'fact'
export ['fact'/0,
'module_info'/0,
'module_info'/1]
attributes []
fdef 'fact'/0() =
do
bif (internal 'make_fun'/4)('-fact/0-Fact/1-0-', 1, 0, 0) >> <_ker3>
then
<<_ker3>>
fdef 'module_info'/0() =
enter (remote 'erlang':'get_module_info'/1)('fact')
fdef 'module_info'/1(_cor0) =
enter (remote 'erlang':'get_module_info'/2)('fact', _cor0)
fdef '-fact/0-Fact/1-0-'/1(_cor2) =
do
bif (internal 'make_fun'/4)('-fact/0-Fact/1-0-', 1, 0, 0) >> <Fact>
then
match _cor2
alt
select _cor2
type k_int
1 ->
<<1>>
alt
when
try
test (remote 'erlang':'>'/2)(_cor2, 1)
of _ker0
_ker0
catch
'false'
end
->
do
bif (remote 'erlang':'-'/2)(_cor2, 1) >> <_cor0>
then
do
call (Fact)(_cor0) >> <_cor1>
then
do
bif (remote 'erlang':'*'/2)(_cor2, _cor1) >> <_ker2>
then
<<_ker2>>
do
[_cor2] >> <_ker1>
then
enter (remote 'erlang':'error'/2)('function_clause', _ker1)
end >> <>
end
{module, fact}. %% version = 0
{exports, [{fact,0},{module_info,0},{module_info,1}]}.
{attributes, []}.
{labels, 11}.
{function, fact, 0, 2}.
{label,1}.
{line,[{location,"fact.erl",4}]}.
{func_info,{atom,fact},{atom,fact},0}.
{label,2}.
{make_fun2,{f,8},0,0,0}.
return.
{function, module_info, 0, 4}.
{label,3}.
{line,[]}.
{func_info,{atom,fact},{atom,module_info},0}.
{label,4}.
{move,{atom,fact},{x,0}}.
{line,[]}.
{call_ext_only,1,{extfunc,erlang,get_module_info,1}}.
{function, module_info, 1, 6}.
{label,5}.
{line,[]}.
{func_info,{atom,fact},{atom,module_info},1}.
{label,6}.
{move,{x,0},{x,1}}.
{move,{atom,fact},{x,0}}.
{line,[]}.
{call_ext_only,2,{extfunc,erlang,get_module_info,2}}.
{function, '-fact/0-Fact/1-0-', 1, 8}.
{label,7}.
{line,[]}.
{func_info,{atom,fact},{atom,'-fact/0-Fact/1-0-'},1}.
{label,8}.
{allocate,1,1}.
{move,{x,0},{y,0}}.
{make_fun2,{f,8},0,0,0}.
{test,is_eq_exact,{f,9},[{y,0},{integer,1}]}.
{move,{integer,1},{x,0}}.
{deallocate,1}.
return.
{label,9}.
{test,is_lt,{f,10},[{integer,1},{y,0}]}.
{line,[{location,"fact.erl",4}]}.
{gc_bif,'-',{f,0},1,[{y,0},{integer,1}],{x,2}}.
{move,{x,0},{x,1}}.
{move,{x,2},{x,0}}.
{line,[{location,"fact.erl",4}]}.
{call_fun,1}.
{line,[{location,"fact.erl",4}]}.
{gc_bif,'*',{f,0},1,[{y,0},{x,0}],{x,0}}.
{deallocate,1}.
return.
{label,10}.
{test_heap,2,0}.
{put_list,{y,0},nil,{x,1}}.
{move,{atom,function_clause},{x,0}}.
{line,[{location,"fact.erl",4}]}.
{call_ext_last,2,{extfunc,erlang,error,2},1}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment