-
Notifications
You must be signed in to change notification settings - Fork 68
Figured out how to compile in memory beam data #421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
803b891
92a9540
dd555d6
798b100
c0d456c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -137,7 +137,7 @@ defmodule ElixirScript.FindUsedFunctions do | |
| walk(params, state) | ||
| end | ||
|
|
||
| defp walk({:for, _, generators}, state) do | ||
| defp walk({:for, _, generators}, state) when is_list(generators) do | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function is too complex (ABC size is 32, max is 30). |
||
| Enum.each(generators, fn | ||
| {:<<>>, _, body} -> | ||
| walk(body, state) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,14 +11,19 @@ defmodule ElixirScript.FindUsedModules do | |
| modules | ||
| |> List.wrap | ||
| |> Enum.each(fn(module) -> | ||
| if ElixirScript.State.get_module(pid, module) == nil do | ||
| do_execute(module, pid) | ||
| end | ||
| do_execute(module, pid) | ||
| end) | ||
| end | ||
|
|
||
| defp do_execute(module, pid) do | ||
| case ElixirScript.Beam.debug_info(module) do | ||
| result = case ModuleState.get_in_memory_module(pid, module) do | ||
| nil -> | ||
| ElixirScript.Beam.debug_info(module) | ||
| beam -> | ||
| ElixirScript.Beam.debug_info(beam) | ||
| end | ||
|
|
||
| case result do | ||
| {:ok, info} -> | ||
| walk_module(module, info, pid) | ||
| {:ok, module, implementations} -> | ||
|
|
@@ -73,7 +78,9 @@ defmodule ElixirScript.FindUsedModules do | |
| module: module | ||
| } | ||
|
|
||
| Enum.each(reachable_defs, &walk(&1, state)) | ||
| Enum.each(reachable_defs, fn(x) -> | ||
| walk(x, state) | ||
| end) | ||
| end | ||
|
|
||
| defp walk_protocol(module, implementations, pid) do | ||
|
|
@@ -165,7 +172,7 @@ defmodule ElixirScript.FindUsedModules do | |
| walk(params, state) | ||
| end | ||
|
|
||
| defp walk({:for, _, generators}, state) do | ||
| defp walk({:for, _, generators}, state) when is_list(generators) do | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function is too complex (ABC size is 33, max is 30). |
||
| walk(Collectable, state) | ||
|
|
||
| Enum.each(generators, fn | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,16 +9,25 @@ defmodule ElixirScript.Translate.Form do | |
| alias ElixirScript.Translate.Clause | ||
| require Logger | ||
|
|
||
| @spec compile!(any, map) :: ESTree.Node.t | ||
| def compile!(ast, state) do | ||
| {js_ast, _} = compile(ast, state) | ||
|
|
||
| js_ast | ||
| end | ||
|
|
||
| @spec compile(any, map) :: {ESTree.Node.t, map} | ||
| def compile(ast, state) | ||
|
|
||
| def compile(nil, state) do | ||
| { J.identifier("null"), state } | ||
| end | ||
|
|
||
| def compile(map, state) when is_map(map) do | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Functions should have a @SPEC type specification. |
||
| quoted = Code.string_to_quoted!("#{inspect map}") | ||
| compile(quoted, state) | ||
| end | ||
|
|
||
| def compile(form, state) when is_boolean(form) or is_integer(form) or is_float(form) or is_binary(form) do | ||
| { J.literal(form), state } | ||
| end | ||
|
|
@@ -122,7 +131,7 @@ defmodule ElixirScript.Translate.Form do | |
| { ast, state } | ||
| end | ||
|
|
||
| def compile({:for, _, _} = ast, state) do | ||
| def compile({:for, _, generators} = ast, state) when is_list(generators) do | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Functions should have a @SPEC type specification. |
||
| For.compile(ast, state) | ||
| end | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,8 @@ defmodule ElixirScript.State do | |
| Agent.start_link(fn -> | ||
| %{ | ||
| modules: Keyword.new, | ||
| js_modules: [] | ||
| js_modules: [], | ||
| in_memory_modules: [] | ||
| } | ||
| end) | ||
| end | ||
|
|
@@ -88,4 +89,24 @@ defmodule ElixirScript.State do | |
| state.modules | ||
| end) | ||
| end | ||
|
|
||
| def get_in_memory_module(pid, module) do | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Functions should have a @SPEC type specification. |
||
| Agent.get(pid, fn(state) -> | ||
| Keyword.get(state.in_memory_modules, module) | ||
| end) | ||
| end | ||
|
|
||
| def get_in_memory_modules(pid) do | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Functions should have a @SPEC type specification. |
||
| Agent.get(pid, fn(state) -> | ||
| state.in_memory_modules | ||
| end) | ||
| end | ||
|
|
||
| def put_in_memory_module(pid, module, beam) do | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Functions should have a @SPEC type specification. |
||
| Agent.update(pid, fn(state) -> | ||
| in_memory_modules = Map.get(state, :in_memory_modules, []) | ||
| in_memory_modules = Keyword.put(in_memory_modules, module, beam) | ||
| %{ state | in_memory_modules: in_memory_modules } | ||
| end) | ||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long (max is 80, was 114).