<?xml version="1.0" encoding="UTF-8"?>
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
    xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml"
    xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook"
    xmlns:scilab="http://www.scilab.org" xml:id="macr2tree" xml:lang="pt">
    <refnamediv>
        <refname>macr2tree</refname>
        <refpurpose>fornece o código interno de uma função Scilab compilada</refpurpose>
    </refnamediv>
    <refsynopsisdiv>
        <title>Seqüência de Chamamento</title>
        <synopsis>p = macr2tree(macro)</synopsis>
    </refsynopsisdiv>
    <refsection>
        <title>Parâmetros</title>
        <variablelist>
            <varlistentry>
                <term>macro</term>
                <listitem>
                    <para>handle of a Scilab macro (NOT its name as a string)</para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>p</term>
                <listitem>
                    <para>List of type <literal>program</literal> with the fields
                    <literal>p.name</literal>, <literal>p.nblines</literal>,
                    <literal>p.inputs</literal>, <literal>p.outputs</literal>, and
                    <literal>p.statements</literal>. The 3 last ones are nested lists
                    describing the internal code of the <literal>macro</literal>.
                    </para>
                </listitem>
            </varlistentry>
        </variablelist>
    </refsection>
    <refsection>
        <title>Descrição</title>
        <para>Esta primitiva converte uma função Scilab compilada
            <literal>function-name</literal> em uma árvore (tlistas imbricadas) que
            codifica a representação interna da função. Deve ser usada com
            <literal>tree2code()</literal>.
        </para>
    </refsection>
    <refsection>
        <title>Exemplos</title>
        <programlisting role="example"><![CDATA[
prog = macr2tree(log2);   // Note that the input is log2, not "log2"
typeof(prog)
fieldnames(prog)'
prog.name
deftxt = tree2code(prog, %T);
printf("%s\n", deftxt);
 ]]></programlisting>
    <screen><![CDATA[--> typeof(prog)
 ans  =
 program

--> fieldnames(prog)'
 ans  =
!name  outputs  inputs  statements  nblines  !

--> prog.name
 ans  =
 log2

--> deftxt = tree2code(prog, %T);

--> printf("%s\n", deftxt);
function [f,e] = log2(x)
  [lhs,rhs] = argn(0)
  if rhs&lt;>1 then
    msg = gettext("%s: Wrong number of input argument(s): %d expected.\n")
    error(msprintf(msg, "log2", 1))
  end
  if argn(1)==1 then
    f = log(x)/log(2)
  else
    [f,e] = frexp(x)
  end
endfunction
]]></screen>
    </refsection>
    <refsection role="see also">
        <title>Ver Também</title>
        <simplelist type="inline">
            <member>
                <link linkend="tree2code">tree2code</link>
            </member>
            <member>
                <link linkend="macrovar">macrovar</link>
            </member>
            <member>
                <link linkend="functions">functions</link>
            </member>
        </simplelist>
    </refsection>
</refentry>
