Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7ba9f99
Fix type
Premwoik Dec 7, 2021
e44716b
Add module formatting abstract code expressions to Elixir code
Premwoik Dec 7, 2021
c1b1b2c
Support bitstring expr pp
Premwoik Dec 13, 2021
3f304ca
Support :case, :fun, :receive and :lc expressions
Premwoik Dec 21, 2021
5782edf
Fix cons and support printing charlist
Premwoik Dec 21, 2021
b471de3
Add basic expr fmt tests
Premwoik Dec 21, 2021
ba7316b
Fix call expr pp, Add test
Premwoik Dec 21, 2021
90af255
Fix typos
erszcz Dec 23, 2021
0071562
Remove expressions Elixir is not able to produce
Premwoik Jan 3, 2022
27de84f
Support clauses and try expr
Premwoik Jan 4, 2022
6342970
Fix atom and call expr, Add basic tests for atom, list and call
Premwoik Jan 5, 2022
fa7aa9c
Add unwrapping for abstract code variables
Premwoik Jan 5, 2022
5bc2cdd
Add helper for translating elixir code to abstract code
Premwoik Jan 5, 2022
761a037
Support Elixir raise
Premwoik Jan 5, 2022
a6e8bdc
Add test for case and if expressions
Premwoik Jan 5, 2022
5a25b58
Restore block support
Premwoik Jan 5, 2022
5353f1c
Fix binary expr pp and add tests
Premwoik Jan 10, 2022
64236eb
Support struct
Premwoik Jan 19, 2022
cc92a04
Support printing if and cond
Premwoik Jan 19, 2022
48e5bf5
Add function that formats converted elixir code
Premwoik Jan 24, 2022
d656cbb
Add pp for guards
Premwoik Jan 24, 2022
d651e33
Clear ElixirExpr doc and rename pretty_print to pp_expr
Premwoik Jan 24, 2022
aae50d6
Support reraise, Add tests and fixes
Premwoik Jan 27, 2022
f10aea2
Add pipe and with tests. Fix with
Premwoik Jan 27, 2022
9485320
Add sigil tests
Premwoik Jan 27, 2022
05c81d2
Apply review - Use sigils, fix doc, update one test
Premwoik Feb 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/gradient/ast_specifier.ex
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ defmodule Gradient.AstSpecifier do
end

@doc """
Iterate over the list in abstract code format and runs mapper on each element
Iterate over the list in abstract code and runs mapper on each element.
"""
@spec cons_mapper(form(), [token()], options()) :: {form(), tokens()}
def cons_mapper({:cons, anno, value, tail}, tokens, opts) do
Expand Down
29 changes: 26 additions & 3 deletions lib/gradient/debug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,37 @@ defmodule Gradient.Debug do

## TODO: specify elixir_form
@type elixir_form() :: any()
@type erlang_form() :: Gradient.SpecifyErlAst.form()
@type erlang_form() :: Gradient.Types.form()

@doc ~S"""
Translate the Elixir code to the Erlang AST.
"""
defmacro elixir_to_ast(do: code) do
quoted_to_ast(code)
end

defmacro elixir_to_ast(code) do
quoted_to_ast(code)
end

@doc ~S"""
Translate the Elixir AST to the Erlang AST.
"""
@spec quoted_to_ast(elixir_form()) :: erlang_form()
def quoted_to_ast(qt) do
env = :elixir_env.new()
{ast, _, _} = :elixir.quoted_to_erl(qt, env)
Macro.escape(ast)
end

@doc ~S"""
Return the Elixir AST of an Elixir module.
"""
@spec elixir_ast(module()) :: {:ok, [elixir_form()]}
def elixir_ast(mod) do
{:ok, {_, [{:debug_info, {:debug_info_v1, :elixir_erl, abstract_code}}]}} =
{:ok, {_, [{:debug_info, {:debug_info_v1, :elixir_erl, abstract_code}}]}} =
:beam_lib.chunks(get_beam_path_as_charlist(mod), [:debug_info])

{:ok, _forms} = :elixir_erl.debug_info(:elixir_v1, :module_name, abstract_code, [])
end

Expand All @@ -22,7 +44,8 @@ defmodule Gradient.Debug do
"""
@spec erlang_ast(module()) :: {:ok, [erlang_form()]}
def erlang_ast(mod) do
{:ok, _forms} = get_beam_path_as_charlist(mod) |> Gradient.ElixirFileUtils.get_forms_from_beam()
{:ok, _forms} =
get_beam_path_as_charlist(mod) |> Gradient.ElixirFileUtils.get_forms_from_beam()
end

@doc ~S"""
Expand Down
Loading