Skip to content

Commit

Permalink
debugger done
Browse files Browse the repository at this point in the history
  • Loading branch information
lucioleKi committed Nov 4, 2024
1 parent b68f3a8 commit 9a0a5e2
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 31 deletions.
87 changes: 72 additions & 15 deletions lib/debugger/src/dbg_ieval.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1176,62 +1176,96 @@ bind_all_generators1([{Generate, Anno, P, <<_/bitstring>>=Bin}|Qs],
{match, Rest, Bs1} ->
Bs2 = zip_add_bindings(Bs1, Bs0),
case Bs2 of
nomatch ->
nomatch when Generate =:= b_generate ->
bind_all_generators1(Qs, [{b_generate, Anno, P, Rest}|Acc],
Bs0, Ieval, skip);
nomatch -> {Acc, error};
_ ->
bind_all_generators1(Qs, [{b_generate, Anno, P, Rest}|Acc],
Bs2, Ieval, continue)
end;
{nomatch, Rest} ->
{nomatch, Rest} when Generate =:= b_generate ->
bind_all_generators1(Qs, [{b_generate, Anno, P, Rest}|Acc], Bs0, Ieval, skip);
{nomatch, _Rest} ->
{Acc, error};
done when Generate =:= b_generate_strict, Bin =/= <<>> ->
{Acc, error};
done ->
{[], done}
end;
bind_all_generators1([{b_generate, Anno, P, <<_/bitstring>>=Bin}|Qs], Acc, Bs0, Ieval, skip) ->
bind_all_generators1([{Generate, Anno, P, <<_/bitstring>>=Bin}|Qs], Acc, Bs0, Ieval, skip)
when Generate =:= b_generate;
Generate =:= b_generate_strict ->
Mfun = match_fun(Bs0),
Efun = fun(Exp, Bs) -> expr(Exp, Bs, #ieval{}) end,
case eval_bits:bin_gen(P, Bin, erl_eval:new_bindings(Bs0), Bs0, Mfun, Efun) of
{match, Rest, _} ->
bind_all_generators1(Qs, [{b_generate, Anno, P, Rest}|Acc], Bs0, Ieval, skip);
{nomatch, Rest} ->
{nomatch, Rest} when Generate =:= b_generate ->
bind_all_generators1(Qs, [{b_generate, Anno, P, Rest}|Acc], Bs0, Ieval, skip);
{nomatch, _Rest} ->
{Acc, error};
done when Generate =:= b_generate_strict, Bin =/= <<>> ->
{Acc, error};
done ->
{[], skip}
end;
bind_all_generators1([{generate, Anno, P, [H|T]}|Qs], Acc, Bs0, Ieval, continue) ->
bind_all_generators1([{Generate, Anno, P, [H|T]}|Qs], Acc, Bs0, Ieval, continue)
when Generate =:= generate;
Generate =:= generate_strict ->
case catch match1(P, H, erl_eval:new_bindings(Bs0), Bs0) of
{match,Bsn} ->
Bs2 = zip_add_bindings(Bsn, Bs0),
case Bs2 of
nomatch ->
nomatch when Generate =:= generate ->
bind_all_generators1(Qs,[{generate, Anno, P, T}|Acc], Bs0, Ieval, skip);
nomatch -> {Acc, error};
_ ->
bind_all_generators1(Qs,[{generate, Anno, P, T}|Acc], Bs2, Ieval, continue)
end;
nomatch ->
nomatch when Generate =:= generate ->
%% match/6 returns nomatch. Skip this value
bind_all_generators1(Qs,[{generate, Anno, P, T}|Acc], Bs0, Ieval, skip)
bind_all_generators1(Qs,[{generate, Anno, P, T}|Acc], Bs0, Ieval, skip);
nomatch ->
{Acc, error}
end;
bind_all_generators1([{generate, Anno, P, [_H|T]}|Qs], Acc, Bs0, Ieval, skip) ->
bind_all_generators1(Qs,[{generate, Anno, P, T}|Acc], Bs0, Ieval, skip);
bind_all_generators1([{m_generate, Anno, P, Iter0}|Qs], Acc, Bs0, Ieval, continue) ->
bind_all_generators1([{generate_strict, Anno, P, [H|T]}|Qs], Acc, Bs0, Ieval, continue) ->
case catch match1(P, H, erl_eval:new_bindings(Bs0), Bs0) of
{match,Bsn} ->
Bs2 = zip_add_bindings(Bsn, Bs0),
case Bs2 of
nomatch -> {Acc, error};
_ ->
bind_all_generators1(Qs,[{generate, Anno, P, T}|Acc], Bs2, Ieval, continue)
end;
nomatch ->
{Acc, error}
end;
bind_all_generators1([{Generate, Anno, P, Iter0}|Qs], Acc, Bs0, Ieval, continue)
when Generate =:= m_generate;
Generate =:= m_generate_strict ->
case maps:next(Iter0) of
{K,V,Iter} ->
case catch match1(P, {K,V}, erl_eval:new_bindings(Bs0), Bs0) of
{match,Bsn} ->
Bs2 = zip_add_bindings(Bsn, Bs0),
case Bs2 of
nomatch ->
nomatch when Generate =:= m_generate ->
bind_all_generators1(Qs,[{m_generate, Anno, P, Iter}|Acc],
Bs0, Ieval, skip);
nomatch ->
{Acc, error};
_ ->
bind_all_generators1(Qs,[{m_generate, Anno, P, Iter}|Acc],
Bs2, Ieval, continue)
end;
nomatch ->
nomatch when Generate =:= m_generate ->
bind_all_generators1(Qs, [{m_generate, Anno, P, Iter}|Acc],
Bs0, Ieval, skip)
Bs0, Ieval, skip);
nomatch ->
{Acc, error}
end;
none ->
{[], done}
Expand All @@ -1244,12 +1278,35 @@ bind_all_generators1([{m_generate, Anno, P, Iter0}|Qs], Acc, Bs0, Ieval, skip) -
none ->
{[], skip}
end;
bind_all_generators1([{m_generate_strict, Anno, P, Iter0}|Qs], Acc, Bs0, Ieval, continue) ->
case maps:next(Iter0) of
{K,V,Iter} ->
case catch match1(P, {K,V}, erl_eval:new_bindings(Bs0), Bs0) of
{match,Bsn} ->
Bs2 = zip_add_bindings(Bsn, Bs0),
case Bs2 of
nomatch ->
{Acc, error};
_ ->
bind_all_generators1(Qs,[{m_generate, Anno, P, Iter}|Acc],
Bs2, Ieval, continue)
end;
nomatch -> {Acc, error}
end;
none ->
{[], done}
end;
bind_all_generators1([{generate,_,_,[]}|_], _, _, _, _) ->
%% no more values left for a var, time to return
{[],done};
bind_all_generators1([{b_generate, _Anno, _P, _Term}|_Qs], Acc, _Bs0, _Ieval,_) ->
{Acc, error};
bind_all_generators1([{generate, _Anno, _P, _Term}|_Qs], Acc, _Bs0, _Ieval,_) ->
bind_all_generators1([{generate_strict,_,_,[]}|_], _, _, _, _) ->
%% no more values left for a var, time to return
{[],done};
bind_all_generators1([{Generate, _Anno, _P, _Term}|_Qs], Acc, _Bs0, _Ieval,_)
when Generate =:= generate;
Generate =:= generate_strict;
Generate =:= b_generate;
Generate =:= b_generate_strict ->
{Acc, error};
bind_all_generators1([], [_H|_T] = Acc, Bs0, _Ieval, continue) ->
%% all vars are bind for this round
Expand Down
8 changes: 7 additions & 1 deletion lib/debugger/src/dbg_iload.erl
Original file line number Diff line number Diff line change
Expand Up @@ -717,10 +717,16 @@ expr_comprehension({zip,Anno,Gens}, St) ->
Gs = [case G of
({generate,L,P0,Qs}) ->
{generator,{generate,L,pattern(P0, St),expr(Qs, false, St)}};
({generate_strict,L,P0,Qs}) ->
{generator,{generate_strict,L,pattern(P0, St),expr(Qs, false, St)}};
({b_generate,L,P0,Qs}) -> %R12.
{generator,{b_generate,L,pattern(P0, St),expr(Qs, false, St)}};
({b_generate_strict,L,P0,Qs}) -> %R12.
{generator,{b_generate_strict,L,pattern(P0, St),expr(Qs, false, St)}};
({m_generate,L,P0,Qs}) -> %OTP 26
{generator,{m_generate,L,mc_pattern(P0, St),expr(Qs, false, St)}}
{generator,{m_generate,L,mc_pattern(P0, St),expr(Qs, false, St)}};
({m_generate_strict,L,P0,Qs}) -> %OTP 26
{generator,{m_generate_strict,L,mc_pattern(P0, St),expr(Qs, false, St)}}
end || G <- Gens],
{zip,ln(Anno),Gs}.

Expand Down
14 changes: 7 additions & 7 deletions lib/debugger/test/zlc_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ strict_list(Config) when is_list(Config) ->
[] = strict_list_mixed_1([], []),
[11,22] = strict_list_mixed_1([{i,1},{i,2}], [{i,10},{i,20}]),
[13,25] = strict_list_mixed_1([{i,3},{i,4},{i,5}], [{i,10},bad,{i,20}]),
{'EXIT',{{badmatches,{bad,{i,15}}},_}} =
{'EXIT',{{bad_generators,{[bad,{i,5}],[{i,15},{i,20}]}},_}} =
catch strict_list_mixed_1([{i,3},bad,{i,5}], [{i,10},{i,15},{i,20}]),
{'EXIT',{{bad_generators,{[{i,5}],[]}},_}} =
catch strict_list_mixed_1([{i,3},{i,5}], [bad]),
Expand All @@ -219,26 +219,26 @@ strict_list(Config) when is_list(Config) ->

%% How should a bad match of map generator be presented?
%% Maybe like this: {badmatches,{{a,3},{{k,1},{v,2}}}}
{'EXIT',{{badmatches,{{a,3},{k,1},{v,2}}},_}} =
{'EXIT',{{bad_generators,{[{a,3}],{{k,1},{v,2},none}}},_}} =
catch strict_list_mixed_2([{a,3}], SimpleMap),

{'EXIT',{{bad_generators,{[],SimpleMap}},_}} =
{'EXIT',{{bad_generators,{[],{{k,1},{v,2},none}}},_}} =
catch strict_list_mixed_2([], SimpleMap),

[] = strict_list_strict_1([], []),
[11,22] = strict_list_strict_1([{i,1},{i,2}], [{i,10},{i,20}]),
{'EXIT',{{badmatches,{bad,{i,15}}},_}} =
{'EXIT',{{bad_generators,{[bad,{i,5}],[{i,15},{i,20}]}},_}} =
catch strict_list_strict_1([{i,3},bad,{i,5}], [{i,10},{i,15},{i,20}]),
{'EXIT',{{badmatches,{{i,4},{wrong_tag,7}}},_}} =
{'EXIT',{{bad_generators,{[{i,4},{i,5}],[{wrong_tag,7},{i,20}]}},_}} =
catch strict_list_strict_1([{i,3},{i,4},{i,5}], [{i,10},{wrong_tag,7},{i,20}]),
{'EXIT',{{badmatches,{{a,b,c},{wrong_tag,7}}},_}} =
{'EXIT',{{bad_generators,{[{a,b,c},{i,5}],[{wrong_tag,7},{i,20}]}},_}} =
catch strict_list_strict_1([{i,3},{a,b,c},{i,5}], [{i,10},{wrong_tag,7},{i,20}]),
{'EXIT',{{bad_generators,{[{i,5}],[]}},_}} =
catch strict_list_strict_1([{i,3},{i,5}], [{i,7}]),

[] = strict_list_strict_2([], [], <<>>),
[5,23] = strict_list_strict_2([{i,1},{i,2}], [{i,2},{i,7}], <<3,9>>),
{'EXIT',{{badmatches,{{i,2},{i,7},<<9:7>>}},_}} =
{'EXIT',{{bad_generators,{[{i,2}],[{i,7}],<<9:7>>}},_}} =
catch strict_list_strict_2([{i,1},{i,2}], [{i,2},{i,7}], <<3,9:7>>),
{'EXIT',{{bad_generators,{[],[],[]}},_}} = catch strict_list_strict_2([], [], []),
{'EXIT',{{bad_generators,{[{i,0}],[],<<>>}},_}} =
Expand Down
12 changes: 4 additions & 8 deletions lib/stdlib/src/erl_eval.erl
Original file line number Diff line number Diff line change
Expand Up @@ -993,8 +993,7 @@ bind_all_generators1([{Generate, Anno, P, <<_/bitstring>>=Bin}|Qs],
nomatch when Generate =:= b_generate ->
bind_all_generators1(Qs,[{b_generate, Anno, P, Rest}|Acc],
Bs0, Lf, Ef, FUVs, skip);
nomatch ->
{Acc, error};
nomatch -> {Acc, error};
_ ->
bind_all_generators1(Qs,[{b_generate, Anno, P, Rest}|Acc],
Bs2, Lf, Ef, FUVs, continue)
Expand Down Expand Up @@ -1040,8 +1039,7 @@ bind_all_generators1([{Generate, Anno, P, [H|T]}|Qs], Acc, Bs0, Lf, Ef, FUVs, co
nomatch when Generate =:= generate ->
bind_all_generators1(Qs,[{Generate, Anno, P, T}|Acc],
Bs0, Lf, Ef, FUVs, skip);
nomatch ->
{Acc, error};
nomatch -> {Acc, error};
_ -> bind_all_generators1(Qs,[{Generate, Anno, P, T}|Acc],
Bs2, Lf, Ef, FUVs, continue)
end;
Expand Down Expand Up @@ -1078,8 +1076,7 @@ bind_all_generators1([{Generate, Anno, P, Iter0}|Qs], Acc, Bs0, Lf, Ef, FUVs, co
nomatch when Generate =:= m_generate ->
bind_all_generators1(Qs,[{m_generate, Anno, P, Iter}|Acc],
Bs0, Lf, Ef, FUVs, skip);
nomatch ->
{Acc, error};
nomatch -> {Acc, error};
_ -> bind_all_generators1(Qs,[{Generate, Anno, P, Iter}|Acc],
Bs2, Lf, Ef, FUVs, continue)
end;
Expand Down Expand Up @@ -1111,8 +1108,7 @@ bind_all_generators1([{m_generate_strict, Anno, P, Iter0}|Qs], Acc, Bs0, Lf, Ef,
_ -> bind_all_generators1(Qs,[{m_generate_strict, Anno, P, Iter}|Acc],
Bs2, Lf, Ef, FUVs, continue)
end;
nomatch ->
{Acc, error}
nomatch -> {Acc, error}
end;
none ->
{[], done}
Expand Down

0 comments on commit 9a0a5e2

Please sign in to comment.