Skip to content

Commit 7516df6

Browse files
committed
renaming for easy refactoring later
1 parent 41cbc82 commit 7516df6

11 files changed

+273
-141
lines changed

jscomp/bin/whole_compiler.ml

+71-70
Large diffs are not rendered by default.

jscomp/core/js_output.ml

+10-10
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,17 @@ let handle_name_tail
6262
(should_return : Lam_compile_defs.return_type)
6363
lam (exp : J.expression) : t =
6464
begin match name, should_return with
65-
| EffectCall, False ->
65+
| EffectCall, ReturnFalse ->
6666
if Lam_analysis.no_side_effects lam
6767
then dummy
6868
else {block = []; value = Some exp ; finished = False}
69-
| EffectCall, True _ ->
69+
| EffectCall, ReturnTrue _ ->
7070
make [S.return exp] ~finished:True
71-
| Declare (kind, n), False ->
71+
| Declare (kind, n), ReturnFalse ->
7272
make [ S.define ~kind n exp]
73-
| Assign n ,False ->
73+
| Assign n ,ReturnFalse ->
7474
make [S.assign n exp ]
75-
| (Declare _ | Assign _ ), True _ ->
75+
| (Declare _ | Assign _ ), ReturnTrue _ ->
7676
make [S.unknown_lambda lam] ~finished:True
7777
| NeedValue, _ -> {block = []; value = Some exp; finished = False }
7878
end
@@ -82,12 +82,12 @@ let handle_block_return
8282
(should_return : Lam_compile_defs.return_type)
8383
(lam : Lam.t) (block : J.block) exp : t =
8484
match st, should_return with
85-
| Declare (kind,n), False ->
85+
| Declare (kind,n), ReturnFalse ->
8686
make (block @ [ S.define ~kind n exp])
87-
| Assign n, False -> make (block @ [S.assign n exp])
88-
| (Declare _ | Assign _), True _ -> make [S.unknown_lambda lam] ~finished:True
89-
| EffectCall, False -> make block ~value:exp
90-
| EffectCall, True _ -> make (block @ [S.return exp]) ~finished:True
87+
| Assign n, ReturnFalse -> make (block @ [S.assign n exp])
88+
| (Declare _ | Assign _), ReturnTrue _ -> make [S.unknown_lambda lam] ~finished:True
89+
| EffectCall, ReturnFalse -> make block ~value:exp
90+
| EffectCall, ReturnTrue _ -> make (block @ [S.return exp]) ~finished:True
9191
| NeedValue, _ -> make block ~value:exp
9292

9393
let statement_of_opt_expr (x : J.expression option) : J.statement =

jscomp/core/lam_compile.ml

+52-51
Large diffs are not rendered by default.

jscomp/core/lam_compile_defs.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ type return_label = {
5555
}
5656

5757
type return_type =
58-
| False
59-
| True of return_label option
58+
| ReturnFalse
59+
| ReturnTrue of return_label option
6060
(* have a mutable field to notifiy it's actually triggered *)
6161
(* anonoymous function does not have identifier *)
6262

jscomp/core/lam_compile_defs.mli

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ type return_label = {
6767
}
6868

6969
type return_type =
70-
| False
71-
| True of return_label option (* anonoymous function does not have identifier *)
70+
| ReturnFalse
71+
| ReturnTrue of return_label option (* anonoymous function does not have identifier *)
7272

7373
(* delegate to the callee to generate expression
7474
Invariant: [output] should return a trailing expression

jscomp/core/lam_compile_group.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -151,22 +151,22 @@ let compile_group ({filename = file_name; env;} as meta : Lam_stats.meta)
151151
(* can not apply again, it's wrong USE it with care*)
152152
(* ([Js_stmt_make.comment (Gen_of_env.query_type id env )], None) ++ *)
153153
Lam_compile.compile_let kind { st = Declare (kind, id);
154-
should_return = False;
154+
should_return = ReturnFalse;
155155
jmp_table = Lam_compile_defs.empty_handler_map;
156156
meta
157157
} id lam
158158

159159
| Recursive id_lams, _ ->
160160
Lam_compile.compile_recursive_lets
161161
{ st = EffectCall ;
162-
should_return = False;
162+
should_return = ReturnFalse;
163163
jmp_table = Lam_compile_defs.empty_handler_map;
164164
meta
165165
}
166166
id_lams
167167
| Nop lam, _ -> (* TODO: Side effect callls, log and see statistics *)
168168
Lam_compile.compile_lambda {st = EffectCall;
169-
should_return = False;
169+
should_return = ReturnFalse;
170170
jmp_table = Lam_compile_defs.empty_handler_map;
171171
meta
172172
} lam

jscomp/core/lam_compile_primitive.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ module E = Js_exp_make
3636
*)
3737
let decorate_side_effect ({st; should_return;_} : Lam_compile_defs.cxt) e : E.t =
3838
match st, should_return with
39-
| _, True _
39+
| _, ReturnTrue _
4040
| (Assign _ | Declare _ | NeedValue), _ -> E.seq e E.unit
41-
| EffectCall, False -> e
41+
| EffectCall, ReturnFalse -> e
4242
(* NeedValue should return a meaningful expression*)
4343

4444
let translate loc

jscomp/test/.depend

+1
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ gpr_1600_test.cmj : ../runtime/js.cmj ../stdlib/array.cmj
227227
gpr_1658_test.cmj : mt.cmj ../runtime/js.cmj
228228
gpr_1667_test.cmj : mt.cmj
229229
gpr_1692_test.cmj :
230+
gpr_1701_test.cmj : ../stdlib/list.cmj
230231
gpr_405_test.cmj : ../stdlib/hashtbl.cmj gpr_405_test.cmi
231232
gpr_441.cmj :
232233
gpr_459_test.cmj : mt.cmj

jscomp/test/Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ OTHERS := literals a test_ari test_export2 test_internalOO test_obj_simple_ffi t
160160
js_option_test\
161161
gpr_1658_test\
162162
gpr_1667_test\
163-
gpr_1692_test
163+
gpr_1692_test\
164+
gpr_1701_test
164165

165166
# bs_uncurry_test
166167
# needs Lam to get rid of Uncurry arity first

jscomp/test/gpr_1701_test.js

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
'use strict';
2+
3+
var List = require("../../lib/js/list.js");
4+
var Pervasives = require("../../lib/js/pervasives.js");
5+
var Caml_exceptions = require("../../lib/js/caml_exceptions.js");
6+
var Caml_builtin_exceptions = require("../../lib/js/caml_builtin_exceptions.js");
7+
8+
var Foo = Caml_exceptions.create("Gpr_1701_test.Foo");
9+
10+
function test(_n) {
11+
while(true) {
12+
var n = _n;
13+
if (n) {
14+
try {
15+
_n = n - 1 | 0;
16+
continue ;
17+
18+
}
19+
catch (exn){
20+
if (exn === Foo) {
21+
return /* () */0;
22+
} else {
23+
throw exn;
24+
}
25+
}
26+
} else {
27+
throw Foo;
28+
}
29+
};
30+
}
31+
32+
test(100);
33+
34+
function read_lines(inc) {
35+
var _acc = /* [] */0;
36+
while(true) {
37+
var acc = _acc;
38+
var match;
39+
try {
40+
match = /* Some */[Pervasives.input_line(inc)];
41+
}
42+
catch (exn){
43+
if (exn === Caml_builtin_exceptions.end_of_file) {
44+
match = /* None */0;
45+
} else {
46+
throw exn;
47+
}
48+
}
49+
if (match) {
50+
_acc = /* :: */[
51+
match[0],
52+
acc
53+
];
54+
continue ;
55+
56+
} else {
57+
return List.rev(acc);
58+
}
59+
};
60+
}
61+
62+
function read_lines2(inc) {
63+
var _acc = /* [] */0;
64+
while(true) {
65+
var acc = _acc;
66+
var exit = 0;
67+
var l;
68+
try {
69+
l = Pervasives.input_line(inc);
70+
exit = 1;
71+
}
72+
catch (exn){
73+
if (exn === Caml_builtin_exceptions.end_of_file) {
74+
return List.rev(acc);
75+
} else {
76+
throw exn;
77+
}
78+
}
79+
if (exit === 1) {
80+
_acc = /* :: */[
81+
l,
82+
acc
83+
];
84+
continue ;
85+
86+
}
87+
88+
};
89+
}
90+
91+
exports.Foo = Foo;
92+
exports.test = test;
93+
exports.read_lines = read_lines;
94+
exports.read_lines2 = read_lines2;
95+
/* Not a pure module */

jscomp/test/gpr_1701_test.ml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
3+
exception Foo
4+
5+
let rec test n =
6+
if n = 0 then raise Foo
7+
else
8+
try
9+
test (n - 1)
10+
with Foo ->()
11+
12+
13+
let () = test 100
14+
15+
16+
17+
let read_lines inc =
18+
let rec loop acc =
19+
match (try Some (input_line inc)
20+
with End_of_file -> None)
21+
with
22+
| Some l -> loop (l :: acc)
23+
| None -> List.rev acc
24+
in
25+
loop []
26+
27+
let read_lines2 inc =
28+
let rec loop acc =
29+
match input_line inc with
30+
| l -> loop (l :: acc)
31+
| exception End_of_file -> List.rev acc
32+
in
33+
loop []

0 commit comments

Comments
 (0)