@@ -2599,7 +2599,18 @@ defmodule Macro do
2599
2599
quote do
2600
2600
unquote ( acc_var ) = [ ]
2601
2601
unquote ( dbg_boolean_tree ( ast , acc_var , result_var ) )
2602
- { :logic_op , Enum . reverse ( unquote ( acc_var ) ) }
2602
+ { :logic_op , Enum . reverse ( unquote ( acc_var ) ) , unquote ( result_var ) }
2603
+ end
2604
+ end
2605
+
2606
+ defp dbg_ast_to_debuggable ( { :__block__ , _meta , exprs } = ast , _env ) when exprs != [ ] do
2607
+ acc_var = unique_var ( :acc , __MODULE__ )
2608
+ result_var = unique_var ( :result , __MODULE__ )
2609
+
2610
+ quote do
2611
+ unquote ( acc_var ) = [ ]
2612
+ unquote ( dbg_block ( ast , acc_var , result_var ) )
2613
+ { :block , Enum . reverse ( unquote ( acc_var ) ) , unquote ( result_var ) }
2603
2614
end
2604
2615
end
2605
2616
@@ -2693,6 +2704,18 @@ defmodule Macro do
2693
2704
end
2694
2705
end
2695
2706
2707
+ defp dbg_block ( { :__block__ , meta , exprs } , acc_var , result_var ) do
2708
+ modified_exprs =
2709
+ Enum . map ( exprs , fn expr ->
2710
+ quote do
2711
+ unquote ( result_var ) = unquote ( expr )
2712
+ unquote ( acc_var ) = [ { unquote ( escape ( expr ) ) , unquote ( result_var ) } | unquote ( acc_var ) ]
2713
+ end
2714
+ end )
2715
+
2716
+ { :__block__ , meta , modified_exprs }
2717
+ end
2718
+
2696
2719
# Made public to be called from Macro.dbg/3, so that we generate as little code
2697
2720
# as possible and call out into a function as soon as we can.
2698
2721
@ doc false
@@ -2730,15 +2753,27 @@ defmodule Macro do
2730
2753
{ [ first_formatted | rest_formatted ] , result }
2731
2754
end
2732
2755
2733
- defp dbg_format_ast_to_debug ( { :logic_op , components } , options ) do
2734
- { _ast , final_value } = List . last ( components )
2735
-
2756
+ defp dbg_format_ast_to_debug ( { :logic_op , components , value } , options ) do
2736
2757
formatted =
2737
2758
Enum . map ( components , fn { ast , value } ->
2738
2759
[ dbg_format_ast ( to_string_with_colors ( ast , options ) ) , " " , inspect ( value , options ) , ?\n ]
2739
2760
end )
2740
2761
2741
- { formatted , final_value }
2762
+ { formatted , value }
2763
+ end
2764
+
2765
+ defp dbg_format_ast_to_debug ( { :block , components , value } , options ) do
2766
+ formatted =
2767
+ [
2768
+ dbg_maybe_underline ( "Code block" , options ) ,
2769
+ ":\n (\n " ,
2770
+ Enum . map ( components , fn { ast , value } ->
2771
+ [ " " , dbg_format_ast_with_value ( ast , value , options ) ]
2772
+ end ) ,
2773
+ ")\n "
2774
+ ]
2775
+
2776
+ { formatted , value }
2742
2777
end
2743
2778
2744
2779
defp dbg_format_ast_to_debug ( { :case , ast , expr_value , clause_index , value } , options ) do
0 commit comments