Skip to content

Commit 48e3225

Browse files
committed
Fixes from compiler testing. Replace String compilation with ElixirScript.String
1 parent 6e2f8f3 commit 48e3225

File tree

10 files changed

+71
-79
lines changed

10 files changed

+71
-79
lines changed

.tool-versions

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
erlang ref-OTP-20.0-rc1
2-
elixir ref-9873e42
3-
nodejs 7.10.0
1+
erlang ref-OTP-20.0-rc2
2+
elixir ref-d19a92b
3+
nodejs 8.1.0

lib/elixir_script/next/passes/find_used_functions.ex

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -46,34 +46,23 @@ defmodule ElixirScript.FindUsedFunctions do
4646

4747
defp walk_module(module, function, arity, pid) do
4848
function = {function, arity}
49-
5049
unless ModuleState.has_used?(pid, module, function) do
51-
%{
52-
attributes: _attrs,
53-
compile_opts: _compile_opts,
54-
definitions: defs,
55-
file: _file,
56-
line: _line,
57-
module: ^module,
58-
unreachable: unreachable
59-
} = ModuleState.get_module(pid, module)
50+
info = ModuleState.get_module(pid, module)
6051

6152
state = %{
6253
pid: pid,
6354
module: module
6455
}
6556

66-
reachable_defs = Enum.filter(defs, fn
67-
{ _, type, _, _} when type in [:defmacro, :defmacrop] -> false
68-
{ name, _, _, _} -> not(name in [function])
69-
_ -> true
70-
end)
71-
72-
Enum.each(reachable_defs, fn({name, _type, _, _clauses}) ->
73-
ModuleState.add_used(state.pid, module, name)
74-
end)
57+
reachable_def = Enum.find(Map.get(info, :definitions, []), fn { name, _, _, _} -> name == function end)
7558

76-
Enum.each(reachable_defs, &walk(&1, state))
59+
case reachable_def do
60+
nil ->
61+
nil
62+
{name, _type, _, _clauses} = func ->
63+
ModuleState.add_used(state.pid, module, name)
64+
walk(func, state)
65+
end
7766
end
7867
end
7968

@@ -105,6 +94,15 @@ defmodule ElixirScript.FindUsedFunctions do
10594
walk({[], params, [], body}, state)
10695
end
10796

97+
defp walk({:|, _, [head, tail]}, state) do
98+
walk(head, state)
99+
walk(tail, state)
100+
end
101+
102+
defp walk({:::, _, _}, state) do
103+
nil
104+
end
105+
108106
defp walk(form, state) when is_list(form) do
109107
Enum.each(form, &walk(&1, state))
110108
end
@@ -234,10 +232,6 @@ defmodule ElixirScript.FindUsedFunctions do
234232
walk(params, state)
235233
end
236234

237-
defp walk({function, _, params}, state) when function in [:|, :::] do
238-
nil
239-
end
240-
241235
defp walk({function, _, params}, state) when is_atom(function) and is_list(params) do
242236
walk_module(state.module, function, length(params), state.pid)
243237
Enum.each(params, &walk(&1, state))

lib/elixir_script/next/passes/find_used_modules.ex

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,21 @@ defmodule ElixirScript.FindUsedModules do
9999
walk({[], params, [], body}, state)
100100
end
101101

102+
defp walk({:|, _, [head, tail]}, state) do
103+
walk(head, state)
104+
walk(tail, state)
105+
end
106+
107+
defp walk({:::, _, _}, state) do
108+
nil
109+
end
110+
102111
defp walk(form, state) when is_list(form) do
103112
Enum.each(form, &walk(&1, state))
104113
end
105114

106115
defp walk(form, state) when is_atom(form) and form not in [BitString, Function, PID, Port, Reference, Any, Elixir] do
107-
if ElixirScript.Translate.Module.is_elixir_module(form) do
116+
if ElixirScript.Translate.Module.is_elixir_module(form) and !ElixirScript.Translate.Module.is_js_module(form, state) do
108117
if ModuleState.get_module(state.pid, form) == nil do
109118
execute(form, state.pid)
110119
end
@@ -133,7 +142,7 @@ defmodule ElixirScript.FindUsedModules do
133142
end
134143

135144
defp walk({:%, _, [module, params]}, state) do
136-
if ElixirScript.Translate.Module.is_elixir_module(module) do
145+
if ElixirScript.Translate.Module.is_elixir_module(module) and !ElixirScript.Translate.Module.is_js_module(module, state) do
137146
if ModuleState.get_module(state.pid, module) == nil do
138147
do_execute(module, state.pid)
139148
end
@@ -233,7 +242,6 @@ defmodule ElixirScript.FindUsedModules do
233242
if ModuleState.get_module(state.pid, module) == nil do
234243
execute(module, state.pid)
235244
end
236-
ModuleState.add_used(state.pid, module, {function, length(params)})
237245
true ->
238246
nil
239247
end
@@ -245,8 +253,7 @@ defmodule ElixirScript.FindUsedModules do
245253
walk(params, state)
246254
end
247255

248-
defp walk({function, _, params}, state) when is_atom(function) and is_list(params) do
249-
ModuleState.add_used(state.pid, state.module, {function, length(params)})
256+
defp walk({function, _, params}, state) when is_atom(function) and is_list(params) do
250257
Enum.each(params, &walk(&1, state))
251258
end
252259

lib/elixir_script/next/passes/translate/examples/example.ex

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

lib/elixir_script/next/passes/translate/examples/size.ex

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

lib/elixir_script/next/passes/translate/form.ex

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ defmodule ElixirScript.Translate.Form do
2424
{ J.literal(form), state }
2525
end
2626

27+
def compile({:|, _, [head, tail]}, state) do
28+
ast = J.call_expression(
29+
J.member_expression(
30+
J.array_expression([compile!(head, state)]),
31+
J.identifier("concat")
32+
),
33+
[compile!(tail, state)]
34+
)
35+
36+
{ ast, state }
37+
end
38+
2739
def compile(form, state) when is_list(form) do
2840
ast = J.array_expression(
2941
Enum.map(form, &compile!(&1, state))
@@ -151,7 +163,7 @@ defmodule ElixirScript.Translate.Form do
151163
def compile({:receive, context, [blocks]}, state) do
152164
line = Keyword.get(context, :line, 1)
153165
{function, arity} = Map.get(state, :function)
154-
Logger.warn "receive not supported, Module: #{inspect state.module}, Function: #{function}/#{arity}, Line: #{line}"
166+
Logger.warn "receive not supported, Module: #{inspect state.module}, Function: #{function}, Line: #{line}"
155167
Receive.compile(blocks, state)
156168
end
157169

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@ defmodule ElixirScript.Translate.Forms.Remote do
143143
def process_module_name(module, state) when is_atom(module) do
144144
cond do
145145
ElixirScript.Translate.Module.is_js_module(module, state) ->
146-
members = tl(Module.split(module))
147-
Identifier.make_namespace_members(members)
146+
process_js_module_name(module, state)
148147
module === Elixir ->
149148
members = ["Elixir", "__load"]
150149

@@ -168,6 +167,23 @@ defmodule ElixirScript.Translate.Forms.Remote do
168167
Form.compile!(module, state)
169168
end
170169

170+
defp process_js_module_name(module, state) do
171+
case Module.split(module) do
172+
["JS"] ->
173+
J.member_expression(
174+
J.member_expression(
175+
J.identifier("Bootstrap"),
176+
J.identifier("Core")
177+
),
178+
J.identifier("global")
179+
)
180+
["JS" | rest] ->
181+
Identifier.make_namespace_members(rest)
182+
x ->
183+
Identifier.make_namespace_members(x)
184+
end
185+
end
186+
171187
defp erlang_compat_function(module, function) do
172188
J.member_expression(
173189
J.member_expression(

lib/elixir_script/next/passes/translate/module.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ defmodule ElixirScript.Translate.Module do
5757
# any public functions
5858
case exports do
5959
%ESTree.ObjectExpression{ properties: [] } ->
60-
ModuleState.put_module(pid, module, Map.put(info, :js_ast, J.program([])))
60+
nil
6161
_ ->
6262
{ compiled_functions, _ } = Enum.map_reduce(combined_defs, state, &Function.compile(&1, &2))
6363

lib/elixir_script/next/passes/translate/module_state.ex

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

priv/std_lib/string.ex

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ defmodule ElixirScript.String do
199199
end
200200

201201
def valid_character?(codepoint) do
202-
ElixirScript.Bootstrap.Functions.is_valid_character(codepoint)
202+
try do
203+
JS.String.fromCodePoint(codepoint) != nil
204+
rescue
205+
_ ->
206+
false
207+
end
203208
end
204209
end

0 commit comments

Comments
 (0)