Skip to content

Commit ced601f

Browse files
committed
reomove Sys.getenv ad-hoc processing
1 parent f371681 commit ced601f

File tree

4 files changed

+24
-49
lines changed

4 files changed

+24
-49
lines changed

jscomp/core/lam_compile.ml

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,27 +1564,6 @@ and
15641564
| NeedValue, _ ->
15651565
Js_output.make block ~value:E.unit
15661566
end
1567-
| (Ltrywith(
1568-
(Lprim {primitive = Pccall {prim_name = "caml_sys_getenv"; _};
1569-
args = [Lconst _]} as body),
1570-
id,
1571-
Lifthenelse
1572-
(Lprim{primitive = Pintcomp(Ceq);
1573-
args = [Lvar id2 ;
1574-
Lprim{primitive = Pglobal_exception {name = "Not_found"}; _}]},
1575-
cont, _reraise )
1576-
)
1577-
| Ltrywith(
1578-
(Lprim {primitive = Pccall {prim_name = "caml_sys_getenv"; _};
1579-
args = [Lconst _]} as body),
1580-
id,
1581-
Lifthenelse(Lprim{primitive = Pintcomp(Ceq);
1582-
args = [
1583-
Lprim { primitive = Pglobal_exception {name = "Not_found"; _}; _}; Lvar id2 ]},
1584-
cont, _reraise )
1585-
)) when Ident.same id id2
1586-
->
1587-
compile_lambda cxt (Lam.try_ body id cont)
15881567
| Ltrywith(lam,id, catch) -> (* generate documentation *)
15891568
(*
15901569
tail --> should be renamed to `shouldReturn`

jscomp/test/caml_sys_poly_fill_test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var Mt = require("./mt.js");
44
var Block = require("../../lib/js/block.js");
55
var Caml_sys = require("../../lib/js/caml_sys.js");
66
var Node_process = require("../../lib/js/node_process.js");
7+
var Caml_builtin_exceptions = require("../../lib/js/caml_builtin_exceptions.js");
78

89
var suites = [/* [] */0];
910

@@ -46,7 +47,11 @@ try {
4647
tmp = Caml_sys.caml_sys_getenv("caml_sys_poly_fill_test.ml");
4748
}
4849
catch (exn){
49-
tmp = "Z";
50+
if (exn === Caml_builtin_exceptions.not_found) {
51+
tmp = "Z";
52+
} else {
53+
throw exn;
54+
}
5055
}
5156

5257
eq("File \"caml_sys_poly_fill_test.ml\", line 23, characters 5-12", "Z", tmp);

lib/js/filename.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,11 @@ try {
131131
temp_dir_name = Caml_sys.caml_sys_getenv("TMPDIR");
132132
}
133133
catch (exn){
134-
temp_dir_name = "/tmp";
134+
if (exn === Caml_builtin_exceptions.not_found) {
135+
temp_dir_name = "/tmp";
136+
} else {
137+
throw exn;
138+
}
135139
}
136140

137141
function quote(param) {
@@ -165,7 +169,11 @@ try {
165169
temp_dir_name$1 = Caml_sys.caml_sys_getenv("TEMP");
166170
}
167171
catch (exn$1){
168-
temp_dir_name$1 = ".";
172+
if (exn$1 === Caml_builtin_exceptions.not_found) {
173+
temp_dir_name$1 = ".";
174+
} else {
175+
throw exn$1;
176+
}
169177
}
170178

171179
var temp_dir_name$2 = temp_dir_name;

lib/whole_compiler.ml

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -97858,16 +97858,20 @@ and compile_general_cases
9785897858
(fun group ->
9785997859
Ext_list.map_last
9786097860
(fun last (switch_case,lam) ->
97861-
let switch_block, should_break =
97861+
(* let switch_block, should_break =
9786297862
Js_output.to_break_block (compile_lambda cxt lam) in
9786397863
let should_break =
9786497864
match cxt.should_return with
9786597865
| ReturnFalse -> should_break
9786697866
| ReturnTrue _ -> false
97867-
in
97867+
in *)
97868+
9786897869
if last
97869-
then {J.switch_case ;
97870-
switch_body = switch_block, should_break
97870+
then
97871+
(* merge and shared *)
97872+
let switch_body = Js_output.to_break_block (compile_lambda cxt lam) in
97873+
{J.switch_case ;
97874+
switch_body
9787197875
}
9787297876
else
9787397877
{ switch_case; switch_body = [],false }
@@ -98930,27 +98934,6 @@ and
9893098934
| NeedValue, _ ->
9893198935
Js_output.make block ~value:E.unit
9893298936
end
98933-
| (Ltrywith(
98934-
(Lprim {primitive = Pccall {prim_name = "caml_sys_getenv"; _};
98935-
args = [Lconst _]} as body),
98936-
id,
98937-
Lifthenelse
98938-
(Lprim{primitive = Pintcomp(Ceq);
98939-
args = [Lvar id2 ;
98940-
Lprim{primitive = Pglobal_exception {name = "Not_found"}; _}]},
98941-
cont, _reraise )
98942-
)
98943-
| Ltrywith(
98944-
(Lprim {primitive = Pccall {prim_name = "caml_sys_getenv"; _};
98945-
args = [Lconst _]} as body),
98946-
id,
98947-
Lifthenelse(Lprim{primitive = Pintcomp(Ceq);
98948-
args = [
98949-
Lprim { primitive = Pglobal_exception {name = "Not_found"; _}; _}; Lvar id2 ]},
98950-
cont, _reraise )
98951-
)) when Ident.same id id2
98952-
->
98953-
compile_lambda cxt (Lam.try_ body id cont)
9895498937
| Ltrywith(lam,id, catch) -> (* generate documentation *)
9895598938
(*
9895698939
tail --> should be renamed to `shouldReturn`

0 commit comments

Comments
 (0)