@@ -30,6 +30,7 @@ defmodule ElixirScript.Beam do
3030 case do_debug_info ( Module . concat ( ElixirScript , module ) ) do
3131 { :ok , info } ->
3232 { :ok , Map . put ( info , :module , module ) }
33+
3334 e ->
3435 e
3536 end
@@ -49,28 +50,32 @@ defmodule ElixirScript.Beam do
4950 case :code . get_object_code ( module ) do
5051 { _ , beam , beam_path } ->
5152 do_debug_info ( beam , beam_path )
53+
5254 :error ->
5355 { :error , "Unknown module" }
5456 end
5557 end
5658
5759 defp do_debug_info ( beam , beam_path ) do
58- with { :ok , { module , [ debug_info: { :debug_info_v1 , backend , data } ] } } <- :beam_lib . chunks ( beam , [ :debug_info ] ) ,
59- { :ok , { ^ module , attribute_info } } = :beam_lib . chunks ( beam , [ :attributes ] ) do
60-
61- if Keyword . get ( attribute_info [ :attributes ] , :protocol ) do
62- get_protocol_implementations ( module , beam_path )
63- else
64- backend . debug_info ( :elixir_v1 , module , data , [ ] )
65- |> process_debug_info ( beam_path )
66- end
60+ with { :ok , { module , [ debug_info: { :debug_info_v1 , backend , data } ] } } <-
61+ :beam_lib . chunks ( beam , [ :debug_info ] ) ,
62+ { :ok , { ^ module , attribute_info } } = :beam_lib . chunks ( beam , [ :attributes ] ) do
63+ if Keyword . get ( attribute_info [ :attributes ] , :protocol ) do
64+ get_protocol_implementations ( module , beam_path )
65+ else
66+ backend . debug_info ( :elixir_v1 , module , data , [ ] )
67+ |> process_debug_info ( beam_path )
68+ end
6769 else
6870 :error ->
6971 { :error , "Unknown module" }
72+
7073 { :error , :beam_lib , { :unknown_chunk , "non_existing.beam" , :debug_info } } ->
7174 { :error , "Unsupported version of Erlang" }
72- { :error , :beam_lib , { :missing_chunk , _ , _ } } ->
75+
76+ { :error , :beam_lib , { :missing_chunk , _ , _ } } ->
7377 { :error , "Debug info not available" }
78+
7479 { :error , :beam_lib , { :file_error , "non_existing.beam" , :enoent } } ->
7580 { :error , "Debug info not available" }
7681 end
@@ -82,12 +87,14 @@ defmodule ElixirScript.Beam do
8287 end
8388
8489 defp process_debug_info ( { :ok , info } , beam_path ) do
85- info = case File . stat ( beam_path , time: :posix ) do
86- { :ok , file_info } ->
87- Map . put ( info , :last_modified , file_info . mtime )
88- _ ->
89- Map . put ( info , :last_modified , nil )
90- end
90+ info =
91+ case File . stat ( beam_path , time: :posix ) do
92+ { :ok , file_info } ->
93+ Map . put ( info , :last_modified , file_info . mtime )
94+
95+ _ ->
96+ Map . put ( info , :last_modified , nil )
97+ end
9198
9299 info = Map . put ( info , :beam_path , beam_path )
93100
@@ -101,36 +108,39 @@ defmodule ElixirScript.Beam do
101108 defp get_protocol_implementations ( module , beam_path ) do
102109 { :ok , protocol_module_info } = process_debug_info ( { :ok , % { } } , beam_path )
103110
104- implementations = module
105- |> Protocol . extract_impls ( :code . get_path ( ) )
106- |> Enum . map ( fn ( x ) -> Module . concat ( [ module , x ] ) end )
107- |> Enum . map ( fn ( x ) ->
108- case debug_info ( x ) do
109- { :ok , info } ->
110- { x , info }
111- _ ->
112- raise "Unable to compile protocol implementation #{ inspect x } "
113- end
114- end )
111+ implementations =
112+ module
113+ |> Protocol . extract_impls ( :code . get_path ( ) )
114+ |> Enum . map ( fn x -> Module . concat ( [ module , x ] ) end )
115+ |> Enum . map ( fn x ->
116+ case debug_info ( x ) do
117+ { :ok , info } ->
118+ { x , info }
119+
120+ _ ->
121+ raise ElixirScript.CompileError ,
122+ message: "Unable to compile protocol implementation #{ inspect ( x ) } " ,
123+ severity: :error
124+ end
125+ end )
115126
116127 { :ok , module , protocol_module_info , implementations }
117128 end
118129
119130 defp replace_definitions ( original_definitions , replacement_definitions ) do
120- Enum . map ( original_definitions , fn
121- { { function , arity } , type , _ , _ } = ast ->
122- ex_ast = Enum . find ( replacement_definitions , fn
123- { { ex_function , ex_arity } , ex_type , _ , _ } ->
124- ex_function == function and ex_arity == arity and ex_type == type
131+ Enum . map ( original_definitions , fn { { function , arity } , type , _ , _ } = ast ->
132+ ex_ast =
133+ Enum . find ( replacement_definitions , fn { { ex_function , ex_arity } , ex_type , _ , _ } ->
134+ ex_function == function and ex_arity == arity and ex_type == type
125135 end )
126136
127- case ex_ast do
128- nil ->
129- ast
130- _ ->
131- ex_ast
132- end
137+ case ex_ast do
138+ nil ->
139+ ast
140+
141+ _ ->
142+ ex_ast
143+ end
133144 end )
134145 end
135-
136146end
0 commit comments