@@ -5,6 +5,19 @@ defmodule ElixirScript.Translate.Form do
55 alias ElixirScript.Translator.Identifier
66 alias ElixirScript.Translate.Clause
77
8+ @ erlang_modules [
9+ :erlang ,
10+ :maps ,
11+ :lists ,
12+ :gen ,
13+ :elixir_errors ,
14+ :supervisor ,
15+ :application ,
16+ :code ,
17+ :elixir_utils ,
18+ :file
19+ ]
20+
821 @ moduledoc """
922 Handles translation of all forms that are not functions or clauses
1023 """
@@ -63,7 +76,7 @@ defmodule ElixirScript.Translate.Form do
6376 Bitstring . compile ( bitstring , state )
6477 end
6578
66- def compile ( { := , _ , [ left , right ] } = match , state ) do
79+ def compile ( { := , _ , [ _ , _ ] } = match , state ) do
6780 Match . compile ( match , state )
6881 end
6982
@@ -139,7 +152,180 @@ defmodule ElixirScript.Translate.Form do
139152 )
140153 end
141154
142- def compile ( { { :. , _ , [ module , function ] } , _ , params } , state ) when module in [ :erlang , :lists , :maps ] do
155+ def compile ( { { :. , _ , [ :erlang , function ] } , _ , [ first ] } , state ) when function in [ :+ , :- ] do
156+ J . unary_expression (
157+ function ,
158+ compile ( first , state ) ,
159+ true
160+ )
161+ end
162+
163+ def compile ( { { :. , _ , [ :erlang , :not ] } , _ , [ first ] } , state ) do
164+ J . unary_expression (
165+ :! ,
166+ compile ( first , state ) ,
167+ true
168+ )
169+ end
170+
171+ def compile ( { { :. , _ , [ :erlang , :bnot ] } , _ , [ first ] } , state ) do
172+ J . unary_expression (
173+ :"~" ,
174+ compile ( first , state ) ,
175+ true
176+ )
177+ end
178+
179+ def compile ( { { :. , _ , [ :erlang , := ] } , _ , [ _ , _ ] = match } , state ) do
180+ Match . compile ( match , state )
181+ end
182+
183+ def compile ( { { :. , _ , [ :erlang , function ] } , _ , [ first , second ] } , state ) when function in [ :+ , :- , :* , :/ , :== , :>= ] do
184+ J . binary_expression (
185+ function ,
186+ compile ( first , state ) ,
187+ compile ( second , state )
188+ )
189+ end
190+
191+ def compile ( { { :. , _ , [ :erlang , :"/=" ] } , _ , [ first , second ] } , state ) do
192+ J . binary_expression (
193+ :!= ,
194+ compile ( first , state ) ,
195+ compile ( second , state )
196+ )
197+ end
198+
199+ def compile ( { { :. , _ , [ :erlang , :"=<" ] } , _ , [ first , second ] } , state ) do
200+ J . binary_expression (
201+ :<= ,
202+ compile ( first , state ) ,
203+ compile ( second , state )
204+ )
205+ end
206+
207+ def compile ( { { :. , _ , [ :erlang , :"=:=" ] } , _ , [ first , second ] } , state ) do
208+ J . binary_expression (
209+ :=== ,
210+ compile ( first , state ) ,
211+ compile ( second , state )
212+ )
213+ end
214+
215+ def compile ( { { :. , _ , [ :erlang , :"=/=" ] } , _ , [ first , second ] } , state ) do
216+ J . binary_expression (
217+ :!== ,
218+ compile ( first , state ) ,
219+ compile ( second , state )
220+ )
221+ end
222+
223+ def compile ( { { :. , _ , [ :erlang , function ] } , _ , [ first , second ] } , state ) when function in [ :andalso , :and ] do
224+ J . binary_expression (
225+ :&& ,
226+ compile ( first , state ) ,
227+ compile ( second , state )
228+ )
229+ end
230+
231+ def compile ( { { :. , _ , [ :erlang , function ] } , _ , [ first , second ] } , state ) when function in [ :orelse , :or ] do
232+ J . binary_expression (
233+ :|| ,
234+ compile ( first , state ) ,
235+ compile ( second , state )
236+ )
237+ end
238+
239+ def compile ( { { :. , _ , [ :erlang , :div ] } , _ , [ first , second ] } , state ) do
240+ J . binary_expression (
241+ :/ ,
242+ compile ( first , state ) ,
243+ compile ( second , state )
244+ )
245+ end
246+
247+ def compile ( { { :. , _ , [ :erlang , :rem ] } , _ , [ first , second ] } , state ) do
248+ J . binary_expression (
249+ :mod ,
250+ compile ( first , state ) ,
251+ compile ( second , state )
252+ )
253+ end
254+
255+ def compile ( { { :. , _ , [ :erlang , :band ] } , _ , [ first , second ] } , state ) do
256+ J . binary_expression (
257+ :& ,
258+ compile ( first , state ) ,
259+ compile ( second , state )
260+ )
261+ end
262+
263+ def compile ( { { :. , _ , [ :erlang , :bor ] } , _ , [ first , second ] } , state ) do
264+ J . binary_expression (
265+ :| ,
266+ compile ( first , state ) ,
267+ compile ( second , state )
268+ )
269+ end
270+
271+ def compile ( { { :. , _ , [ :erlang , :bsl ] } , _ , [ first , second ] } , state ) do
272+ J . binary_expression (
273+ :"<<" ,
274+ compile ( first , state ) ,
275+ compile ( second , state )
276+ )
277+ end
278+
279+ def compile ( { { :. , _ , [ :erlang , :bsl ] } , _ , [ first , second ] } , state ) do
280+ J . binary_expression (
281+ :">>" ,
282+ compile ( first , state ) ,
283+ compile ( second , state )
284+ )
285+ end
286+
287+ def compile ( { { :. , _ , [ :erlang , :bxor ] } , _ , [ first , second ] } , state ) do
288+ J . binary_expression (
289+ :">>" ,
290+ compile ( first , state ) ,
291+ compile ( second , state )
292+ )
293+ end
294+
295+ def compile ( { { :. , _ , [ :erlang , :++ ] } , _ , [ _ , _ ] = params } , state ) do
296+ J . call_expression (
297+ J . member_expression (
298+ J . member_expression (
299+ J . member_expression (
300+ J . identifier ( "Bootstrap" ) ,
301+ J . identifier ( "Core" )
302+ ) ,
303+ J . identifier ( :erlang )
304+ ) ,
305+ J . identifier ( "list_concatenation2" )
306+ ) ,
307+ Enum . map ( params , & compile ( & 1 , state ) )
308+ )
309+ end
310+
311+ def compile ( { { :. , _ , [ :erlang , :-- ] } , _ , [ _ , _ ] = params } , state ) do
312+ J . call_expression (
313+ J . member_expression (
314+ J . member_expression (
315+ J . member_expression (
316+ J . identifier ( "Bootstrap" ) ,
317+ J . identifier ( "Core" )
318+ ) ,
319+ J . identifier ( :erlang )
320+ ) ,
321+ J . identifier ( "list_substraction2" )
322+ ) ,
323+ Enum . map ( params , & compile ( & 1 , state ) )
324+ )
325+ end
326+
327+
328+ def compile ( { { :. , _ , [ module , function ] } , _ , params } , state ) when module in @ erlang_modules do
143329 J . call_expression (
144330 J . member_expression (
145331 J . member_expression (
0 commit comments