1-module(receive_stacked).
2-compile([export_all,nowarn_export_all]).
3
4%% Messages may be stored outside any process heap until they
5%% have been accepted by the 'remove_message' instruction.
6%% When matching of a message fails, it is not allowed to
7%% leave references to the message or any part of it in
8%% the Y registers. An experimental code generator could
9%% do that, causing an emulator crash if there happenened to
10%% be a garbage collection.
11%%
12%% The 'S' file corresponding to this file was compiled with
13%% that experimental code generator.
14
15f1() ->
16    receive
17        X when is_integer(X) ->
18            id(42),
19            X
20    end.
21
22f2() ->
23    receive
24        [X] ->
25            Res = {ok,X},
26            id(42),
27            {Res,X}
28    end.
29
30f3() ->
31    receive
32        [H|_] when is_integer(H) ->
33            Res = {ok,H},
34            id(42),
35            {Res,H}
36    end.
37
38f4() ->
39    receive
40        [_|T] when is_list(T) ->
41            Res = {ok,T},
42            id(42),
43            {Res,T}
44    end.
45
46f5() ->
47    receive
48        {X} when is_integer(X) ->
49            Res = #{key=>X},
50            id(42),
51            {Res,X}
52    end.
53
54f6() ->
55    receive
56        <<_:8,T/binary>> when byte_size(T) > 8 ->
57            id(42),
58            T
59    end.
60
61f7() ->
62    receive
63        <<_:8,T/binary>> when is_binary(T) ->
64            id(42),
65            T
66    end.
67
68f8() ->
69    receive
70        <<_:8,T/binary>> = Bin when is_binary(Bin) ->
71            id(42),
72            T
73    end.
74
75m1() ->
76    receive
77        #{key:=V} when is_integer(V) ->
78            id(42),
79            [V]
80    end.
81
82m2() ->
83    K1 = id(key1),
84    K2 = id(key2),
85    receive
86        #{K1:=V1,K2:=V2} when is_integer(V1), is_integer(V2) ->
87            id(42),
88            {V1,V2}
89    end.
90
91id(I) ->
92    I.
93