Skip to content

Commit d4e6b48

Browse files
committed
got all tests passing again
1 parent 36ead77 commit d4e6b48

14 files changed

Lines changed: 76 additions & 353 deletions

File tree

lib/elixir_script.ex

Lines changed: 0 additions & 231 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ defmodule ElixirScript do
7070
result = %{ data: data }
7171
|> ElixirScript.Passes.Init.execute(opts)
7272
|> ElixirScript.Passes.FindModules.execute(opts)
73-
|> ElixirScript.Passes.FindDeps.execute(opts)
7473
|> ElixirScript.Passes.FindFunctions.execute(opts)
7574
|> ElixirScript.Passes.AddStdLib.execute(opts)
7675
|> ElixirScript.Passes.JavaScriptAST.execute(opts)
@@ -124,7 +123,6 @@ defmodule ElixirScript do
124123
|> ElixirScript.Passes.DepsPaths.execute(opts)
125124
|> ElixirScript.Passes.ASTFromFile.execute(opts)
126125
|> ElixirScript.Passes.FindModules.execute(opts)
127-
|> ElixirScript.Passes.FindDeps.execute(opts)
128126
|> ElixirScript.Passes.RemoveUnused.execute(opts)
129127
|> ElixirScript.Passes.LoadModules.execute(opts)
130128
|> ElixirScript.Passes.FindChangedFiles.execute(opts)
@@ -139,21 +137,6 @@ defmodule ElixirScript do
139137
result
140138
end
141139

142-
defp process_path(path) do
143-
path = Path.join(path, "**/*.{ex,exs,exjs}") |> Path.wildcard
144-
{exjs, ex} = Enum.partition(path, fn(x) ->
145-
case Path.extname(x) do
146-
ext when ext in [".ex", ".exs"] ->
147-
false
148-
_ ->
149-
true
150-
end
151-
end)
152-
153-
ex = Kernel.ParallelRequire.files(ex)
154-
{exjs, ex}
155-
end
156-
157140
@doc false
158141
def get_stdlib_state() do
159142
case @stdlib_state do
@@ -164,48 +147,6 @@ defmodule ElixirScript do
164147
end
165148
end
166149

167-
defp get_compiler_cache(path, opts) do
168-
refresh_cache = cond do
169-
Map.get(opts, :full_build) ->
170-
true
171-
empty?(opts.output) ->
172-
true
173-
old_version?(opts) ->
174-
true
175-
Cache.get(path) == nil ->
176-
true
177-
true ->
178-
false
179-
end
180-
181-
if refresh_cache do
182-
Cache.delete(path)
183-
Cache.new(get_stdlib_state)
184-
else
185-
%{ Cache.get(path) | full_build?: false }
186-
end
187-
end
188-
189-
defp empty?(path) when is_binary(path) do
190-
case File.ls(path) do
191-
{:ok, []} ->
192-
true
193-
{:error, _} ->
194-
true
195-
_ ->
196-
false
197-
end
198-
end
199-
200-
defp empty?(_) do
201-
true
202-
end
203-
204-
defp old_version?(opts) do
205-
cache_version = Map.get(opts, :version, nil)
206-
cache_version == version()
207-
end
208-
209150
@doc false
210151
def version(), do: @version
211152

@@ -234,22 +175,6 @@ defmodule ElixirScript do
234175
result
235176
end
236177

237-
defp do_compile(opts, quoted_code_list, state, loaded_modules) do
238-
compiler_opts = build_compiler_options(opts)
239-
240-
ElixirScript.Translator.State.start_link(compiler_opts, loaded_modules)
241-
ElixirScript.Translator.State.deserialize(state, loaded_modules)
242-
243-
quoted_code_list
244-
|> Enum.map(&update_quoted(&1))
245-
#|> ModuleCollector.process_modules(compiler_opts[:app])
246-
247-
code = create_code(compiler_opts, ElixirScript.Translator.State.get)
248-
new_state = ElixirScript.Translator.State.serialize()
249-
250-
{ code, new_state }
251-
end
252-
253178
defp build_compiler_options(opts) do
254179
default_options = Map.new
255180
|> Map.put(:include_path, false)
@@ -264,140 +189,12 @@ defmodule ElixirScript do
264189
Map.merge(default_options, opts)
265190
end
266191

267-
defp file_to_quoted(file) do
268-
file
269-
|> File.read!
270-
|> Code.string_to_quoted!
271-
end
272-
273-
defp update_quoted(quoted) do
274-
Macro.prewalk(quoted, fn
275-
({name, context, parms}) ->
276-
context = if context[:import] == Kernel do
277-
context = Keyword.update!(context, :import, fn(_) -> ElixirScript.Kernel end)
278-
else
279-
context
280-
end
281-
282-
{name, context, parms}
283-
(x) ->
284-
x
285-
end)
286-
end
287-
288192
@doc false
289193
def custom_env() do
290194
__using__([])
291195
__ENV__
292196
end
293197

294-
defp create_code(compiler_opts, state) do
295-
296-
parent = self
297-
298-
Map.values(state.modules)
299-
|> Enum.reject(fn(ast) ->
300-
not ast.name in state.added_modules
301-
end)
302-
|> Enum.map(fn ast ->
303-
spawn_link fn ->
304-
env = ElixirScript.Translator.LexicalScope.module_scope(ast.name, Utils.name_to_js_file_name(ast.name) <> ".js", state.compiler_opts.env)
305-
306-
module = case ast.type do
307-
:module ->
308-
ElixirScript.Translator.Defmodule.make_module(ast.name, ast.body, env)
309-
:protocol ->
310-
ElixirScript.Translator.Defprotocol.make(ast.name, ast.functions, env)
311-
:protocol_implementation ->
312-
ElixirScript.Translator.Defimpl.make(ast.name, ast.impl_type, ast.body, env)
313-
end
314-
315-
316-
result = javascript_ast_to_code(module)
317-
318-
send parent, { self, result }
319-
end
320-
end)
321-
|> Enum.map(fn pid ->
322-
receive do
323-
{^pid, result} -> result
324-
end
325-
end)
326-
end
327-
328-
@doc false
329-
def update_protocols(compiler_output, compiler_opts) do
330-
Enum.reduce(compiler_output, %{}, fn
331-
{file, code, app_name}, state ->
332-
case String.split(file, ".DefImpl.") do
333-
[protocol, impl] ->
334-
protocol = String.split(protocol, "/") |> List.last |> String.to_atom
335-
impl = String.replace(impl, ".js", "") |> String.to_atom
336-
337-
entry = Map.get(state, protocol, [])
338-
entry = entry ++ [{app_name, impl}]
339-
340-
341-
Map.put(state, protocol, entry)
342-
[_] ->
343-
state
344-
end
345-
_, state ->
346-
state
347-
end)
348-
|> do_make_defimpl(compiler_opts)
349-
end
350-
351-
@doc false
352-
def update_protocols_in_path(compiler_output, compiler_opts, output_path) do
353-
Enum.reduce(compiler_output, %{}, fn { file, code, app_name }, state ->
354-
case String.split(file, ".DefImpl.") do
355-
[protocol, _] ->
356-
protocol = String.split(protocol, "/") |> List.last
357-
protocol_impls = find_protocols_implementations_in_path(output_path, protocol)
358-
protocol = String.to_atom(protocol)
359-
360-
entry = Map.get(state, protocol, [])
361-
entry = entry ++ protocol_impls
362-
363-
Map.put(state, protocol, entry)
364-
[_] ->
365-
state
366-
end
367-
end)
368-
|> do_make_defimpl(compiler_opts)
369-
end
370-
371-
defp do_make_defimpl(protocols, compiler_opts) do
372-
Enum.map(protocols, fn {protocol, impls} ->
373-
ElixirScript.Translator.Defprotocol.make_defimpl(protocol, Enum.uniq(impls), compiler_opts)
374-
end)
375-
|> Enum.map(fn(module) ->
376-
javascript_ast_to_code(module)
377-
end)
378-
end
379-
380-
defp find_protocols_implementations_in_path(path, protocol_prefix) do
381-
Path.join([path, "**", protocol_prefix <> ".DefImpl*.js"])
382-
|> Path.wildcard
383-
|> Enum.filter(fn path -> !String.ends_with?(path, "DefImpl.js") end)
384-
|> Enum.map(fn impl ->
385-
386-
path_split = Path.split(impl)
387-
388-
implementation = path_split
389-
|> List.last
390-
|> String.split(".DefImpl.")
391-
|> List.last
392-
|> String.replace(".js", "")
393-
|> String.to_atom
394-
395-
app_name = Enum.at(path_split, length(path_split) - 2)
396-
397-
{app_name, implementation}
398-
end)
399-
end
400-
401198
@doc """
402199
Copies the javascript that makes up the ElixirScript stdlib
403200
to the specified location
@@ -410,34 +207,6 @@ defmodule ElixirScript do
410207
end)
411208
end
412209

413-
defp javascript_ast_to_code(module) do
414-
path = Utils.name_to_js_file_name(module.name) <> ".js"
415-
js_ast = Builder.program(module.body)
416-
417-
js_code = js_ast
418-
|> prepare_js_ast
419-
|> Generator.generate
420-
421-
{ path, js_code, module.app_name }
422-
end
423-
424-
defp prepare_js_ast(js_ast) do
425-
js_ast = case js_ast do
426-
modules when is_list(modules) ->
427-
modules
428-
|> Enum.reduce([], &(&2 ++ &1.body))
429-
|> Builder.program
430-
%ElixirScript.Translator.Group{ body: body } ->
431-
Builder.program(body)
432-
%ElixirScript.Translator.Empty{ } ->
433-
Builder.program([])
434-
_ ->
435-
js_ast
436-
end
437-
438-
js_ast
439-
end
440-
441210
#Gets path to js files whether the mix project is available
442211
#or when used as an escript
443212
defp operating_path do

lib/elixir_script/compiler/output.ex

Lines changed: 0 additions & 59 deletions
This file was deleted.

lib/elixir_script/passes/consolidate_protocols.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ defmodule ElixirScript.Passes.ConsolidateProtocols do
6464
app_name = protocol.app
6565

6666
body = Enum.flat_map(implementations, fn({impl_app_name, impl_data}) ->
67-
x = Atom.to_string(impl_data.type)
67+
x = Atom.to_string(Utils.quoted_to_name(impl_data.for))
6868
x = String.to_atom(protocol_name <> ".DefImpl." <> x)
6969
name = Utils.name_to_js_name(x)
70-
imports = ModuleSystems.import_module(name, Utils.make_local_file_path(impl_app_name, Utils.name_to_js_file_name(x), compiler_opts.root))
70+
imports = ModuleSystems.import_module(name, Utils.make_local_file_path(impl_data.app, Utils.name_to_js_file_name(x), compiler_opts.root))
7171
call = JS.call_expression(
7272
JS.member_expression(
7373
JS.identifier("impls"),

lib/elixir_script/passes/find_deps.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ defmodule ElixirScript.Passes.FindDeps do
1010

1111
defp do_find_dependencies({ module, module_data }) do
1212
{_, deps} = Macro.prewalk(module_data.ast, [], &collect_references(&1, &2))
13-
{ module, Map.put(module_data, :deps, deps) }
13+
{ module, Map.put(module_data, :deps, [ElixirScript.Kernel] ++ deps) }
1414
end
1515

1616
defp collect_references({:import, _, [{{:., _, [{:__aliases__, _, head_import_name}, :{}]}, _, tail_imports }]}, state) do

lib/elixir_script/passes/find_functions.ex

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,7 @@ defmodule ElixirScript.Passes.FindFunctions do
55
def execute(data, opts) do
66
new_data = Enum.map(data.data, fn { module_name, module_data } ->
77

8-
%{def: functions, defp: private_functions, defgen: generators, defgenp: private_generators } = case module_data.ast do
9-
{:defmodule, _, [_, [do: body]]} ->
10-
get_functions_from_module(body)
11-
{:defprotocol, _, [_, [do: {:__block__, _, _} = block]]} ->
12-
get_functions_from_module(block)
13-
{:defprotocol, _, [{:__aliases__, _, _} = the_alias, [do: spec]]} ->
14-
get_functions_from_module({:__block__, [], [spec]})
15-
_ ->
16-
%{ def: Keyword.new, defp: Keyword.new, defgen: Keyword.new, defgenp: Keyword.new }
17-
end
18-
8+
%{def: functions, defp: private_functions, defgen: generators, defgenp: private_generators } = get_functions_from_module(module_data.ast)
199

2010
module_data = Map.put(module_data, :functions, functions ++ generators)
2111
|> Map.put(:private_functions, private_functions ++ private_generators)
@@ -62,7 +52,7 @@ defmodule ElixirScript.Passes.FindFunctions do
6252
end
6353

6454
defp get_functions_from_module(_) do
65-
%{ def: Keyword.new, defp: Keyword.new }
55+
%{ def: Keyword.new, defp: Keyword.new, defgen: Keyword.new, defgenp: Keyword.new }
6656
end
6757

6858
defp add_function_to_map(map, type, name, arity) do

0 commit comments

Comments
 (0)