Skip to content

Commit fae3337

Browse files
committed
Translate erlang binary and unary operators to javascript one
1 parent 1c4bbe6 commit fae3337

File tree

4 files changed

+81
-144
lines changed

4 files changed

+81
-144
lines changed

lib/elixir_script/passes/translate/form.ex

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,86 @@ defmodule ElixirScript.Translate.Form do
211211
ElixirScript.Translate.Function.compile(ast, state)
212212
end
213213

214+
def compile({{:., _, [:erlang, op]}, _, [item]}, state) when op in [:+, :-] do
215+
ast = J.unary_expression(
216+
op,
217+
true,
218+
compile!(item, state)
219+
)
220+
221+
{ast, state}
222+
end
223+
224+
def compile({{:., _, [:erlang, op]}, _, [left, right]}, state) when op in [:+, :-, :*, :/, :==, :>, :<, :>=] do
225+
ast = J.binary_expression(
226+
op,
227+
compile!(left, state),
228+
compile!(right, state)
229+
)
230+
231+
{ast, state}
232+
end
233+
234+
def compile({{:., _, [:erlang, :"=<"]}, _, [left, right]}, state) do
235+
ast = J.binary_expression(
236+
:<=,
237+
compile!(left, state),
238+
compile!(right, state)
239+
)
240+
241+
{ast, state}
242+
end
243+
244+
def compile({{:., _, [:erlang, :"=:="]}, _, [left, right]}, state) do
245+
ast = J.binary_expression(
246+
:===,
247+
compile!(left, state),
248+
compile!(right, state)
249+
)
250+
251+
{ast, state}
252+
end
253+
254+
def compile({{:., _, [:erlang, :"=/="]}, _, [left, right]}, state) do
255+
ast = J.binary_expression(
256+
:!==,
257+
compile!(left, state),
258+
compile!(right, state)
259+
)
260+
261+
{ast, state}
262+
end
263+
264+
def compile({{:., _, [:erlang, :"/="]}, _, [left, right]}, state) do
265+
ast = J.binary_expression(
266+
:!=,
267+
compile!(left, state),
268+
compile!(right, state)
269+
)
270+
271+
{ast, state}
272+
end
273+
274+
def compile({{:., _, [:erlang, op]}, _, [left, right]}, state) when op in [:andalso, :and] do
275+
ast = J.binary_expression(
276+
:&&,
277+
compile!(left, state),
278+
compile!(right, state)
279+
)
280+
281+
{ast, state}
282+
end
283+
284+
def compile({{:., _, [:erlang, op]}, _, [left, right]}, state) when op in [:orelse, :or] do
285+
ast = J.binary_expression(
286+
:||,
287+
compile!(left, state),
288+
compile!(right, state)
289+
)
290+
291+
{ast, state}
292+
end
293+
214294
def compile({{:., _, [{_, _, nil} = var, func_or_prop]}, _, []}, state) do
215295
ast = J.call_expression(
216296
ElixirScript.Translate.Forms.JS.call_property(),

lib/elixir_script/passes/translate/forms/remote.ex

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -27,76 +27,6 @@ defmodule ElixirScript.Translate.Forms.Remote do
2727
erlang functions into JavaScript functions.
2828
"""
2929

30-
def compile({:., _, [:erlang, :+]}, state) do
31-
ast = erlang_compat_function("erlang", "plus")
32-
{ ast, state }
33-
end
34-
35-
def compile({:., _, [:erlang, :-]}, state) do
36-
ast = erlang_compat_function("erlang", "minus")
37-
{ ast, state }
38-
end
39-
40-
def compile({:., _, [:erlang, :*]}, state) do
41-
ast = erlang_compat_function("erlang", "multiply")
42-
{ ast, state }
43-
end
44-
45-
def compile({:., _, [:erlang, :/]}, state) do
46-
ast = erlang_compat_function("erlang", "div")
47-
{ ast, state }
48-
end
49-
50-
def compile({:., _, [:erlang, :==]}, state) do
51-
ast = erlang_compat_function("erlang", "equal")
52-
{ ast, state }
53-
end
54-
55-
def compile({:., _, [:erlang, :>]}, state) do
56-
ast = erlang_compat_function("erlang", "greaterThan")
57-
{ ast, state }
58-
end
59-
60-
def compile({:., _, [:erlang, :>=]}, state) do
61-
ast = erlang_compat_function("erlang", "greaterThanOrEqualTo")
62-
{ ast, state }
63-
end
64-
65-
def compile({:., _, [:erlang, :"/="]}, state) do
66-
ast = erlang_compat_function("erlang", "doesNotEqual")
67-
{ ast, state }
68-
end
69-
70-
def compile({:., _, [:erlang, :"<"]}, state) do
71-
ast = erlang_compat_function("erlang", "lessThan")
72-
{ ast, state }
73-
end
74-
75-
def compile({:., _, [:erlang, :"=<"]}, state) do
76-
ast = erlang_compat_function("erlang", "lessThanOrEqualTo")
77-
{ ast, state }
78-
end
79-
80-
def compile({:., _, [:erlang, :"=:="]}, state) do
81-
ast = erlang_compat_function("erlang", "strictlyEqual")
82-
{ ast, state }
83-
end
84-
85-
def compile({:., _, [:erlang, :"=/="]}, state) do
86-
ast = erlang_compat_function("erlang", "doesNotStrictlyEqual")
87-
{ ast, state }
88-
end
89-
90-
def compile({:., _, [:erlang, function]}, state) when function in [:andalso, :and] do
91-
ast = erlang_compat_function("erlang", "and")
92-
{ ast, state }
93-
end
94-
95-
def compile({:., _, [:erlang, function]}, state) when function in [:orelse, :or] do
96-
ast = erlang_compat_function("erlang", "or")
97-
{ ast, state }
98-
end
99-
10030
def compile({:., _, [:erlang, :++]}, state) do
10131
ast = erlang_compat_function("erlang", "list_concatenation")
10232
{ ast, state }

0 commit comments

Comments
 (0)