Skip to content

Commit 9a9993e

Browse files
committed
promote
1 parent 5fc3300 commit 9a9993e

File tree

12 files changed

+63
-35
lines changed

12 files changed

+63
-35
lines changed

compiler/lib/generate.ml

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,11 @@ let throw_statement ctx cx k loc =
10281028
, loc )
10291029
]
10301030

1031+
let is_int = function
1032+
| J.ENum n -> J.Num.is_int n
1033+
| J.EBin ((J.Bor | J.Lsr), _, _) -> true
1034+
| _ -> false
1035+
10311036
let rec translate_expr ctx queue loc x e level : _ * J.statement_list =
10321037
match e with
10331038
| Apply { f; args; exact } ->
@@ -1322,23 +1327,31 @@ let rec translate_expr ctx queue loc x e level : _ * J.statement_list =
13221327
| Eq, [ x; y ] ->
13231328
let (px, cx), queue = access_queue' ~ctx queue x in
13241329
let (py, cy), queue = access_queue' ~ctx queue y in
1325-
( bool
1326-
(J.call
1327-
(J.dot (s_var "Object") (Utf8_string.of_string_exn "is"))
1328-
[ cx; cy ]
1329-
loc)
1330-
, or_p px py
1331-
, queue )
1330+
let e =
1331+
if is_int cx || is_int cy
1332+
then bool (J.EBin (J.EqEqEq, cx, cy))
1333+
else
1334+
bool
1335+
(J.call
1336+
(J.dot (s_var "Object") (Utf8_string.of_string_exn "is"))
1337+
[ cx; cy ]
1338+
loc)
1339+
in
1340+
e, or_p px py, queue
13321341
| Neq, [ x; y ] ->
13331342
let (px, cx), queue = access_queue' ~ctx queue x in
13341343
let (py, cy), queue = access_queue' ~ctx queue y in
1335-
( bool_not
1336-
(J.call
1337-
(J.dot (s_var "Object") (Utf8_string.of_string_exn "is"))
1338-
[ cx; cy ]
1339-
loc)
1340-
, or_p px py
1341-
, queue )
1344+
let e =
1345+
if is_int cx || is_int cy
1346+
then bool (J.EBin (J.NotEqEq, cx, cy))
1347+
else
1348+
bool_not
1349+
(J.call
1350+
(J.dot (s_var "Object") (Utf8_string.of_string_exn "is"))
1351+
[ cx; cy ]
1352+
loc)
1353+
in
1354+
e, or_p px py, queue
13421355
| IsInt, [ x ] ->
13431356
let (px, cx), queue = access_queue' ~ctx queue x in
13441357
bool (Mlvalue.is_immediate cx), px, queue

compiler/lib/javascript.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ module Num : sig
4242

4343
val is_neg : t -> bool
4444

45+
val is_int : t -> bool
46+
4547
(** Arithmetic *)
4648

4749
val add : t -> t -> t
@@ -133,6 +135,13 @@ end = struct
133135

134136
let is_neg s = Char.equal s.[0] '-'
135137

138+
let is_int = function
139+
| "-0" -> false
140+
| s ->
141+
String.for_all s ~f:(function
142+
| '0' .. '9' | '-' | '+' -> true
143+
| _ -> false)
144+
136145
let neg s =
137146
match String.drop_prefix s ~prefix:"-" with
138147
| None -> "-" ^ s

compiler/lib/javascript.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ module Num : sig
4343

4444
val is_neg : t -> bool
4545

46+
val is_int : t -> bool
47+
4648
(** Arithmetic *)
4749

4850
val add : t -> t -> t

compiler/tests-compiler/effects.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ let fff () =
4949
10,
5050
[0,
5151
function(e, cont){
52-
return e === E
52+
return Object.is(e, E)
5353
? cont([0, function(k, cont){return cont(11);}])
5454
: cont(0);
5555
}],

compiler/tests-compiler/effects_continuations.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ let%expect_test "test-compiler/lib-effects/test1.ml" =
106106
try{var _t_ = runtime.caml_int_of_string(s), n = _t_;}
107107
catch(_x_){
108108
var _p_ = caml_wrap_exception(_x_);
109-
if(_p_[1] !== Stdlib[7]){
109+
if(! Object.is(_p_[1], Stdlib[7])){
110110
var raise$1 = caml_pop_trap();
111111
return raise$1(caml_maybe_attach_backtrace(_p_, 0));
112112
}
@@ -119,15 +119,15 @@ let%expect_test "test-compiler/lib-effects/test1.ml" =
119119
}
120120
catch(_w_){
121121
var _q_ = caml_wrap_exception(_w_);
122-
if(_q_ !== Stdlib[8]){
122+
if(! Object.is(_q_, Stdlib[8])){
123123
var raise$0 = caml_pop_trap();
124124
return raise$0(caml_maybe_attach_backtrace(_q_, 0));
125125
}
126126
var m = 0;
127127
}
128128
runtime.caml_push_trap
129129
(function(_v_){
130-
if(_v_ === Stdlib[8]) return cont(0);
130+
if(Object.is(_v_, Stdlib[8])) return cont(0);
131131
var raise = caml_pop_trap();
132132
return raise(caml_maybe_attach_backtrace(_v_, 0));
133133
});

compiler/tests-compiler/effects_exceptions.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ let%expect_test "test-compiler/lib-effects/test1.ml" =
6060
try{var _k_ = runtime.caml_int_of_string(s), n = _k_;}
6161
catch(_o_){
6262
var _g_ = caml_wrap_exception(_o_);
63-
if(_g_[1] !== Stdlib[7]){
63+
if(! Object.is(_g_[1], Stdlib[7])){
6464
var raise$1 = caml_pop_trap();
6565
return raise$1(caml_maybe_attach_backtrace(_g_, 0));
6666
}
@@ -73,15 +73,15 @@ let%expect_test "test-compiler/lib-effects/test1.ml" =
7373
}
7474
catch(_n_){
7575
var _h_ = caml_wrap_exception(_n_);
76-
if(_h_ !== Stdlib[8]){
76+
if(! Object.is(_h_, Stdlib[8])){
7777
var raise$0 = caml_pop_trap();
7878
return raise$0(caml_maybe_attach_backtrace(_h_, 0));
7979
}
8080
var m = 0;
8181
}
8282
caml_push_trap
8383
(function(_m_){
84-
if(_m_ === Stdlib[8]) return cont(0);
84+
if(Object.is(_m_, Stdlib[8])) return cont(0);
8585
var raise = caml_pop_trap();
8686
return raise(caml_maybe_attach_backtrace(_m_, 0));
8787
});

compiler/tests-compiler/gh1354.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ with Exit ->
6666
try{0; _b_ = _a_ + 1 | 0; throw caml_maybe_attach_backtrace(Stdlib[3], 1);}
6767
catch(_e_){
6868
var _c_ = caml_wrap_exception(_e_);
69-
if(_c_ !== Stdlib[3]) throw caml_maybe_attach_backtrace(_c_, 0);
69+
if(! Object.is(_c_, Stdlib[3])) throw caml_maybe_attach_backtrace(_c_, 0);
7070
caml_call2(Stdlib_Printf[3], _d_, _b_ | 0);
7171
var Test = [0];
7272
runtime.caml_register_global(3, Test, "Test");
@@ -153,7 +153,7 @@ with Exit ->
153153
}
154154
catch(_j_){
155155
var _d_ = caml_wrap_exception(_j_);
156-
if(_d_ !== Stdlib[3]) throw caml_maybe_attach_backtrace(_d_, 0);
156+
if(! Object.is(_d_, Stdlib[3])) throw caml_maybe_attach_backtrace(_d_, 0);
157157
caml_call3(Stdlib_Printf[3], _e_, _c_ | 0, _b_);
158158
var Test = [0];
159159
runtime.caml_register_global(4, Test, "Test");
@@ -229,7 +229,7 @@ with Exit ->
229229
}
230230
catch(_h_){
231231
var _c_ = caml_wrap_exception(_h_);
232-
if(_c_ !== Stdlib[3]) throw caml_maybe_attach_backtrace(_c_, 0);
232+
if(! Object.is(_c_, Stdlib[3])) throw caml_maybe_attach_backtrace(_c_, 0);
233233
caml_call2(Stdlib_Printf[3], _d_, _b_);
234234
var Test = [0];
235235
runtime.caml_register_global(4, Test, "Test");

compiler/tests-compiler/gh747.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ end
350350
125: (Stdlib_Printf[1], outchan, _c_, str);
351351
126: }
352352
127: /*<<test.ml:69:6>>*/ /*<<test.ml:69:6>>*/ var _g_ = i + 1 | 0;
353-
128: if(_f_ === i) break;
353+
128: if(Object.is(_f_, i)) break;
354354
129: i = _g_;
355355
130: }
356356
131: }

compiler/tests-compiler/global_deadcode.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ let%expect_test "Eliminates unused functions from functor" =
6969
if(! t) return [0, 0, x, 0, 1];
7070
var r = t[3], v = t[2], l = t[1], c = caml_call2(Ord[1], x, v);
7171
if(0 === c) return t;
72-
if(0 <= c){var rr = add(x, r); return r === rr ? t : bal(l, v, rr);}
72+
if(0 <= c){var rr = add(x, r); return Object.is(r, rr) ? t : bal(l, v, rr);}
7373
var ll = add(x, l);
74-
return l === ll ? t : bal(ll, v, r);
74+
return Object.is(l, ll) ? t : bal(ll, v, r);
7575
}
7676
function singleton(x){return [0, 0, x, 0, 1];}
7777
function find(x, param){

compiler/tests-compiler/loops.ml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ let f t x =
254254
try{var val$0 = caml_call2(Stdlib_Hashtbl[6], t, x);}
255255
catch(_f_){
256256
var _c_ = caml_wrap_exception(_f_);
257-
if(_c_ === Stdlib[8]) return - 1;
257+
if(Object.is(_c_, Stdlib[8])) return - 1;
258258
throw caml_maybe_attach_backtrace(_c_, 0);
259259
}
260260
if(val$0 && ! val$0[2]){
@@ -265,7 +265,8 @@ let f t x =
265265
try{var val = caml_call2(Stdlib_Hashtbl[6], t, x$0);}
266266
catch(_e_){
267267
var _a_ = caml_wrap_exception(_e_);
268-
if(_a_ !== Stdlib[3]) throw caml_maybe_attach_backtrace(_a_, 0);
268+
if(! Object.is(_a_, Stdlib[3]))
269+
throw caml_maybe_attach_backtrace(_a_, 0);
269270
var _d_ = 0;
270271
break a;
271272
}
@@ -500,12 +501,12 @@ let add_substitute =
500501
var lim = caml_ml_string_length(s), k = k$2, stop = new_start;
501502
for(;;){
502503
if(lim <= stop) throw caml_maybe_attach_backtrace(Stdlib[8], 1);
503-
if(caml_string_get(s, stop) === opening){
504+
if(Object.is(caml_string_get(s, stop), opening)){
504505
var i = stop + 1 | 0, k$0 = k + 1 | 0;
505506
k = k$0;
506507
stop = i;
507508
}
508-
else if(caml_string_get(s, stop) === closing){
509+
else if(Object.is(caml_string_get(s, stop), closing)){
509510
if(0 === k) break;
510511
var i$0 = stop + 1 | 0, k$1 = k - 1 | 0;
511512
k = k$1;

0 commit comments

Comments
 (0)