diff options
author | Björn Gustavsson <[email protected]> | 2013-10-03 12:58:54 +0200 |
---|---|---|
committer | Björn-Egil Dahlberg <[email protected]> | 2014-01-28 15:56:28 +0100 |
commit | 760ed909f8e2a655100ea773829c7d0e7dd40088 (patch) | |
tree | 1b79bd3c8076bac00a1cf7f609b9f63820686fad /lib/compiler/src | |
parent | c0bb7f866257168e0a05110767fc7096a93d351d (diff) | |
download | otp-760ed909f8e2a655100ea773829c7d0e7dd40088.tar.gz otp-760ed909f8e2a655100ea773829c7d0e7dd40088.tar.bz2 otp-760ed909f8e2a655100ea773829c7d0e7dd40088.zip |
Pass the map pair operators through to the v3_codegen pass
Diffstat (limited to 'lib/compiler/src')
-rw-r--r-- | lib/compiler/src/v3_codegen.erl | 17 | ||||
-rw-r--r-- | lib/compiler/src/v3_kernel.erl | 25 | ||||
-rw-r--r-- | lib/compiler/src/v3_kernel.hrl | 3 | ||||
-rw-r--r-- | lib/compiler/src/v3_kernel_pp.erl | 4 | ||||
-rw-r--r-- | lib/compiler/src/v3_life.erl | 10 |
5 files changed, 37 insertions, 22 deletions
diff --git a/lib/compiler/src/v3_codegen.erl b/lib/compiler/src/v3_codegen.erl index e8eec08323..c1d555efac 100644 --- a/lib/compiler/src/v3_codegen.erl +++ b/lib/compiler/src/v3_codegen.erl @@ -1502,16 +1502,17 @@ set_cg([{var,R}], {map,SrcMap,Es}, Le, Vdb, Bef, _ -> SrcMap end, - % MapPairs in put_map must be sorted in ascending Key Order - % Key literals must be unique when arriving here in v3_codegen + %% MapPairs in put_map must be sorted in ascending Key order. + %% Key literals must be unique when arriving here in v3_codegen. - SortedEs = lists:sort(fun - ({map_pair,{_T1,K1},_},{map_pair,{_T2,K2},_}) when K1 < K2 -> true; - ({map_pair,{_,_},_},{map_pair,{_,_},_}) -> false - end, Es), + SortedEs = lists:sort(fun({_,{_T1,K1},_},{_,{_T2,K2},_}) -> + K1 =< K2 + end, Es), List = flatmap(fun - ({map_pair,K,{var,V}}) -> [K,fetch_var(V, Int0)]; - ({map_pair,K,E}) -> [K,E] + ({map_pair_assoc,K,{var,V}}) -> [K,fetch_var(V, Int0)]; + ({map_pair_exact,K,{var,V}}) -> [K,fetch_var(V, Int0)]; + ({map_pair_assoc,K,E}) -> [K,E]; + ({map_pair_exact,K,E}) -> [K,E] end, SortedEs), Live = max_reg(Bef#sr.reg), Int1 = clear_dead(Int0, Le#l.i, Vdb), diff --git a/lib/compiler/src/v3_kernel.erl b/lib/compiler/src/v3_kernel.erl index 44f853ec2b..14e776fd3c 100644 --- a/lib/compiler/src/v3_kernel.erl +++ b/lib/compiler/src/v3_kernel.erl @@ -503,11 +503,11 @@ map_pairs(Es, Sub, St) -> (#c_map_pair_assoc{key=K0,val=V0}, {Kes,Esp,St0}) -> {K,[],St1} = expr(K0, Sub, St0), {V,Ep,St2} = atomic(V0, Sub, St1), - {[#k_map_pair{key=K,val=V}|Kes],Ep ++ Esp,St2}; + {[#k_map_pair_assoc{key=K,val=V}|Kes],Ep ++ Esp,St2}; (#c_map_pair_exact{key=K0,val=V0}, {Kes,Esp,St0}) -> {K,[],St1} = expr(K0, Sub, St0), {V,Ep,St2} = atomic(V0, Sub, St1), - {[#k_map_pair{key=K,val=V}|Kes],Ep ++ Esp,St2} + {[#k_map_pair_exact{key=K,val=V}|Kes],Ep ++ Esp,St2} end, {[],[],St}, Es). %% call_type(Module, Function, Arity) -> call | bif | apply | error. @@ -668,10 +668,14 @@ pattern(#c_tuple{anno=A,es=Ces}, Isub, Osub0, St0) -> pattern(#c_map{anno=A,es=Ces}, Isub, Osub0, St0) -> {Kes,Osub1,St1} = pattern_list(Ces, Isub, Osub0, St0), {#k_map{anno=A,es=Kes},Osub1,St1}; +pattern(#c_map_pair_assoc{anno=A,key=Ck,val=Cv},Isub, Osub0, St0) -> + {Kk,Osub1,St1} = pattern(Ck, Isub, Osub0, St0), + {Kv,Osub2,St2} = pattern(Cv, Isub, Osub1, St1), + {#k_map_pair_assoc{anno=A,key=Kk,val=Kv},Osub2,St2}; pattern(#c_map_pair_exact{anno=A,key=Ck,val=Cv},Isub, Osub0, St0) -> {Kk,Osub1,St1} = pattern(Ck, Isub, Osub0, St0), {Kv,Osub2,St2} = pattern(Cv, Isub, Osub1, St1), - {#k_map_pair{anno=A,key=Kk,val=Kv},Osub2,St2}; + {#k_map_pair_assoc{anno=A,key=Kk,val=Kv},Osub2,St2}; pattern(#c_binary{anno=A,segments=Cv}, Isub, Osub0, St0) -> {Kv,Osub1,St1} = pattern_bin(Cv, Isub, Osub0, St0), {#k_binary{anno=A,segs=Kv},Osub1,St1}; @@ -1347,8 +1351,8 @@ get_match(#k_tuple{es=Es}, St0) -> {#k_tuple{es=Mes},Mes,St1}; get_match(#k_map{es=Es0}, St0) -> {Mes,St1} = new_vars(length(Es0), St0), - {Es,_} = mapfoldl(fun(#k_map_pair{}=Pair, [V|Vs]) -> - {Pair#k_map_pair{val=V},Vs} + {Es,_} = mapfoldl(fun(#k_map_pair_assoc{}=Pair, [V|Vs]) -> + {Pair#k_map_pair_assoc{val=V},Vs} end, Mes, Es0), {#k_map{es=Es},Mes,St1}; get_match(M, St) -> @@ -1368,7 +1372,8 @@ new_clauses(Cs0, U, St) -> #k_bin_int{next=N} -> [N|As]; #k_map{es=Es} -> - Vals = [V || #k_map_pair{val=V} <- Es], + Vals = [V || + #k_map_pair_assoc{val=V} <- Es], Vals ++ As; _Other -> As @@ -1470,7 +1475,7 @@ arg_val(Arg, C) -> end; #k_map{es=Es} -> Keys = [begin - #k_map_pair{key=#k_literal{val=Key}} = Pair, + #k_map_pair_assoc{key=#k_literal{val=Key}} = Pair, Key end || Pair <- Es], %% multiple keys may have the same name @@ -1846,7 +1851,9 @@ lit_vars(#k_cons{hd=H,tl=T}) -> union(lit_vars(H), lit_vars(T)); lit_vars(#k_map{var=Var,es=Es}) -> lit_list_vars([Var|Es]); -lit_vars(#k_map_pair{key=K,val=V}) -> +lit_vars(#k_map_pair_assoc{key=K,val=V}) -> + union(lit_vars(K), lit_vars(V)); +lit_vars(#k_map_pair_exact{key=K,val=V}) -> union(lit_vars(K), lit_vars(V)); lit_vars(#k_binary{segs=V}) -> lit_vars(V); lit_vars(#k_bin_end{}) -> []; @@ -1886,7 +1893,7 @@ pat_vars(#k_tuple{es=Es}) -> pat_list_vars(Es); pat_vars(#k_map{es=Es}) -> pat_list_vars(Es); -pat_vars(#k_map_pair{val=V}) -> +pat_vars(#k_map_pair_assoc{val=V}) -> pat_vars(V). pat_list_vars(Ps) -> diff --git a/lib/compiler/src/v3_kernel.hrl b/lib/compiler/src/v3_kernel.hrl index 6671109afb..9da394d50d 100644 --- a/lib/compiler/src/v3_kernel.hrl +++ b/lib/compiler/src/v3_kernel.hrl @@ -39,7 +39,8 @@ -record(k_tuple, {anno=[],es}). -record(k_map, {anno=[],var,es}). --record(k_map_pair, {anno=[],key,val}). +-record(k_map_pair_assoc, {anno=[],key,val}). +-record(k_map_pair_exact, {anno=[],key,val}). -record(k_cons, {anno=[],hd,tl}). -record(k_binary, {anno=[],segs}). -record(k_bin_seg, {anno=[],size,unit,type,flags,seg,next}). diff --git a/lib/compiler/src/v3_kernel_pp.erl b/lib/compiler/src/v3_kernel_pp.erl index 1af90792d3..e8d19336f6 100644 --- a/lib/compiler/src/v3_kernel_pp.erl +++ b/lib/compiler/src/v3_kernel_pp.erl @@ -115,8 +115,10 @@ format_1(#k_map{es=Es}, Ctxt) -> format_hseq(Es, ",", ctxt_bump_indent(Ctxt, 1), fun format/2), $},$~ ]; -format_1(#k_map_pair{key=K,val=V}, Ctxt) -> +format_1(#k_map_pair_assoc{key=K,val=V}, Ctxt) -> ["~<",format(K, Ctxt),",",format(V, Ctxt),">"]; +format_1(#k_map_pair_exact{key=K,val=V}, Ctxt) -> + ["::<",format(K, Ctxt),",",format(V, Ctxt),">"]; format_1(#k_binary{segs=S}, Ctxt) -> ["#<",format(S, ctxt_bump_indent(Ctxt, 2)),">#"]; format_1(#k_bin_seg{next=Next}=S, Ctxt) -> diff --git a/lib/compiler/src/v3_life.erl b/lib/compiler/src/v3_life.erl index 507f5d0df1..a3bd781c98 100644 --- a/lib/compiler/src/v3_life.erl +++ b/lib/compiler/src/v3_life.erl @@ -369,8 +369,10 @@ literal(#k_tuple{es=Es}, Ctxt) -> {tuple,literal_list(Es, Ctxt)}; literal(#k_map{var=Var,es=Es}, Ctxt) -> {map,literal(Var, Ctxt),literal_list(Es, Ctxt)}; -literal(#k_map_pair{key=K,val=V}, Ctxt) -> - {map_pair,literal(K, Ctxt),literal(V, Ctxt)}; +literal(#k_map_pair_assoc{key=K,val=V}, Ctxt) -> + {map_pair_assoc,literal(K, Ctxt),literal(V, Ctxt)}; +literal(#k_map_pair_exact{key=K,val=V}, Ctxt) -> + {map_pair_exact,literal(K, Ctxt),literal(V, Ctxt)}; literal(#k_literal{val=V}, _Ctxt) -> {literal,V}. @@ -402,7 +404,9 @@ literal2(#k_tuple{es=Es}, Ctxt) -> {tuple,literal_list2(Es, Ctxt)}; literal2(#k_map{es=Es}, Ctxt) -> {map,literal_list2(Es, Ctxt)}; -literal2(#k_map_pair{key=K,val=V}, Ctxt) -> +literal2(#k_map_pair_assoc{key=K,val=V}, Ctxt) -> + {map_pair,literal2(K, Ctxt),literal2(V, Ctxt)}; +literal2(#k_map_pair_exact{key=K,val=V}, Ctxt) -> {map_pair,literal2(K, Ctxt),literal2(V, Ctxt)}. literal_list2(Ks, Ctxt) -> |