@@ -5,15 +5,37 @@ defmodule Gradient.Debug do
55
66 ## TODO: specify elixir_form
77 @ type elixir_form ( ) :: any ( )
8- @ type erlang_form ( ) :: Gradient.SpecifyErlAst . form ( )
8+ @ type erlang_form ( ) :: Gradient.Types . form ( )
9+
10+ @ doc ~S"""
11+ Translate the Elixir code to the Erlang AST.
12+ """
13+ defmacro elixir_to_ast ( do: code ) do
14+ quoted_to_ast ( code )
15+ end
16+
17+ defmacro elixir_to_ast ( code ) do
18+ quoted_to_ast ( code )
19+ end
20+
21+ @ doc ~S"""
22+ Translate the Elixir AST to the Erlang AST.
23+ """
24+ @ spec quoted_to_ast ( elixir_form ( ) ) :: erlang_form ( )
25+ def quoted_to_ast ( qt ) do
26+ env = :elixir_env . new ( )
27+ { ast , _ , _ } = :elixir . quoted_to_erl ( qt , env )
28+ Macro . escape ( ast )
29+ end
930
1031 @ doc ~S"""
1132 Return the Elixir AST of an Elixir module.
1233 """
1334 @ spec elixir_ast ( module ( ) ) :: { :ok , [ elixir_form ( ) ] }
1435 def elixir_ast ( mod ) do
15- { :ok , { _ , [ { :debug_info , { :debug_info_v1 , :elixir_erl , abstract_code } } ] } } =
36+ { :ok , { _ , [ { :debug_info , { :debug_info_v1 , :elixir_erl , abstract_code } } ] } } =
1637 :beam_lib . chunks ( get_beam_path_as_charlist ( mod ) , [ :debug_info ] )
38+
1739 { :ok , _forms } = :elixir_erl . debug_info ( :elixir_v1 , :module_name , abstract_code , [ ] )
1840 end
1941
@@ -22,7 +44,8 @@ defmodule Gradient.Debug do
2244 """
2345 @ spec erlang_ast ( module ( ) ) :: { :ok , [ erlang_form ( ) ] }
2446 def erlang_ast ( mod ) do
25- { :ok , _forms } = get_beam_path_as_charlist ( mod ) |> Gradient.ElixirFileUtils . get_forms_from_beam ( )
47+ { :ok , _forms } =
48+ get_beam_path_as_charlist ( mod ) |> Gradient.ElixirFileUtils . get_forms_from_beam ( )
2649 end
2750
2851 @ doc ~S"""
0 commit comments