mirror of
https://github.com/valitydev/parse_trans.git
synced 2024-11-06 08:35:17 +00:00
97 lines
4.5 KiB
HTML
97 lines
4.5 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<title>Module parse_trans_codegen</title>
|
|
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="EDoc">
|
|
</head>
|
|
<body bgcolor="white">
|
|
<div class="navbar"><a name="#navbar_top"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div>
|
|
<hr>
|
|
|
|
<h1>Module parse_trans_codegen</h1>
|
|
<ul class="index"><li><a href="#description">Description</a></li><li><a href="#index">Function Index</a></li><li><a href="#functions">Function Details</a></li></ul>Parse transform for code generation pseduo functions.
|
|
|
|
<p><b>Authors:</b> : Ulf Wiger (<a href="mailto:ulf.wiger@erlang-solutions.com"><tt>ulf.wiger@erlang-solutions.com</tt></a>).</p>
|
|
|
|
<h2><a name="description">Description</a></h2><p>Parse transform for code generation pseduo functions</p>
|
|
|
|
<p>...</p>
|
|
|
|
<h2><a name="index">Function Index</a></h2>
|
|
<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#parse_transform-2">parse_transform/2</a></td><td>
|
|
Searches for calls to pseudo functions in the module <code>codegen</code>,
|
|
and converts the corresponding erlang code to a data structure
|
|
representing the abstract form of that code.</td></tr>
|
|
</table>
|
|
|
|
<h2><a name="functions">Function Details</a></h2>
|
|
|
|
<h3 class="function"><a name="parse_transform-2">parse_transform/2</a></h3>
|
|
<div class="spec">
|
|
<p><tt>parse_transform(Forms, Options) -> NewForms</tt></p>
|
|
</div><p><p>
|
|
Searches for calls to pseudo functions in the module <code>codegen</code>,
|
|
and converts the corresponding erlang code to a data structure
|
|
representing the abstract form of that code.</p>
|
|
|
|
<p>The purpose of these functions is to let the programmer write
|
|
the actual code that is to be generated, rather than manually
|
|
writing abstract forms, which is more error prone and cannot be
|
|
checked by the compiler until the generated module is compiled.</p>
|
|
|
|
<p>Supported functions:</p>
|
|
|
|
<h2>gen_function/2</h2>
|
|
|
|
<p>Usage: <code>codegen:gen_function(Name, Fun)</code></p>
|
|
|
|
<p>Substitutes the abstract code for a function with name <code>Name</code>
|
|
and the same behaviour as <code>Fntun</code>.</p>
|
|
|
|
<p><code>Fun</code> can either be a anonymous <code>fun</code>, which is then converted to
|
|
a named function. It can also be an <code>implicit fun</code>, e.g.
|
|
<code>fun is_member/2</code>. In this case, the referenced function is fetched
|
|
and converted to an abstract form representation. It is also renamed
|
|
so that the generated function has the name <code>Name</code>.</p>
|
|
|
|
<h2>gen_functions/1</h2>
|
|
|
|
<p>Takes a list of <code>{Name, Fun}</code> tuples and produces a list of abstract
|
|
data objects, just as if one had written
|
|
<code>[codegen:gen_function(N1,F1),codegen:gen_function(N2,F2),...]</code>.</p>
|
|
|
|
<h2>exprs/1</h2>
|
|
|
|
<p>Usage: <code>codegen:exprs(Fun)</code></p>
|
|
|
|
<p><code>Fun</code> is either an anonymous function, or an implicit fun with only one
|
|
function clause. This "function" takes the body of the fun and produces
|
|
a data type representing the abstract form of the list of expressions in
|
|
the body. The arguments of the function clause are ignored, but can be
|
|
used to ensure that all necessary variables are known to the compiler.</p>
|
|
|
|
<h2>Variable substitution</h2>
|
|
|
|
<p>It is possible to do some limited expansion (importing a value
|
|
bound at compile-time), using the construct <code>{'$var', V}</code>, where
|
|
<code>V</code> is a bound variable in the scope of the call to <code>gen_function/2</code>.</p>
|
|
|
|
Example:
|
|
<pre>
|
|
gen(Name, X) ->
|
|
codegen:gen_function(Name, fun(L) -> lists:member({'$var',X}, L) end).
|
|
</pre>
|
|
|
|
After transformation, calling <code>gen(contains_17, 17)</code> will yield the
|
|
abstract form corresponding to:
|
|
<pre>
|
|
contains_17(L) ->
|
|
lists:member(17, L).
|
|
</pre></p>
|
|
<hr>
|
|
|
|
<div class="navbar"><a name="#navbar_bottom"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div>
|
|
<p><i>Generated by EDoc, Sep 5 2010, 14:28:44.</i></p>
|
|
</body>
|
|
</html>
|