Skip to content

Commit c1f6574

Browse files
committed
Stopped doing steps on modules in different processes
1 parent 2197174 commit c1f6574

File tree

5 files changed

+43
-62
lines changed

5 files changed

+43
-62
lines changed

lib/elixir_script.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ defmodule ElixirScript do
199199
|> ElixirScript.Passes.FindFunctions.execute(opts)
200200
|> ElixirScript.Passes.JavaScriptAST.execute(opts)
201201
|> ElixirScript.Passes.ConsolidateProtocols.execute(opts)
202-
|> ElixirScript.Passes.CreateJSModules.execute(opts)
203202
|> ElixirScript.Passes.JavaScriptCode.execute(opts)
204203
|> ElixirScript.Passes.JavaScriptName.execute(opts)
205204
|> ElixirScript.Passes.HandleOutput.execute(opts)

lib/elixir_script/passes/create_js_modules.ex

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,9 @@ defmodule ElixirScript.Passes.CreateJSModules do
44

55
def execute(compiler_data, opts) do
66
parent = self
7-
8-
data = Enum.map(compiler_data.data, fn({module_name, module_data}) ->
9-
10-
spawn_link fn ->
7+
data = Enum.map(compiler_data.data, fn({module_name, module_data}) ->
118
module_data = compile(module_data, opts, compiler_data.state)
12-
result = {module_name, module_data}
13-
send parent, {self, result }
14-
end
15-
16-
end)
17-
|> Enum.map(fn pid ->
18-
receive do
19-
{^pid, result} ->
20-
result
21-
end
9+
{module_name, module_data}
2210
end)
2311

2412
%{ compiler_data | data: data }

lib/elixir_script/passes/java_script_ast.ex

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,9 @@ defmodule ElixirScript.Passes.JavaScriptAST do
88
State.set_module_data(compiler_data.state, compiler_data.data)
99
State.set_loaded_modules(compiler_data.state, Map.get(compiler_data, :loaded_modules, []))
1010

11-
parent = self
12-
13-
data = State.get_module_data(compiler_data.state)
14-
|> Enum.map(fn({module_name, module_data}) ->
15-
16-
spawn_link fn ->
11+
data = Enum.map(State.get_module_data(compiler_data.state), fn({module_name, module_data}) ->
1712
module_data = compile(module_data, opts, compiler_data.state)
18-
result = {module_name, module_data}
19-
send parent, {self, result }
20-
end
21-
22-
end)
23-
|> Enum.map(fn pid ->
24-
receive do
25-
{^pid, result} ->
26-
result
27-
end
13+
{module_name, module_data}
2814
end)
2915

3016
%{ compiler_data | data: data }

lib/elixir_script/passes/java_script_code.ex

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,9 @@ defmodule ElixirScript.Passes.JavaScriptCode do
55
def execute(compiler_data, _) do
66
parent = self
77

8-
data = Enum.map(compiler_data.data, fn({module_name, module_data}) ->
9-
10-
spawn_link fn ->
8+
data = Enum.map(compiler_data.data, fn({module_name, module_data}) ->
119
module_data = compile(module_data)
12-
result = {module_name, module_data}
13-
send parent, {self, result }
14-
end
15-
16-
end)
17-
|> Enum.map(fn pid ->
18-
receive do
19-
{^pid, result} ->
20-
result
21-
end
10+
{module_name, module_data}
2211
end)
2312

2413
%{ compiler_data | data: data }
@@ -28,7 +17,6 @@ defmodule ElixirScript.Passes.JavaScriptCode do
2817
module_data
2918
end
3019

31-
3220
defp compile(module_data) do
3321
js_ast = Builder.program(List.wrap(module_data.javascript_ast))
3422

src/javascript/lib/core/functions.js

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import Protocol from './protocol';
2-
import Core from '../core';
1+
import Protocol from "./protocol";
2+
import Core from "../core";
33

44
function call_property(item, property) {
55
let prop = null;
66

77
if (
8-
typeof item === 'number' ||
9-
typeof item === 'symbol' ||
10-
typeof item === 'boolean' ||
11-
typeof item === 'string'
8+
typeof item === "number" ||
9+
typeof item === "symbol" ||
10+
typeof item === "boolean" ||
11+
typeof item === "string"
1212
) {
1313
if (item[property] !== undefined) {
1414
prop = property;
@@ -50,15 +50,15 @@ function contains(left, right) {
5050
}
5151

5252
function get_global() {
53-
if (typeof self !== 'undefined') {
53+
if (typeof self !== "undefined") {
5454
return self;
55-
} else if (typeof window !== 'undefined') {
55+
} else if (typeof window !== "undefined") {
5656
return window;
57-
} else if (typeof global !== 'undefined') {
57+
} else if (typeof global !== "undefined") {
5858
return global;
5959
}
6060

61-
throw new Error('No global state found');
61+
throw new Error("No global state found");
6262
}
6363

6464
function defstruct(defaults) {
@@ -78,15 +78,15 @@ function defstruct(defaults) {
7878
function defexception(defaults) {
7979
return class extends Error {
8080
constructor(update = {}) {
81-
const message = update.message || '';
81+
const message = update.message || "";
8282
super(message);
8383

8484
const the_values = Object.assign(defaults, update);
8585
Object.assign(this, the_values);
8686

8787
this.name = this.constructor.name;
8888
this.message = message;
89-
this[Symbol.for('__exception__')] = true;
89+
this[Symbol.for("__exception__")] = true;
9090
Error.captureStackTrace(this, this.constructor.name);
9191
}
9292

@@ -121,7 +121,7 @@ function is_valid_character(codepoint) {
121121
function b64EncodeUnicode(str) {
122122
return btoa(
123123
encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, (match, p1) =>
124-
String.fromCharCode(`0x${p1}`)),
124+
String.fromCharCode(`0x${p1}`))
125125
);
126126
}
127127

@@ -148,7 +148,7 @@ function update_map(map, property, value) {
148148
return add_property_to_map(map, property, value);
149149
}
150150

151-
throw 'map does not have key';
151+
throw "map does not have key";
152152
}
153153

154154
function bnot(expr) {
@@ -213,7 +213,7 @@ function can_decode64(data) {
213213
function remove_from_list(list, element) {
214214
let found = false;
215215

216-
return list.filter((elem) => {
216+
return list.filter(elem => {
217217
if (!found && elem === element) {
218218
found = true;
219219
return false;
@@ -309,9 +309,9 @@ function reverse(list) {
309309

310310
function maps_find(key, map) {
311311
if (key in get_object_keys(map)) {
312-
return new Core.Tuple(Symbol.for('ok'), map[key]);
312+
return new Core.Tuple(Symbol.for("ok"), map[key]);
313313
}
314-
return Symbol.for('error');
314+
return Symbol.for("error");
315315
}
316316

317317
function flatten(list, tail = []) {
@@ -377,6 +377,25 @@ function maps_fold(fun, acc, map) {
377377
return acc1;
378378
}
379379

380+
function build_namespace(ns, ns_string) {
381+
let parts = ns_string.split(".");
382+
let parent = ns;
383+
384+
if (parts[0] === "Elixir") {
385+
parts = parts.slice(1);
386+
}
387+
388+
for (const part of parts) {
389+
if (typeof parent[part] === "undefined") {
390+
parent[part] = {};
391+
}
392+
393+
parent = parent[part];
394+
}
395+
396+
return parent;
397+
}
398+
380399
export default {
381400
call_property,
382401
apply,
@@ -416,4 +435,5 @@ export default {
416435
mapfoldl,
417436
filtermap,
418437
maps_fold,
438+
build_namespace
419439
};

0 commit comments

Comments
 (0)