0

"-spec()" を渡すために Erlang Mixer ライブラリ ( https://github.com/opscode/mixer ) を拡張しようとしています。モジュールに追加する機能の行。しかし、erlc がコアの erlang コードに仕様をどのように配置するかについては不明です。

私は本当に単純な(テスト)モジュールから始めました:

-module(mix1).
-export([square/1]).
-spec(square(number()) -> number()).
square(X) -> X * X.

そして、「erlc +debug_info -S mix1.erl」でコンパイルし、これを取得しました(module_info関数は削除されました):

{module, mix1}.  %% version = 0

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

{attributes, []}.
{labels, 7}.
{function, square, 1, 2}.
  {label,1}.
    {line,[{location,"mix1.erl",7}]}.
    {func_info,{atom,mix1},{atom,square},1}.
  {label,2}.
    {line,[{location,"mix1.erl",8}]}.
    {gc_bif,'*',{f,0},1,[{x,0},{x,0}],{x,0}}.
    return.

「-spec()」がどのように変換されているかを理解しようとしていますが、そこに表示されません。アイデアはありますか? 何が欠けていますか。ここでの最終的な目標は、これを解析変換に使用することです。

4

1 に答える 1

1

あなたの出力は厳密には AST ではなく、正規化された形式の AST だと思います。

{ok, Forms} = epp:parse_file("mix1.erl",[],[]).
{ok,[{attribute,1,file,{"mix1.erl",1}},
     {attribute,1,module,mix1},
     {attribute,2,export,[{square,1}]},
     {attribute,3,spec,
                {{square,1},
                 [{type,3,'fun',
                        [{type,3,product,[{type,3,number,[]}]},
                         {type,3,number,[]}]}]}},
     {function,4,square,1,
               [{clause,4,
                        [{var,4,'X'}],
                        [],
                        [{op,4,'*',{var,4,'X'},{var,4,'X'}}]}]},
     {eof,6}]}
于 2013-10-30T08:07:47.810 に答える