Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hhugo committed Dec 2, 2023
1 parent 683da36 commit 32a79e3
Show file tree
Hide file tree
Showing 10 changed files with 277 additions and 369 deletions.
1 change: 1 addition & 0 deletions compiler/lib/generate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,7 @@ let throw_statement ctx cx k loc =
]

let is_int = function
| J.ENum n -> J.Num.is_int n && not (J.Num.is_zero n)
| J.EBin ((J.Bor | J.Lsr), _, _) -> true
| _ -> false

Expand Down
2 changes: 1 addition & 1 deletion compiler/tests-compiler/effects_toplevel.ml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ let%expect_test "test-compiler/lib-effects/test1.ml" =
undef,
function(_d_){
var _e_ = i + 1 | 0;
if(! Object.is(5, i)) return caml_cps_exact_call1(_c_, _e_);
if(5 !== i) return caml_cps_exact_call1(_c_, _e_);
caml_callback(g, [undef]);
var Test = [0];
runtime.caml_register_global(2, Test, "Test");
Expand Down
14 changes: 7 additions & 7 deletions compiler/tests-compiler/gh1007.ml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ let () = M.myfun M.x
next = x$0[1],
rev_sort =
function(n, l){
if(Object.is(2, n)){
if(2 === n){
if(l){
var match = l[2];
if(match){
Expand All @@ -178,7 +178,7 @@ let () = M.myfun M.x
}
}
}
else if(Object.is(3, n) && l){
else if(3 === n && l){
var _d_ = l[2];
if(_d_){
var match$2 = _d_[2];
Expand Down Expand Up @@ -240,7 +240,7 @@ let () = M.myfun M.x
},
sort =
function(n, l){
if(Object.is(2, n)){
if(2 === n){
if(l){
var match = l[2];
if(match){
Expand All @@ -256,7 +256,7 @@ let () = M.myfun M.x
}
}
}
else if(Object.is(3, n) && l){
else if(3 === n && l){
var _b_ = l[2];
if(_b_){
var match$2 = _b_[2];
Expand Down Expand Up @@ -390,7 +390,7 @@ let () = M.run ()
};
if(even(i)) caml_call1(Stdlib[42], cst);
var _a_ = i + 1 | 0;
if(Object.is(4, i)) return 0;
if(4 === i) return 0;
var i = _a_;
}
}
Expand Down Expand Up @@ -499,7 +499,7 @@ let () = M.run ()
even = closures$0[1];
if(even(i)) caml_call1(Stdlib[42], cst);
var _e_ = i + 1 | 0;
if(Object.is(4, i)){
if(4 === i){
var _d_ = caml_call1(list_rev, delayed[1]);
return caml_call2(list_iter, function(f){return caml_call1(f, 0);}, _d_);
}
Expand Down Expand Up @@ -631,7 +631,7 @@ let () = M.run ()
var f = param$0[2], param$0 = f(0);
}
var _g_ = i + 1 | 0;
if(Object.is(4, i)){
if(4 === i){
var _f_ = caml_call1(list_rev, delayed[1]);
return caml_call2(list_iter, function(f){return caml_call1(f, 0);}, _f_);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/tests-compiler/gh1320.ml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ let () = myfun ()
_b_ = g(i);
caml_call2(Stdlib_Printf[3], _a_, _b_);
var _c_ = i + 1 | 0;
if(Object.is(4, i)) return 0;
if(4 === i) return 0;
var i = _c_;
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/tests-compiler/lazy.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ let%expect_test "static eval of string get" =
if(Object.is(0, n)) return 0;
var _b_ = do_the_lazy_rec(n - 1 | 0), _c_ = runtime.caml_obj_tag(lz);
a:
if(Object.is(250, _c_))
if(250 === _c_)
var _d_ = lz[1];
else{
if(! Object.is(246, _c_) && ! Object.is(244, _c_)){var _d_ = lz; break a;}
if(246 !== _c_ && 244 !== _c_){var _d_ = lz; break a;}
var _d_ = caml_call1(CamlinternalLazy[2], lz);
}
return [0, _d_, _b_];
Expand Down
34 changes: 17 additions & 17 deletions compiler/tests-compiler/loops.ml
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,20 @@ let rec fun_with_loop acc = function
return caml_call1
(list_rev, caml_call1(list_rev, caml_call1(list_rev, acc$0)));
var x = param$0[1];
if(Object.is(1, x) && ! param$0[2]){
if(1 === x && ! param$0[2]){
var a$0 = [0, acc$0], i$0 = 0;
for(;;){
a$0[1] = [0, 1, a$0[1]];
var _b_ = i$0 + 1 | 0;
if(Object.is(10, i$0)) return a$0[1];
if(10 === i$0) return a$0[1];
var i$0 = _b_;
}
}
var xs = param$0[2], a = [0, acc$0], i = 0;
for(;;){
a[1] = [0, 1, a[1]];
var _a_ = i + 1 | 0;
if(Object.is(10, i)) break;
if(10 === i) break;
var i = _a_;
}
var acc$1 = [0, x, a[1]], acc$0 = acc$1, param$0 = xs;
Expand Down Expand Up @@ -134,11 +134,11 @@ let for_for_while () =
for(;;){
for(;;){if(10 <= runtime.caml_mul(k, j)) break; id[1]++;}
var _b_ = j + 1 | 0;
if(Object.is(10, j)) break;
if(10 === j) break;
var j = _b_;
}
var _a_ = k + 1 | 0;
if(Object.is(10, k)) return 0;
if(10 === k) return 0;
var k = _a_;
}
}
Expand Down Expand Up @@ -175,11 +175,11 @@ let for_for_while () =
id[1]++;
}
var _b_ = j + 1 | 0;
if(Object.is(10, j)) break;
if(10 === j) break;
var j = _b_;
}
var _a_ = k + 1 | 0;
if(Object.is(10, k)) return 0;
if(10 === k) return 0;
var k = _a_;
}
}
Expand Down Expand Up @@ -311,7 +311,7 @@ in loop x
var x$1 = x;
for(;;){
if(Object.is(0, x$1)) return 1;
if(Object.is(1, x$1)) break;
if(1 === x$1) break;
var x$2 = x$1 + 1 | 0, x$1 = x$2;
}
var x$0 = 2;
Expand Down Expand Up @@ -435,12 +435,12 @@ let add_substitute =
var lim$1 = caml_ml_string_length(s), previous = 32, i$4 = 0;
for(;;){
if(i$4 >= lim$1){
var _b_ = Object.is(92, previous) ? 1 : 0;
var _b_ = 92 === previous ? 1 : 0;
return _b_ ? caml_call2(add_char, b, previous) : _b_;
}
var previous$0 = caml_string_get(s, i$4);
if(Object.is(36, previous$0))
if(Object.is(92, previous)){
if(36 === previous$0)
if(92 === previous){
caml_call2(add_char, b, previous$0);
var i$5 = i$4 + 1 | 0, previous = 32, i$4 = i$5;
}
Expand All @@ -450,7 +450,7 @@ let add_substitute =
var opening = caml_string_get(s, start$0);
a:
{
if(! Object.is(40, opening) && ! Object.is(123, opening)){
if(40 !== opening && 123 !== opening){
var start = start$0 + 1 | 0, lim$0 = caml_ml_string_length(s);
b:
{
Expand All @@ -466,7 +466,7 @@ let add_substitute =
if(97 <= match){
if(123 <= match) break d;
}
else if(! Object.is(95, match)) break d;
else if(95 !== match) break d;
}
else if(58 <= match){
if(65 > match) break;
Expand All @@ -486,10 +486,10 @@ let add_substitute =
break a;
}
var new_start = start$0 + 1 | 0, k$2 = 0;
if(Object.is(40, opening))
if(40 === opening)
var closing = 41;
else{
if(! Object.is(123, opening))
if(123 !== opening)
throw caml_maybe_attach_backtrace([0, Assert_failure, _a_], 1);
var closing = 125;
}
Expand All @@ -515,12 +515,12 @@ let add_substitute =
caml_call2(add_string, b, caml_call1(f, ident));
var previous = 32, i$4 = next_i;
}
else if(Object.is(92, previous)){
else if(92 === previous){
caml_call2(add_char, b, 92);
caml_call2(add_char, b, previous$0);
var i$6 = i$4 + 1 | 0, previous = 32, i$4 = i$6;
}
else if(Object.is(92, previous$0))
else if(92 === previous$0)
var i$7 = i$4 + 1 | 0, previous = previous$0, i$4 = i$7;
else{
caml_call2(add_char, b, previous$0);
Expand Down
4 changes: 2 additions & 2 deletions compiler/tests-compiler/match_with_exn.ml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ let fun2 () =
var _d_ = caml_wrap_exception(_e_);
if(! Object.is(_d_[1], A)) throw caml_maybe_attach_backtrace(_d_, 0);
var i = _d_[2];
if(! Object.is(2, i)) return i + 2 | 0;
if(2 !== i) return i + 2 | 0;
var i$0 = i;
break a;
}
Expand All @@ -98,7 +98,7 @@ let fun2 () =
var _a_ = caml_wrap_exception(_c_);
if(Object.is(_a_[1], A)){
var _b_ = _a_[2];
if(Object.is(2, _b_)){var i = _b_; break a;}
if(2 === _b_){var i = _b_; break a;}
}
throw caml_maybe_attach_backtrace(_a_, 0);
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/tests-compiler/mutable_closure.ml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ let%expect_test _ =
closures =
function(i){
function f(counter, n){
if(Object.is(- 1, n)){
if(- 1 === n){
var _j_ = - 2;
if(counter >= 50) return caml_trampoline_return(g, [0, _j_]);
var counter$1 = counter + 1 | 0;
Expand All @@ -137,7 +137,7 @@ let%expect_test _ =
return g(counter$0, _k_);
}
function g(counter, n){
if(Object.is(- 1, n)){
if(- 1 === n){
var _h_ = - 2;
if(counter >= 50) return caml_trampoline_return(f, [0, _h_]);
var counter$1 = counter + 1 | 0;
Expand All @@ -162,7 +162,7 @@ let%expect_test _ =
indirect[1] =
[0, function(i, f){return function(param){return f(i);};}(i, f), _f_];
var _g_ = i + 1 | 0;
if(Object.is(3, i)){
if(3 === i){
var
_d_ = indirect[1],
indirect$0 =
Expand Down
4 changes: 2 additions & 2 deletions compiler/tests-compiler/variable_declaration_output.ml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ let%expect_test _ =
if(_a_){
_b_ = _a_[1];
if(_b_){
if(Object.is(2, _b_[1]) && ! param[2]) return 3;
if(2 === _b_[1] && ! param[2]) return 3;
}
else if(! param[2]) return 2;
}
Expand All @@ -153,7 +153,7 @@ let%expect_test _ =
if(_a_){
var _b_ = _a_[1];
if(_b_){
if(Object.is(2, _b_[1]) && ! param[2]) return 3;
if(2 === _b_[1] && ! param[2]) return 3;
}
else if(! param[2]) return 2;
}
Expand Down
Loading

0 comments on commit 32a79e3

Please sign in to comment.