From 3c5067eab057391e101845b03c1ba7b76d2b3562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn-Egil=20Dahlberg?= Date: Tue, 1 Oct 2013 23:42:17 +0200 Subject: compiler: Implement support for exact Op in Maps The syntax is handled upto v3_kernel where it is reduced to previous behaviour for construction and updates. Meaning, the ':=' operator is handled exactly as '=>' operator. --- lib/compiler/src/sys_core_fold.erl | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'lib/compiler/src/sys_core_fold.erl') diff --git a/lib/compiler/src/sys_core_fold.erl b/lib/compiler/src/sys_core_fold.erl index cdbe2d0753..2cd6ea0e53 100644 --- a/lib/compiler/src/sys_core_fold.erl +++ b/lib/compiler/src/sys_core_fold.erl @@ -438,18 +438,28 @@ pair_list_reversed([E|Es],Ctxt,Sub,Out,Keys) -> %% check if key already is present in map, i.e. #{ a=>1, a=>2 } %% where 'a' is duplicate. Update maps set with the key if not present. -map_has_key(#c_map_pair{key=#c_literal{val=K}},Ks) -> +map_has_key(MapPair,Ks) -> + K = map_get_literal_key_from_pair(MapPair), case gb_sets:is_element(K,Ks) of false -> {false, gb_sets:add(K,Ks)}; true -> {true, K} end. -pair(#c_map_pair{key=K,val=V}, effect, Sub) -> +map_get_literal_key_from_pair(#c_map_pair_assoc{key=#c_literal{val=K}}) -> K; +map_get_literal_key_from_pair(#c_map_pair_exact{key=#c_literal{val=K}}) -> K. + +pair(#c_map_pair_assoc{key=K,val=V}, effect, Sub) -> + make_effect_seq([K,V], Sub); +pair(#c_map_pair_exact{key=K,val=V}, effect, Sub) -> make_effect_seq([K,V], Sub); -pair(#c_map_pair{key=K0,val=V0}=Pair, value=Ctxt, Sub) -> +pair(#c_map_pair_assoc{key=K0,val=V0}=Pair, value=Ctxt, Sub) -> + K = expr(K0, Ctxt, Sub), + V = expr(V0, Ctxt, Sub), + Pair#c_map_pair_assoc{key=K,val=V}; +pair(#c_map_pair_exact{key=K0,val=V0}=Pair, value=Ctxt, Sub) -> K = expr(K0, Ctxt, Sub), V = expr(V0, Ctxt, Sub), - Pair#c_map_pair{key=K,val=V}. + Pair#c_map_pair_exact{key=K,val=V}. bitstr_list(Es, Sub) -> [bitstr(E, Sub) || E <- Es]. @@ -1559,10 +1569,10 @@ map_pair_pattern_list(Ps0, Isub, Osub0) -> {Ps,{_,Osub}} = mapfoldl(fun map_pair_pattern/2, {Isub,Osub0}, Ps0), {Ps,Osub}. -map_pair_pattern(#c_map_pair{key=K0,val=V0}=Pair, {Isub,Osub0}) -> +map_pair_pattern(#c_map_pair_exact{key=K0,val=V0}=Pair, {Isub,Osub0}) -> {K,Osub1} = pattern(K0, Isub, Osub0), {V,Osub} = pattern(V0, Isub, Osub1), - {Pair#c_map_pair{key=K,val=V},{Isub,Osub}}. + {Pair#c_map_pair_exact{key=K,val=V},{Isub,Osub}}. bin_pattern_list(Ps0, Isub, Osub0) -> {Ps,{_,Osub}} = mapfoldl(fun bin_pattern/2, {Isub,Osub0}, Ps0), -- cgit v1.2.3