@@ -10,9 +10,24 @@ defmodule ElixirScript.Beam do
1010 @ spec debug_info ( atom ) :: { :ok | :error , map | binary }
1111 def debug_info ( module )
1212
13- #Replace some modules with ElixirScript versions
14- def debug_info ( module ) when module in [ String , Agent ] do
15- case debug_info ( Module . concat ( ElixirScript , module ) ) do
13+ # We get debug info from String and then replace
14+ # functions in it with equivalents in ElixirScript.String.
15+ # This is so that we don't include the unicode database
16+ # in our output
17+ def debug_info ( String ) do
18+ { :ok , info } = do_debug_info ( String )
19+ { :ok , ex_string_info } = do_debug_info ( ElixirScript.String )
20+
21+ definitions = replace_definitions ( info . definitions , ex_string_info . definitions )
22+
23+ info = % { info | definitions: definitions }
24+
25+ { :ok , info }
26+ end
27+
28+ # Replace some modules with ElixirScript versions
29+ def debug_info ( module ) when module in [ Agent ] do
30+ case do_debug_info ( Module . concat ( ElixirScript , module ) ) do
1631 { :ok , info } ->
1732 { :ok , Map . put ( info , :module , module ) }
1833 e ->
@@ -21,6 +36,10 @@ defmodule ElixirScript.Beam do
2136 end
2237
2338 def debug_info ( module ) when is_atom ( module ) do
39+ do_debug_info ( module )
40+ end
41+
42+ defp do_debug_info ( module ) when is_atom ( module ) do
2443 #TODO: Get modified date from _beam_path to check for cached version?
2544 with { _ , beam , _beam_path } <- :code . get_object_code ( module ) ,
2645 { :ok , { ^ module , [ debug_info: { :debug_info_v1 , backend , data } ] } } <- :beam_lib . chunks ( beam , [ :debug_info ] ) ,
@@ -59,4 +78,21 @@ defmodule ElixirScript.Beam do
5978 { :ok , module , implementations }
6079 end
6180
62- end
81+ defp replace_definitions ( original_definitions , replacement_definitions ) do
82+ Enum . map ( original_definitions , fn
83+ { { function , arity } , type , _ , _ } = ast ->
84+ ex_ast = Enum . find ( replacement_definitions , fn
85+ { { ex_function , ex_arity } , ex_type , _ , _ } ->
86+ ex_function == function and ex_arity == arity and ex_type == type
87+ end )
88+
89+ case ex_ast do
90+ nil ->
91+ ast
92+ _ ->
93+ ex_ast
94+ end
95+ end )
96+ end
97+
98+ end
0 commit comments