Skip to content

Instantly share code, notes, and snippets.

@0xYUANTI
Created November 30, 2012 15:57
Show Gist options
  • Save 0xYUANTI/4176609 to your computer and use it in GitHub Desktop.
Save 0xYUANTI/4176609 to your computer and use it in GitHub Desktop.
The reftrick: assembly
{function, recv, 1, 9}.
{label,8}.
{line,[{location,"reftrick.erl",33}]}.
{func_info,{atom,reftrick},{atom,recv},1}.
{label,9}.
{test,is_eq_exact,{f,10},[{x,0},{integer,0}]}.
{move,{atom,ok},{x,0}}.
return.
{label,10}.
{allocate_zero,1,1}.
{bif,self,{f,0},[],{x,1}}.
{move,{x,0},{y,0}}.
{move,{x,1},{x,0}}.
{move,{atom,bar},{x,1}}.
{line,[{location,"reftrick.erl",34}]}.
send.
{line,[{location,"reftrick.erl",35}]}.
{label,11}.
{loop_rec,{f,13},{x,0}}.
{test,is_eq_exact,{f,12},[{x,0},{atom,bar}]}.
remove_message.
{jump,{f,14}}.
{label,12}.
{loop_rec_end,{f,11}}.
{label,13}.
{wait,{f,11}}.
{label,14}.
{line,[{location,"reftrick.erl",36}]}.
{gc_bif,'-',{f,0},0,[{y,0},{integer,1}],{x,0}}.
{call_last,1,{f,9},1}.
{function, recv_ref, 1, 16}.
{label,15}.
{line,[{location,"reftrick.erl",38}]}.
{func_info,{atom,reftrick},{atom,recv_ref},1}.
{label,16}.
{test,is_eq_exact,{f,17},[{x,0},{integer,0}]}.
{move,{atom,ok},{x,0}}.
return.
{label,17}.
{allocate_zero,2,1}.
{move,{x,0},{y,1}}.
{line,[{location,"reftrick.erl",39}]}.
{recv_mark,{f,18}}.
{call_ext,0,{extfunc,erlang,make_ref,0}}.
{test_heap,3,1}.
{bif,self,{f,0},[],{x,1}}.
{move,{x,0},{y,0}}.
{put_tuple,2,{x,2}}.
{put,{y,0}}.
{put,{atom,bar}}.
{move,{x,1},{x,0}}.
{move,{x,2},{x,1}}.
{line,[{location,"reftrick.erl",40}]}.
send.
{line,[{location,"reftrick.erl",41}]}.
{recv_set,{f,18}}.
{label,18}.
{loop_rec,{f,20},{x,0}}.
{test,is_tuple,{f,19},[{x,0}]}.
{test,test_arity,{f,19},[{x,0},2]}.
{get_tuple_element,{x,0},0,{x,1}}.
{get_tuple_element,{x,0},1,{x,2}}.
{test,is_eq_exact,{f,19},[{x,2},{atom,bar}]}.
{test,is_eq_exact,{f,19},[{x,1},{y,0}]}.
remove_message.
{jump,{f,21}}.
{label,19}.
{loop_rec_end,{f,18}}.
{label,20}.
{wait,{f,18}}.
{label,21}.
{line,[{location,"reftrick.erl",42}]}.
{gc_bif,'-',{f,0},0,[{y,1},{integer,1}],{x,0}}.
{call_last,1,{f,16},2}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment