mirror of
https://github.com/valitydev/parse_trans.git
synced 2024-11-06 08:35:17 +00:00
57 lines
854 B
Erlang
57 lines
854 B
Erlang
-module(ex_codegen).
|
|
|
|
-compile({parse_transform, parse_trans_codegen}).
|
|
|
|
-export([f/1, g/2, h/0, i/0, gen/2, fs/0]).
|
|
|
|
|
|
f(Name) ->
|
|
codegen:gen_function(
|
|
Name,
|
|
fun(1,2,3) ->
|
|
foo;
|
|
(A,B,C) ->
|
|
{A,B,C}
|
|
end).
|
|
|
|
|
|
|
|
g(Name, V) ->
|
|
codegen:gen_function(
|
|
Name,
|
|
fun(L) ->
|
|
member({'$var',V}, L)
|
|
end).
|
|
|
|
h() ->
|
|
codegen:gen_function(
|
|
funny,
|
|
fun() ->
|
|
fun gen/2
|
|
end).
|
|
|
|
i() ->
|
|
codegen:exprs(fun(X) ->
|
|
case X of 1 ->
|
|
is_1;
|
|
Other ->
|
|
{is_other,Other}
|
|
end
|
|
end).
|
|
|
|
|
|
gen(Name, X) ->
|
|
codegen:gen_function(Name, fun(L) -> lists:member({'$var',X}, L) end).
|
|
|
|
fs() ->
|
|
V = local_V,
|
|
codegen:gen_functions(
|
|
[{foo, fun() ->
|
|
foo
|
|
end},
|
|
{h1, fun h/0},
|
|
{g1, fun g/2},
|
|
{bar, fun() ->
|
|
bar
|
|
end}]).
|