2.3 KiB
Module ct_expand
Compile-time expansion utility.
Authors: : Ulf Wiger (ulf@wiger.net
).
Description
This module serves as an example of parse_trans-based transforms,
but might also be a useful utility in its own right.
The transform searches for calls to the pseudo-function
ct_expand:term(Expr)
, and then replaces the call site with the
result of evaluating Expr
at compile-time.
For example, the line
ct_expand:term(lists:sort([3,5,2,1,4]))
would be expanded at compile-time to [1,2,3,4,5]
.
ct_expand has now been extended to also evaluate calls to local functions. See examples/ct_expand_test.erl for some examples.
A debugging facility exists: passing the option {ct_expand_trace, Flags} as an option, or adding a compiler attribute -ct_expand_trace(Flags) will enable a form of call trace.
Flags
can be []
(no trace) or [F]
, where F
is c
(call trace),
r
(return trace), or x
(exception trace)'.
Data Types
form()
form() = any()
forms()
forms() = [form()]
options()
options() = [{atom(), any()}]
Function Index
extract_fun/3 | |
lfun_rewrite/2 | |
parse_transform/2 |
Function Details
extract_fun/3
extract_fun(Name, Arity, Forms) -> any()
lfun_rewrite/2
lfun_rewrite(Exprs, Forms) -> any()
parse_transform/2
parse_transform(Forms::forms(), Options::options()) -> forms()