Skip to content

Commit 5c0ef8b

Browse files
committed
Some bug fixes. Add elixir_config erlang compat module
1 parent 51f9576 commit 5c0ef8b

File tree

13 files changed

+124
-50
lines changed

13 files changed

+124
-50
lines changed

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
erlang 20.0
22
elixir 1.5.0-otp-20
3-
nodejs 8.2.0
3+
nodejs 8.2.1

lib/elixir_script/passes/translate/clause.ex

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ defmodule ElixirScript.Translate.Clause do
22
alias ESTree.Tools.Builder, as: J
33
alias ElixirScript.Translate.Form
44
alias ElixirScript.Translate.Forms.Pattern
5+
alias ElixirScript.Translate.Function
56

67
@moduledoc """
78
Handles translation of all of the clause ASTs
@@ -19,20 +20,7 @@ defmodule ElixirScript.Translate.Clause do
1920
{patterns, params, state} = Pattern.compile(args, state)
2021
guard = compile_guard(params, guards, state)
2122

22-
body = case body do
23-
nil ->
24-
J.identifier("null")
25-
{:__block__, _, block_body} ->
26-
{list, _} = Enum.map_reduce(block_body, state, &Form.compile(&1, &2))
27-
List.flatten(list)
28-
b when is_list(b) ->
29-
{list, _} = Enum.map_reduce(b, state, &Form.compile(&1, &2))
30-
List.flatten(list)
31-
_ ->
32-
Form.compile!(body, state)
33-
|> List.wrap
34-
|> List.flatten
35-
end
23+
{body, _state} = Function.compile_block(body, state)
3624

3725
body = body
3826
|> return_last_statement

lib/elixir_script/passes/translate/form.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ defmodule ElixirScript.Translate.Form do
102102
ElixirScript.Translate.Forms.Map.compile(map, state)
103103
end
104104

105+
def compile({:<<>>, _, []} = bitstring, state) do
106+
Bitstring.compile(bitstring, state)
107+
end
108+
105109
def compile({:<<>>, _, elements} = bitstring, state) do
106110
is_interpolated_string = Enum.all?(elements, fn(x) ->
107111
case x do

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ defmodule ElixirScript.Translate.Forms.Bitstring do
2727
do_compile_element({:binary, Form.compile!(element, state)})
2828
end
2929

30-
def compile_element({:<<>>, [], elements}, state) do
30+
def compile_element({:<<>>, _, elements}, state) do
3131
{ast, _} = compile(elements, state)
3232
ast
3333
end

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ defmodule ElixirScript.Translate.Forms.Remote do
1111
:lists,
1212
:gen,
1313
:elixir_errors,
14+
:elixir_config,
1415
:supervisor,
1516
:application,
1617
:code,

lib/elixir_script/passes/translate/module.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ defmodule ElixirScript.Translate.Module do
6060

6161
#we combine our function arities
6262
combined_defs = combine_defs(used_defs)
63-
exports = make_exports(module, combined_defs, defs, state)
63+
exports = make_exports(module, combined_defs)
6464

6565
# If there are no public exports, skip compilation
6666
case exports do
@@ -93,7 +93,7 @@ defmodule ElixirScript.Translate.Module do
9393
end)
9494
end
9595

96-
defp make_exports(module, reachable_defs, definitions, state) do
96+
defp make_exports(module, reachable_defs) do
9797
exports = Enum.reduce(reachable_defs, [], fn
9898
{{name, _arity}, :def, _, _}, list ->
9999
function_name = ElixirScript.Translate.Identifier.make_identifier(name)

package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,20 @@
3030
"babel-core": "^6.24.0",
3131
"babel-preset-env": "^1.6.0",
3232
"babel-register": "^6.24.0",
33-
"eslint": "^4.2.0",
34-
"eslint-config-airbnb-base": "^11.1.0",
33+
"eslint": "^4.3.0",
34+
"eslint-config-airbnb-base": "^11.3.1",
3535
"eslint-plugin-import": "^2.7.0",
36-
"nyc": "^11.0.3",
36+
"nyc": "^11.1.0",
3737
"rollup": "^0.45.2",
3838
"rollup-plugin-babel": "^2.7.1",
3939
"rollup-plugin-babili": "^3.1.0",
4040
"rollup-plugin-node-resolve": "^3.0.0",
41-
"sinon": "^2.3.8"
41+
"sinon": "^2.4.1"
4242
},
4343
"ava": {
44-
"require": ["babel-register"],
44+
"require": [
45+
"babel-register"
46+
],
4547
"babel": {
4648
"babelrc": true
4749
}

priv/build/iife/ElixirScript.Core.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/javascript/lib/core.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import erlang from './core/erlang_compat/erlang';
66
import maps from './core/erlang_compat/maps';
77
import lists from './core/erlang_compat/lists';
88
import elixir_errors from './core/erlang_compat/elixir_errors';
9+
import elixir_config from './core/erlang_compat/elixir_config';
910
import io from './core/erlang_compat/io';
1011
import binary from './core/erlang_compat/binary';
1112
import unicode from './core/erlang_compat/unicode';
@@ -49,5 +50,6 @@ export default {
4950
elixir_errors,
5051
io,
5152
binary,
52-
unicode
53+
unicode,
54+
elixir_config
5355
};
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const MODULE = Symbol.for('elixir_config');
2+
const ets = new Map();
3+
4+
function _new(opts) {
5+
ets.set(MODULE, new Map());
6+
ets.get(MODULE).set(MODULE, opts);
7+
return MODULE;
8+
}
9+
10+
function _delete(module) {
11+
ets.delete(module);
12+
return true;
13+
}
14+
15+
function put(key, value) {
16+
ets.get(MODULE).set(key, value);
17+
return Symbol.for('ok');
18+
}
19+
20+
function get(key) {
21+
return ets.get(MODULE).get(key);
22+
}
23+
24+
function update(key, fun) {
25+
const value = fun(ets.get(MODULE).get(key));
26+
put(key, value);
27+
return value;
28+
}
29+
30+
function get_and_put(key, value) {
31+
const oldValue = get(key);
32+
put(key, value);
33+
return oldValue;
34+
}
35+
36+
export default {
37+
new: _new,
38+
delete: _delete,
39+
put,
40+
get,
41+
update,
42+
get_and_put
43+
};

0 commit comments

Comments
 (0)