@@ -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
0 commit comments