Skip to content

Commit 2779c00

Browse files
committed
Add in_process to lexical_scope. Removed created of generators
1 parent a6d3fab commit 2779c00

File tree

5 files changed

+21
-13
lines changed

5 files changed

+21
-13
lines changed

lib/elixir_script/translator/kernel/special_forms/block.ex

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,33 @@ defmodule ElixirScript.Translator.Block do
66
def make_block(expressions, env) do
77
{ list, env } = Enum.map_reduce(expressions, env, fn(x, updated_env) ->
88
{item, updated_env } = Translator.translate(x, updated_env)
9-
{process_call(item), updated_env}
9+
{process_call(item, env), updated_env}
1010
end)
1111

1212
{ JS.block_statement(list), env }
1313
end
1414

15-
defp process_call(item) do
15+
def process_call(item, %ElixirScript.Translator.LexicalScope{ in_process: true }) do
1616
case item do
1717
%ESTree.CallExpression{ callee: %ESTree.MemberExpression{ object: %ESTree.Identifier{ name: "Object" }, property: %ESTree.Identifier{ name: "freeze" }} } ->
1818
item
1919
%ESTree.CallExpression{ callee: %ESTree.MemberExpression{ object: %ESTree.Identifier{ name: "Symbol" }, property: %ESTree.Identifier{ name: "for" }} } ->
2020
item
2121
%ESTree.CallExpression{}->
22-
item
22+
JS.yield_expression(item, true)
2323
%ESTree.BinaryExpression{ left: %ESTree.CallExpression{} }->
24-
item
24+
JS.yield_expression(item, true)
2525
%ESTree.BinaryExpression{ right: %ESTree.CallExpression{} }->
26-
item
26+
JS.yield_expression(item, true)
2727
_ ->
2828
item
2929
end
3030
end
3131

32+
def process_call(item, _) do
33+
item
34+
end
35+
3236
defp make_gen_call(func, params) do
3337
JS.call_expression(
3438
JS.member_expression(

lib/elixir_script/translator/kernel/special_forms/fn.ex

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ defmodule ElixirScript.Translator.Function do
44
alias ElixirScript.Translator
55
alias ElixirScript.Translator.Group
66
alias ElixirScript.Translator.PatternMatching
7+
alias ElixirScript.Translator.Block
78

89
@patterns JS.member_expression(
910
JS.member_expression(
@@ -63,7 +64,7 @@ defmodule ElixirScript.Translator.Function do
6364

6465
if guards do
6566
{ guard_body, _ } = hd(List.wrap(guards))
66-
|> prepare_function_body(env)
67+
|> prepare_function_body(%{ env | context: :guard})
6768

6869
guard_body = JS.block_statement(guard_body)
6970
make_function_clause(patterns, params, body, guard_body)
@@ -103,11 +104,11 @@ defmodule ElixirScript.Translator.Function do
103104
def make_function_clause(patterns, params, body, guard_body) do
104105
arguments = [
105106
JS.array_expression(patterns),
106-
JS.function_expression(params, [], body, true),
107+
JS.function_expression(params, [], body),
107108
]
108109

109110
if guard_body do
110-
arguments = arguments ++ [JS.function_expression(params, [], guard_body, true)]
111+
arguments = arguments ++ [JS.function_expression(params, [], guard_body)]
111112
end
112113

113114
JS.call_expression(
@@ -138,6 +139,7 @@ defmodule ElixirScript.Translator.Function do
138139
end
139140

140141
list = Group.inflate_groups(list)
142+
|> Enum.map(fn(x) -> Block.process_call(x, env) end)
141143
|> return_last_expression
142144

143145
{ list, env }
@@ -160,7 +162,7 @@ defmodule ElixirScript.Translator.Function do
160162

161163
last_item = case last_item do
162164
%ESTree.YieldExpression{} ->
163-
JS.return_statement(last_item)
165+
JS.return_statement(last_item)
164166
%ESTree.Literal{} ->
165167
JS.return_statement(last_item)
166168
%ESTree.Identifier{} ->

lib/elixir_script/translator/lexical_scope.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ defmodule ElixirScript.Translator.LexicalScope do
1717
export_vars: [{atom, atom | non_neg_integer}] | nil,
1818
lexical_tracker: nil,
1919
caller: t | nil,
20+
in_process: boolean,
2021
env: nil
2122
}
2223

@@ -36,6 +37,7 @@ defmodule ElixirScript.Translator.LexicalScope do
3637
export_vars: nil,
3738
lexical_tracker: nil,
3839
caller: nil,
40+
in_process: false,
3941
env: nil
4042
]
4143

src/javascript/lib/core/functions.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import BitString from './bit_string';
33
import Patterns from './patterns';
44
import Protocol from './protocol';
55

6-
function* call_property(item, property){
6+
function call_property(item, property){
77
let prop = null;
88

99
if(typeof item === "number" || typeof item === "symbol" || typeof item === "boolean" || typeof item === "string"){
@@ -25,9 +25,9 @@ function* call_property(item, property){
2525
}
2626

2727
if(item[prop] instanceof Function){
28-
return yield* item[prop]();
28+
return item[prop]();
2929
}else{
30-
return yield item[prop];
30+
return item[prop];
3131
}
3232
}
3333

src/javascript/lib/core/patterns/defmatch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function make_case(pattern: Array<any>, fn: Function, guard: Function = (
4343
}
4444

4545
export function defmatch(...cases: Array<Case>): Function {
46-
return function* (...args: Array<any>): any {
46+
return function (...args: Array<any>): any {
4747
for (let processedCase of cases) {
4848
let result = [];
4949
args = fillInOptionalValues(args, processedCase.arity, processedCase.optionals);

0 commit comments

Comments
 (0)