Permalink
Browse files

Set up the project

Add directories, Makefiles, a dummy (identity) parse transform, and
a test suite for parameterized modules.

Using any pre-R16 system that still supports parameterized modules,
running "make" will build everything and run the tests.
  • Loading branch information...
1 parent be436e5 commit 42c1e14b2dfc037ce87cbe8d5f5dcfb8f621f195 @bjorng bjorng committed Jan 15, 2013
View
@@ -0,0 +1 @@
+*.beam
View
@@ -0,0 +1,10 @@
+.PHONY: all
+all: src tests
+
+.PHONY: src
+src:
+ $(MAKE) -C src
+
+.PHONY: test
+tests: src
+ $(MAKE) -C tests
View
No changes.
View
@@ -0,0 +1,19 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 1013. All Rights Reserved.
+%%
+%% The contents of this file are subject to the Erlang Public License,
+%% Version 1.1, (the "License"); you may not use this file except in
+%% compliance with the License. You should have received a copy of the
+%% Erlang Public License along with this software. If not, it can be
+%% retrieved online at http://www.erlang.org/.
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+%% the License for the specific language governing rights and limitations
+%% under the License.
+%%
+%% %CopyrightEnd%
+%%
+-compile({parse_transform,pmod_pt}).
View
@@ -0,0 +1,2 @@
+../ebin/pmod_pt.beam: pmod_pt.erl
+ erlc -Werror -o ../ebin pmod_pt.erl
View
@@ -0,0 +1,24 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 2013. All Rights Reserved.
+%%
+%% The contents of this file are subject to the Erlang Public License,
+%% Version 1.1, (the "License"); you may not use this file except in
+%% compliance with the License. You should have received a copy of the
+%% Erlang Public License along with this software. If not, it can be
+%% retrieved online at http://www.erlang.org/.
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+%% the License for the specific language governing rights and limitations
+%% under the License.
+%%
+%% %CopyrightEnd%
+%%
+
+-module(pmod_pt).
+-export([parse_transform/2]).
+
+parse_transform(Forms, _Options) ->
+ Forms.
View
@@ -0,0 +1,18 @@
+MODULES = \
+ test_pmod.beam \
+ alpha.beam \
+ beta.beam \
+ gamma.beam \
+ pmod_basic.beam \
+ my_lists.beam \
+ static_call.beam \
+ fun_in_pmod.beam
+
+EBIN = $(dir $(CURDIR))ebin
+
+.PHONY: tests
+tests: $(MODULES)
+ erl -pa $(EBIN) -noinput -eval 'eunit:test(test_pmod)' -run erlang halt
+
+%.beam: %.erl
+ erlc -pa $(EBIN) -Werror $<
View
@@ -0,0 +1,32 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 2013. All Rights Reserved.
+%%
+%% The contents of this file are subject to the Erlang Public License,
+%% Version 1.1, (the "License"); you may not use this file except in
+%% compliance with the License. You should have received a copy of the
+%% Erlang Public License along with this software. If not, it can be
+%% retrieved online at http://www.erlang.org/.
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+%% the License for the specific language governing rights and limitations
+%% under the License.
+%%
+%% %CopyrightEnd%
+%%
+
+-include_lib("pmod_transform/include/pmod.hrl").
+
+-module(alpha, [X,Y]).
+-export([a/0,b/1,c/2]).
+
+a() ->
+ {?MODULE,a,[X,Y],[]}.
+
+b(S) ->
+ {?MODULE,b,[X,Y],[S]}.
+
+c(S, T) ->
+ {?MODULE,c,[X,Y],[S,T]}.
View
@@ -0,0 +1,23 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 2013. All Rights Reserved.
+%%
+%% The contents of this file are subject to the Erlang Public License,
+%% Version 1.1, (the "License"); you may not use this file except in
+%% compliance with the License. You should have received a copy of the
+%% Erlang Public License along with this software. If not, it can be
+%% retrieved online at http://www.erlang.org/.
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+%% the License for the specific language governing rights and limitations
+%% under the License.
+%%
+%% %CopyrightEnd%
+%%
+
+-include_lib("pmod_transform/include/pmod.hrl").
+
+-module(bad_extend).
+-extends(bad_extend).
View
@@ -0,0 +1,35 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 2013. All Rights Reserved.
+%%
+%% The contents of this file are subject to the Erlang Public License,
+%% Version 1.1, (the "License"); you may not use this file except in
+%% compliance with the License. You should have received a copy of the
+%% Erlang Public License along with this software. If not, it can be
+%% retrieved online at http://www.erlang.org/.
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+%% the License for the specific language governing rights and limitations
+%% under the License.
+%%
+%% %CopyrightEnd%
+%%
+
+-include_lib("pmod_transform/include/pmod.hrl").
+
+-module(beta, [X,Y]).
+-extends(alpha).
+
+-export([a/0,b/1]).
+-export([call_base_a/0]).
+
+a() ->
+ {?MODULE,?BASE_MODULE,a,[X,Y],[]}.
+
+b(S) ->
+ {?MODULE,?BASE_MODULE,b,[X,Y],[S]}.
+
+call_base_a() ->
+ BASE:a().
@@ -0,0 +1,25 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 2013. All Rights Reserved.
+%%
+%% The contents of this file are subject to the Erlang Public License,
+%% Version 1.1, (the "License"); you may not use this file except in
+%% compliance with the License. You should have received a copy of the
+%% Erlang Public License along with this software. If not, it can be
+%% retrieved online at http://www.erlang.org/.
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+%% the License for the specific language governing rights and limitations
+%% under the License.
+%%
+%% %CopyrightEnd%
+%%
+
+-include_lib("pmod_transform/include/pmod.hrl").
+
+-module(defining_instance, [X]).
+
+instance() ->
+ ok.
View
@@ -0,0 +1,33 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 2013. All Rights Reserved.
+%%
+%% The contents of this file are subject to the Erlang Public License,
+%% Version 1.1, (the "License"); you may not use this file except in
+%% compliance with the License. You should have received a copy of the
+%% Erlang Public License along with this software. If not, it can be
+%% retrieved online at http://www.erlang.org/.
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+%% the License for the specific language governing rights and limitations
+%% under the License.
+%%
+%% %CopyrightEnd%
+%%
+
+-include_lib("pmod_transform/include/pmod.hrl").
+
+-module(fun_in_pmod, [X]).
+-export([add_fun/0,get_fun/0]).
+
+add_fun() ->
+ fun(N) -> X + N end.
+
+get_fun() ->
+ fun get1/0.
+
+get1() ->
+ X.
+
View
@@ -0,0 +1,32 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 2013. All Rights Reserved.
+%%
+%% The contents of this file are subject to the Erlang Public License,
+%% Version 1.1, (the "License"); you may not use this file except in
+%% compliance with the License. You should have received a copy of the
+%% Erlang Public License along with this software. If not, it can be
+%% retrieved online at http://www.erlang.org/.
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+%% the License for the specific language governing rights and limitations
+%% under the License.
+%%
+%% %CopyrightEnd%
+%%
+
+-include_lib("pmod_transform/include/pmod.hrl").
+
+-module(gamma, [X,Y]).
+-extends(beta).
+
+-export([a/0,new/1]).
+
+new(Z) ->
+ B = ?BASE_MODULE:new(Z, 17),
+ instance(B, Z, 42).
+
+a() ->
+ {?MODULE,?BASE_MODULE,a,[X,Y],[]}.
View
@@ -0,0 +1,27 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 2013. All Rights Reserved.
+%%
+%% The contents of this file are subject to the Erlang Public License,
+%% Version 1.1, (the "License"); you may not use this file except in
+%% compliance with the License. You should have received a copy of the
+%% Erlang Public License along with this software. If not, it can be
+%% retrieved online at http://www.erlang.org/.
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+%% the License for the specific language governing rights and limitations
+%% under the License.
+%%
+%% %CopyrightEnd%
+%%
+
+-include_lib("pmod_transform/include/pmod.hrl").
+
+-module(my_lists).
+-extends(lists).
+-export([empty_list/0]).
+
+empty_list() ->
+ [].
View
@@ -0,0 +1,99 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 2013. All Rights Reserved.
+%%
+%% The contents of this file are subject to the Erlang Public License,
+%% Version 1.1, (the "License"); you may not use this file except in
+%% compliance with the License. You should have received a copy of the
+%% Erlang Public License along with this software. If not, it can be
+%% retrieved online at http://www.erlang.org/.
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+%% the License for the specific language governing rights and limitations
+%% under the License.
+%%
+%% %CopyrightEnd%
+%%
+
+-include_lib("pmod_transform/include/pmod.hrl").
+
+-module(pmod_basic, [Props]).
+
+-export([lookup/1,or_props/1,prepend/1,append/1,stupid_sum/0]).
+-export([bar/1,bar_bar/1]).
+-export([bc1/0, bc2/0]).
+-export([collapse/1]).
+-export([records/0]).
+
+-import(lists, [keymap/3]).
+
+lookup(Key) ->
+ proplists:lookup(Key, Props).
+
+or_props(Keys) ->
+ Res = or_props_1(Keys, false),
+ true = is_bool(Res), %is_bool/1 does not use Props.
+ Res.
+
+prepend(Term) ->
+ new([Term|Props]).
+
+append(Term) ->
+ pmod_basic:new(Props++[Term]).
+
+or_props_1([K|Ks], Acc) ->
+ or_props_1(Ks, proplists:get_bool(K, Props) or Acc);
+or_props_1([], Acc) -> Acc.
+
+is_bool(true) -> true;
+is_bool(false) -> true;
+is_bool(_) -> false.
+
+stupid_sum() ->
+ put(counter, 0),
+ Res = stupid_sum_1(Props, 0),
+ {Res,get(counter)}.
+
+stupid_sum_1([H|T], Sum0) ->
+ try add(Sum0, H) of
+ Sum -> stupid_sum_1(T, Sum)
+ catch
+ error:_ -> stupid_sum_1(T, Sum0)
+ after
+ bump()
+ end;
+stupid_sum_1([], Sum) -> Sum.
+
+bump() ->
+ put(counter, get(counter)+1).
+
+add(A, B) ->
+ A+B.
+
+-record(s, {a}).
+
+bar(S) when S#s.a == 0 -> ok.
+
+bar_bar(S) when is_record(S, s) -> ok;
+bar_bar(_) -> error.
+
+
+-record(r, {a,b,c}).
+
+records() ->
+ R = #r{a=42,b=19},
+ update(R).
+
+update(#r{a=A}=S) ->
+ S#r{a=A+1,b=S#r.b+10}.
+
+bc1() ->
+ [A || <<A:1>> <= <<"9">> ].
+
+bc2() ->
+ << <<A:1>> || A <- [1,0,1,0] >>.
+
+collapse(L) ->
+ keymap(fun lists:sort/1, 2, L).
Oops, something went wrong.

0 comments on commit 42c1e14

Please sign in to comment.