Skip to content

Commit 59f4693

Browse files
committed
Runtime: don't use double equal (part 3)
1 parent b55ce87 commit 59f4693

File tree

10 files changed

+254
-244
lines changed

10 files changed

+254
-244
lines changed

compiler/lib/generate.ml

+5-4
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ let apply_fun_raw ctx f params exact trampolined =
797797
let l = Utf8_string.of_string_exn "l" in
798798
J.ECond
799799
( J.EBin
800-
( J.EqEq
800+
( J.EqEqEq
801801
, J.ECond
802802
( J.EBin (J.Ge, J.dot f l, int 0)
803803
, J.dot f l
@@ -956,9 +956,10 @@ let _ =
956956
register_bin_prim "%int_lsr" `Pure (fun cx cy _ -> to_int (J.EBin (J.Lsr, cx, cy)));
957957
register_bin_prim "%int_asr" `Pure (fun cx cy _ -> J.EBin (J.Asr, cx, cy));
958958
register_un_prim "%int_neg" `Pure (fun cx _ -> to_int (J.EUn (J.Neg, cx)));
959-
register_bin_prim "caml_eq_float" `Pure (fun cx cy _ -> bool (J.EBin (J.EqEq, cx, cy)));
959+
register_bin_prim "caml_eq_float" `Pure (fun cx cy _ ->
960+
bool (J.EBin (J.EqEqEq, cx, cy)));
960961
register_bin_prim "caml_neq_float" `Pure (fun cx cy _ ->
961-
bool (J.EBin (J.NotEq, cx, cy)));
962+
bool (J.EBin (J.NotEqEq, cx, cy)));
962963
register_bin_prim "caml_ge_float" `Pure (fun cx cy _ -> bool (J.EBin (J.Le, cy, cx)));
963964
register_bin_prim "caml_le_float" `Pure (fun cx cy _ -> bool (J.EBin (J.Le, cx, cy)));
964965
register_bin_prim "caml_gt_float" `Pure (fun cx cy _ -> bool (J.EBin (J.Lt, cy, cx)));
@@ -1307,7 +1308,7 @@ let rec translate_expr ctx queue loc x e level : _ * J.statement_list =
13071308
let (px, cx), queue = access_queue' ~ctx queue a in
13081309
let (py, cy), queue = access_queue' ~ctx queue b in
13091310
let prop = or_p px py in
1310-
bool (J.EBin (J.EqEq, cx, cy)), prop, queue
1311+
bool (J.EBin (J.EqEqEq, cx, cy)), prop, queue
13111312
| Extern "caml_string_concat", [ a; b ] when Config.Flag.use_js_string () ->
13121313
let (pa, ca), queue = access_queue' ~ctx queue a in
13131314
let (pb, cb), queue = access_queue' ~ctx queue b in

compiler/tests-compiler/call_gen.ml

+45-45
Original file line numberDiff line numberDiff line change
@@ -60,51 +60,51 @@ module M1 = struct
6060
print_fun_decl generated (Some "caml_call2");
6161
[%expect
6262
{|
63-
function f(g){return caml_call2(f_prime(g), 3, 4);}
64-
//end
65-
function f_prime(g){
66-
try{var _i_ = caml_call2(g, 1, 2); return _i_;}
67-
catch(e$0){
68-
var e = caml_wrap_exception(e$0);
69-
throw caml_maybe_attach_backtrace(e, 0);
70-
}
71-
}
72-
//end
73-
function g(param){
74-
return f
75-
(function(a, b, c, d){
76-
return caml_call1(Stdlib[44], ((a + b | 0) + c | 0) + d | 0);
77-
});
78-
}
79-
//end
80-
function h(param){
81-
return f
82-
(function(a, b, c, d){
83-
return caml_call1(Stdlib[44], ((a + b | 0) + c | 0) + d | 0);
84-
});
85-
}
86-
//end
87-
function k(a, b, c, d){
88-
return caml_call1(Stdlib[44], ((a + b | 0) + c | 0) + d | 0);
89-
}
90-
//end
91-
function l(_g_, _h_){return k(_b_, _a_, _g_, _h_);}
92-
//end
93-
function m(_e_, _f_){return k(_d_, _c_, _e_, _f_);}
94-
//end
95-
function caml_call1(f, a0){
96-
return (f.l >= 0 ? f.l : f.l = f.length) == 1
97-
? f(a0)
98-
: runtime.caml_call_gen(f, [a0]);
99-
}
100-
//end
101-
function caml_call2(f, a0, a1){
102-
return (f.l >= 0 ? f.l : f.l = f.length) == 2
103-
? f(a0, a1)
104-
: runtime.caml_call_gen(f, [a0, a1]);
105-
}
106-
//end
107-
|}]
63+
function f(g){return caml_call2(f_prime(g), 3, 4);}
64+
//end
65+
function f_prime(g){
66+
try{var _i_ = caml_call2(g, 1, 2); return _i_;}
67+
catch(e$0){
68+
var e = caml_wrap_exception(e$0);
69+
throw caml_maybe_attach_backtrace(e, 0);
70+
}
71+
}
72+
//end
73+
function g(param){
74+
return f
75+
(function(a, b, c, d){
76+
return caml_call1(Stdlib[44], ((a + b | 0) + c | 0) + d | 0);
77+
});
78+
}
79+
//end
80+
function h(param){
81+
return f
82+
(function(a, b, c, d){
83+
return caml_call1(Stdlib[44], ((a + b | 0) + c | 0) + d | 0);
84+
});
85+
}
86+
//end
87+
function k(a, b, c, d){
88+
return caml_call1(Stdlib[44], ((a + b | 0) + c | 0) + d | 0);
89+
}
90+
//end
91+
function l(_g_, _h_){return k(_b_, _a_, _g_, _h_);}
92+
//end
93+
function m(_e_, _f_){return k(_d_, _c_, _e_, _f_);}
94+
//end
95+
function caml_call1(f, a0){
96+
return (f.l >= 0 ? f.l : f.l = f.length) === 1
97+
? f(a0)
98+
: runtime.caml_call_gen(f, [a0]);
99+
}
100+
//end
101+
function caml_call2(f, a0, a1){
102+
return (f.l >= 0 ? f.l : f.l = f.length) === 2
103+
? f(a0, a1)
104+
: runtime.caml_call_gen(f, [a0, a1]);
105+
}
106+
//end
107+
|}]
108108
end
109109

110110
module M2 = struct

compiler/tests-compiler/effects_toplevel.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ let%expect_test "test-compiler/lib-effects/test1.ml" =
3434
print_program code;
3535
[%expect
3636
{|
37-
3837
(function(globalThis){
3938
"use strict";
4039
var
@@ -52,7 +51,7 @@ let%expect_test "test-compiler/lib-effects/test1.ml" =
5251
>= 0
5352
? f.l
5453
: f.l = f.length)
55-
== 2
54+
=== 2
5655
? f(a0, a1)
5756
: runtime.caml_call_gen(f, [a0, a1])
5857
: runtime.caml_trampoline_return(f, [a0, a1]);
@@ -93,4 +92,5 @@ let%expect_test "test-compiler/lib-effects/test1.ml" =
9392
[]);
9493
}
9594
(globalThis));
96-
//end |}]
95+
//end
96+
|}]

compiler/tests-compiler/gh1051.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ let%expect_test _ =
3636
{|
3737
Warning: integer overflow: native integer 0xffffffff (4294967295) truncated to 0xffffffff (-1); the generated code might be incorrect.
3838
function caml_call2(f, a0, a1){
39-
return (f.l >= 0 ? f.l : f.l = f.length) == 2
39+
return (f.l >= 0 ? f.l : f.l = f.length) === 2
4040
? f(a0, a1)
4141
: runtime.caml_call_gen(f, [a0, a1]);
4242
}

compiler/tests-compiler/gh1354.ml

+9-6
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ with Exit ->
5151
caml_maybe_attach_backtrace = runtime.caml_maybe_attach_backtrace,
5252
caml_wrap_exception = runtime.caml_wrap_exception;
5353
function caml_call2(f, a0, a1){
54-
return (f.l >= 0 ? f.l : f.l = f.length) == 2
54+
return (f.l >= 0 ? f.l : f.l = f.length) === 2
5555
? f(a0, a1)
5656
: runtime.caml_call_gen(f, [a0, a1]);
5757
}
@@ -75,7 +75,8 @@ with Exit ->
7575
}
7676
}
7777
(globalThis));
78-
//end |}];
78+
//end
79+
|}];
7980
Util.compile_and_run ~debug:false prog;
8081
[%expect {|
8182
1 |}]
@@ -115,7 +116,7 @@ with Exit ->
115116
caml_string_of_jsbytes = runtime.caml_string_of_jsbytes,
116117
caml_wrap_exception = runtime.caml_wrap_exception;
117118
function caml_call3(f, a0, a1, a2){
118-
return (f.l >= 0 ? f.l : f.l = f.length) == 3
119+
return (f.l >= 0 ? f.l : f.l = f.length) === 3
119120
? f(a0, a1, a2)
120121
: runtime.caml_call_gen(f, [a0, a1, a2]);
121122
}
@@ -162,7 +163,8 @@ with Exit ->
162163
}
163164
}
164165
(globalThis));
165-
//end |}];
166+
//end
167+
|}];
166168
Util.compile_and_run ~debug:false prog;
167169
[%expect {|
168170
2 0
@@ -201,7 +203,7 @@ with Exit ->
201203
caml_string_of_jsbytes = runtime.caml_string_of_jsbytes,
202204
caml_wrap_exception = runtime.caml_wrap_exception;
203205
function caml_call2(f, a0, a1){
204-
return (f.l >= 0 ? f.l : f.l = f.length) == 2
206+
return (f.l >= 0 ? f.l : f.l = f.length) === 2
205207
? f(a0, a1)
206208
: runtime.caml_call_gen(f, [a0, a1]);
207209
}
@@ -238,7 +240,8 @@ with Exit ->
238240
}
239241
}
240242
(globalThis));
241-
//end |}];
243+
//end
244+
|}];
242245
Util.compile_and_run ~debug:false prog;
243246
[%expect {|
244247
1

compiler/tests-compiler/gh1559.ml

+8-6
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ let () = my_ref := 2
7070
"use strict";
7171
var runtime = globalThis.jsoo_runtime;
7272
function caml_call1(f, a0){
73-
return (f.l >= 0 ? f.l : f.l = f.length) == 1
73+
return (f.l >= 0 ? f.l : f.l = f.length) === 1
7474
? f(a0)
7575
: runtime.caml_call_gen(f, [a0]);
7676
}
7777
function caml_call2(f, a0, a1){
78-
return (f.l >= 0 ? f.l : f.l = f.length) == 2
78+
return (f.l >= 0 ? f.l : f.l = f.length) === 2
7979
? f(a0, a1)
8080
: runtime.caml_call_gen(f, [a0, a1]);
8181
}
@@ -114,7 +114,8 @@ let () = my_ref := 2
114114
return;
115115
}
116116
(globalThis));
117-
//end |}]
117+
//end
118+
|}]
118119

119120
let%expect_test _ =
120121
let prog =
@@ -174,12 +175,12 @@ let () = my_ref := 2
174175
"use strict";
175176
var runtime = globalThis.jsoo_runtime;
176177
function caml_call1(f, a0){
177-
return (f.l >= 0 ? f.l : f.l = f.length) == 1
178+
return (f.l >= 0 ? f.l : f.l = f.length) === 1
178179
? f(a0)
179180
: runtime.caml_call_gen(f, [a0]);
180181
}
181182
function caml_call2(f, a0, a1){
182-
return (f.l >= 0 ? f.l : f.l = f.length) == 2
183+
return (f.l >= 0 ? f.l : f.l = f.length) === 2
183184
? f(a0, a1)
184185
: runtime.caml_call_gen(f, [a0, a1]);
185186
}
@@ -234,4 +235,5 @@ let () = my_ref := 2
234235
return;
235236
}
236237
(globalThis));
237-
//end |}]
238+
//end
239+
|}]

compiler/tests-compiler/gh747.ml

+9-7
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ print_endline(String.make 1 "Ɋ".[0] ^ String.make 1 "Ɋ".[1]);;
6363
8: runtime = globalThis.jsoo_runtime,
6464
9: caml_string_of_jsbytes = runtime.caml_string_of_jsbytes;
6565
10: /*<<?>>*/ function caml_call1(f, a0){
66-
11: return (f.l >= 0 ? f.l : f.l = f.length) == 1
66+
11: return (f.l >= 0 ? f.l : f.l = f.length) === 1
6767
12: ? f(a0)
6868
13: : runtime.caml_call_gen(f, [a0]);
6969
14: }
7070
15: /*<<?>>*/ function caml_call2(f, a0, a1){
71-
16: return (f.l >= 0 ? f.l : f.l = f.length) == 2
71+
16: return (f.l >= 0 ? f.l : f.l = f.length) === 2
7272
17: ? f(a0, a1)
7373
18: : runtime.caml_call_gen(f, [a0, a1]);
7474
19: }
@@ -110,7 +110,8 @@ print_endline(String.make 1 "Ɋ".[0] ^ String.make 1 "Ɋ".[1]);;
110110
55: /*<<?>>*/ }
111111
56: (globalThis));
112112
57:
113-
58: //# sourceMappingURL=test.map |}]
113+
58: //# sourceMappingURL=test.map
114+
|}]
114115

115116
let%expect_test _ =
116117
with_temp_dir ~f:(fun () ->
@@ -233,17 +234,17 @@ end
233234
8: runtime = globalThis.jsoo_runtime,
234235
9: caml_string_of_jsbytes = runtime.caml_string_of_jsbytes;
235236
10: /*<<?>>*/ function caml_call2(f, a0, a1){
236-
11: return (f.l >= 0 ? f.l : f.l = f.length) == 2
237+
11: return (f.l >= 0 ? f.l : f.l = f.length) === 2
237238
12: ? f(a0, a1)
238239
13: : runtime.caml_call_gen(f, [a0, a1]);
239240
14: }
240241
15: /*<<?>>*/ function caml_call3(f, a0, a1, a2){
241-
16: return (f.l >= 0 ? f.l : f.l = f.length) == 3
242+
16: return (f.l >= 0 ? f.l : f.l = f.length) === 3
242243
17: ? f(a0, a1, a2)
243244
18: : runtime.caml_call_gen(f, [a0, a1, a2]);
244245
19: }
245246
20: /*<<?>>*/ function caml_call8(f, a0, a1, a2, a3, a4, a5, a6, a7){
246-
21: return (f.l >= 0 ? f.l : f.l = f.length) == 8
247+
21: return (f.l >= 0 ? f.l : f.l = f.length) === 8
247248
22: ? f(a0, a1, a2, a3, a4, a5, a6, a7)
248249
23: : runtime.caml_call_gen(f, [a0, a1, a2, a3, a4, a5, a6, a7]);
249250
24: }
@@ -395,4 +396,5 @@ end
395396
170: /*<<?>>*/ }
396397
171: (globalThis));
397398
172:
398-
173: //# sourceMappingURL=test.map |}]
399+
173: //# sourceMappingURL=test.map
400+
|}]

compiler/tests-compiler/side_effect.ml

+4-3
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ let%expect_test _ =
5656
runtime = globalThis.jsoo_runtime,
5757
caml_string_of_jsbytes = runtime.caml_string_of_jsbytes;
5858
function caml_call1(f, a0){
59-
return (f.l >= 0 ? f.l : f.l = f.length) == 1
59+
return (f.l >= 0 ? f.l : f.l = f.length) === 1
6060
? f(a0)
6161
: runtime.caml_call_gen(f, [a0]);
6262
}
6363
function caml_call2(f, a0, a1){
64-
return (f.l >= 0 ? f.l : f.l = f.length) == 2
64+
return (f.l >= 0 ? f.l : f.l = f.length) === 2
6565
? f(a0, a1)
6666
: runtime.caml_call_gen(f, [a0, a1]);
6767
}
@@ -119,7 +119,8 @@ let%expect_test _ =
119119
return;
120120
}
121121
(globalThis));
122-
//end |}];
122+
//end
123+
|}];
123124
[%expect {| |}];
124125
Util.compile_and_run
125126
~flags:[]

compiler/tests-compiler/static_eval.ml

+3-2
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ let%expect_test "static eval of tags" =
185185
"use strict";
186186
var runtime = globalThis.jsoo_runtime;
187187
function caml_call1(f, a0){
188-
return (f.l >= 0 ? f.l : f.l = f.length) == 1
188+
return (f.l >= 0 ? f.l : f.l = f.length) === 1
189189
? f(a0)
190190
: runtime.caml_call_gen(f, [a0]);
191191
}
@@ -204,4 +204,5 @@ let%expect_test "static eval of tags" =
204204
return;
205205
}
206206
(globalThis));
207-
//end |}]
207+
//end
208+
|}]

0 commit comments

Comments
 (0)