[erlang-questions] The inner workings of erlang:element/2

Adam Krupicka akrupicka@REDACTED
Fri Sep 11 11:21:52 CEST 2015


> -module(elt).
> -export([elt/1]).
> 
> elt(X) -> element(3, X).
> <EOF>
> % erlc +"'S'" elt.erl
> % cat elt.S
> <snip>
> {function, elt, 1, 2}.
>   {label,1}.
>     {line,[{location,"elt.erl",4}]}.
>     {func_info,{atom,elt},{atom,elt},1}.
>   {label,2}.
>     {line,[{location,"elt.erl",4}]}.
>     {bif,element,{f,0},[{integer,3},{x,0}],{x,0}}.
>     return.
> <snip>

I added a function that calls setelement/3 and the difference in the
generated assembler code is, indeed, apparent:

{function, selt, 1, 4}.
  {label,3}.
    {line,[{location,"elt.erl",5}]}.
    {func_info,{atom,elt},{atom,selt},1}.
  {label,4}.
    {move,{x,0},{x,1}}.
    {move,{atom,val},{x,2}}.
    {move,{integer,3},{x,0}}.
    {line,[{location,"elt.erl",5}]}.
    {call_ext_only,3,{extfunc,erlang,setelement,3}}.


A. K.



More information about the erlang-questions mailing list