edoc for parse_trans_codegen

This commit is contained in:
Ulf Wiger 2010-07-02 06:39:05 -04:00
parent 59ee9e4f18
commit 0f2fc09ab2
2 changed files with 29 additions and 1 deletions

View File

@ -2,7 +2,7 @@
-compile({parse_transform, parse_trans_codegen}).
-export([f/1, g/2]).
-export([f/1, g/2, gen/2]).
f(Name) ->
@ -23,3 +23,6 @@ g(Name, V) ->
member({'$var',V}, L)
end).
gen(Name, X) ->
codegen:gen_function(Name, fun(L) -> lists:member({'$var',X}, L) end).

View File

@ -34,6 +34,31 @@
-export([parse_transform/2]).
%% @spec (Forms, Options) -> NewForms
%%
%% @doc
%% Searches for calls to `codegen:gen_function(Name, Fun)' and
%% substitutes the abstract code for a function with name `Name'
%% and the same behaviour as `Fun'.
%%
%% It is possible to do some limited expansion (importing a value
%% bound at compile-time), using the construct <code>{'$var', V}</code>, where
%% `V' is a bound variable in the scope of the call to `gen_function/2'.
%%
%% Example:
%% <pre>
%% gen(Name, X) ->
%% codegen:gen_function(Name, fun(L) -> lists:member({'$var',X}, L) end).
%% </pre>
%%
%% After transformation, calling `gen(contains_17, 17)' will yield the
%% abstract form corresponding to:
%% <pre>
%% contains_17(L) ->
%% lists:member(17, L).
%% </pre>
%% @end
%%
parse_transform(Forms, Options) ->
{NewForms, _} =
parse_trans:depth_first(fun xform_fun/4, [], Forms, Options),