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 bbb0d67 commit 683da36
Show file tree
Hide file tree
Showing 14 changed files with 739 additions and 563 deletions.
1 change: 0 additions & 1 deletion compiler/lib/generate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,6 @@ let throw_statement ctx cx k loc =
]

let is_int = function
| J.ENum n -> J.Num.is_int 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(5 !== i) return caml_cps_exact_call1(_c_, _e_);
if(! Object.is(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(2 === n){
if(Object.is(2, n)){
if(l){
var match = l[2];
if(match){
Expand All @@ -178,7 +178,7 @@ let () = M.myfun M.x
}
}
}
else if(3 === n && l){
else if(Object.is(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(2 === n){
if(Object.is(2, n)){
if(l){
var match = l[2];
if(match){
Expand All @@ -256,7 +256,7 @@ let () = M.myfun M.x
}
}
}
else if(3 === n && l){
else if(Object.is(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(4 === i) return 0;
if(Object.is(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(4 === i){
if(Object.is(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(4 === i){
if(Object.is(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
4 changes: 2 additions & 2 deletions compiler/tests-compiler/gh1320.ml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ let () = myfun ()
function(i){
function g(x){return app(f, x);}
function f(x){
return 0 === x ? 1 : runtime.caml_mul(i, app(g, x - 1 | 0));
return Object.is(0, x) ? 1 : runtime.caml_mul(i, app(g, x - 1 | 0));
}
var block = [0, g, f];
return block;
Expand All @@ -61,7 +61,7 @@ let () = myfun ()
_b_ = g(i);
caml_call2(Stdlib_Printf[3], _a_, _b_);
var _c_ = i + 1 | 0;
if(4 === i) return 0;
if(Object.is(4, i)) return 0;
var i = _c_;
}
}
Expand Down
169 changes: 86 additions & 83 deletions compiler/tests-compiler/gh747.ml
Original file line number Diff line number Diff line change
Expand Up @@ -316,86 +316,89 @@ end
91: function format_backtrace_slot(pos, slot){
92: function info(is_raise){
93: /*<<test.ml:46:4>>*/ return is_raise
94: ? 0 === pos ? cst_Raised_at : cst_Re_raised_at
95: : 0 === pos ? cst_Raised_by_primitive_operat : cst_Called_from;
96: /*<<test.ml:49:75>>*/ }
97: /*<<test.ml:51:2>>*/ if(0 === slot[0]){
98: /*<<test.ml:59:14>>*/ var
99: _h_ = slot[5],
100: _i_ = slot[4],
101: _j_ = slot[3],
102: _k_ = slot[6] ? cst_inlined : cst,
103: _l_ = slot[2],
104: _m_ = slot[7],
105: /*<<test.ml:59:14>>*/ _n_ = info(slot[1]);
106: /*<<test.ml:58:6>>*/ return [0,
107: /*<<test.ml:58:11>>*/ caml_call8
108: (Stdlib_Printf[4], _a_, _n_, _m_, _l_, _k_, _j_, _i_, _h_)];
109: }
110: if(slot[1]) /*<<test.ml:54:50>>*/ return 0;
111: /*<<test.ml:56:51>>*/ /*<<test.ml:56:51>>*/ var _o_ = info(0);
112: /*<<test.ml:56:8>>*/ return [0,
113: /*<<test.ml:56:13>>*/ caml_call2(Stdlib_Printf[4], _b_, _o_)];
114: /*<<test.ml:61:52>>*/ }
115: function print_exception_backtrace(outchan, backtrace){
116: /*<<test.ml:64:2>>*/ if(! backtrace)
117: /*<<test.ml:66:6>>*/ return /*<<test.ml:66:6>>*/ caml_call2
118: (Stdlib_Printf[1], outchan, _d_);
119: var a = backtrace[1], _f_ = a.length - 1 - 1 | 0, _e_ = 0;
120: if(_f_ >= 0){
121: var i = _e_;
122: for(;;){
123: /*<<test.ml:70:14>>*/ /*<<test.ml:70:14>>*/ var
124: match = format_backtrace_slot(i, runtime.caml_check_bound(a, i)[1 + i]);
125: if(match){
126: var str = match[1];
127: /*<<test.ml:72:24>>*/ /*<<test.ml:72:24>>*/ caml_call3
128: (Stdlib_Printf[1], outchan, _c_, str);
129: }
130: /*<<test.ml:69:6>>*/ /*<<test.ml:69:6>>*/ var _g_ = i + 1 | 0;
131: if(Object.is(_f_, i)) break;
132: var i = _g_;
133: }
134: }
135: return 0;
136: /*<<test.ml:73:10>>*/ }
137: function compare(left, right, e1, e2){
138: /*<<test.ml:77:35>>*/ if(0 === e1[0]){
139: var v1 = e1[1];
140: if(0 !== e2[0]) /*<<test.ml:80:23>>*/ return -1;
141: var v2 = e2[1];
142: /*<<test.ml:78:24>>*/ return /*<<test.ml:78:24>>*/ caml_call2
143: (left, v1, v2);
144: }
145: var v1$0 = e1[1];
146: if(0 === e2[0]) /*<<test.ml:81:23>>*/ return 1;
147: var v2$0 = e2[1];
148: /*<<test.ml:79:26>>*/ return /*<<test.ml:79:26>>*/ caml_call2
149: (right, v1$0, v2$0);
150: /*<<test.ml:81:24>>*/ }
151: /*<<test.ml:75:16>>*/ var
152: /*<<test.ml:75:16>>*/ Either = [0, compare],
153: Test =
154: [0,
155: executable_name,
156: os_type,
157: backend_type,
158: big_endian,
159: word_size,
160: int_size,
161: unix,
162: win32,
163: cygwin,
164: max_array_length,
165: max_floatarray_length,
166: max_string_length,
167: Unhandled,
168: format_backtrace_slot,
169: print_exception_backtrace,
170: Either];
171: runtime.caml_register_global(12, Test, "Test");
172: return;
173: /*<<?>>*/ }
174: (globalThis));
175:
176: //# sourceMappingURL=test.map |}]
94: ? Object.is(0, pos) ? cst_Raised_at : cst_Re_raised_at
95: : Object.is
96: (0, pos)
97: ? cst_Raised_by_primitive_operat
98: : cst_Called_from;
99: /*<<test.ml:49:75>>*/ }
100: /*<<test.ml:51:2>>*/ if(0 === slot[0]){
101: /*<<test.ml:59:14>>*/ var
102: _h_ = slot[5],
103: _i_ = slot[4],
104: _j_ = slot[3],
105: _k_ = slot[6] ? cst_inlined : cst,
106: _l_ = slot[2],
107: _m_ = slot[7],
108: /*<<test.ml:59:14>>*/ _n_ = info(slot[1]);
109: /*<<test.ml:58:6>>*/ return [0,
110: /*<<test.ml:58:11>>*/ caml_call8
111: (Stdlib_Printf[4], _a_, _n_, _m_, _l_, _k_, _j_, _i_, _h_)];
112: }
113: if(slot[1]) /*<<test.ml:54:50>>*/ return 0;
114: /*<<test.ml:56:51>>*/ /*<<test.ml:56:51>>*/ var _o_ = info(0);
115: /*<<test.ml:56:8>>*/ return [0,
116: /*<<test.ml:56:13>>*/ caml_call2(Stdlib_Printf[4], _b_, _o_)];
117: /*<<test.ml:61:52>>*/ }
118: function print_exception_backtrace(outchan, backtrace){
119: /*<<test.ml:64:2>>*/ if(! backtrace)
120: /*<<test.ml:66:6>>*/ return /*<<test.ml:66:6>>*/ caml_call2
121: (Stdlib_Printf[1], outchan, _d_);
122: var a = backtrace[1], _f_ = a.length - 1 - 1 | 0, _e_ = 0;
123: if(_f_ >= 0){
124: var i = _e_;
125: for(;;){
126: /*<<test.ml:70:14>>*/ /*<<test.ml:70:14>>*/ var
127: match = format_backtrace_slot(i, runtime.caml_check_bound(a, i)[1 + i]);
128: if(match){
129: var str = match[1];
130: /*<<test.ml:72:24>>*/ /*<<test.ml:72:24>>*/ caml_call3
131: (Stdlib_Printf[1], outchan, _c_, str);
132: }
133: /*<<test.ml:69:6>>*/ /*<<test.ml:69:6>>*/ var _g_ = i + 1 | 0;
134: if(Object.is(_f_, i)) break;
135: var i = _g_;
136: }
137: }
138: return 0;
139: /*<<test.ml:73:10>>*/ }
140: function compare(left, right, e1, e2){
141: /*<<test.ml:77:35>>*/ if(0 === e1[0]){
142: var v1 = e1[1];
143: if(0 !== e2[0]) /*<<test.ml:80:23>>*/ return -1;
144: var v2 = e2[1];
145: /*<<test.ml:78:24>>*/ return /*<<test.ml:78:24>>*/ caml_call2
146: (left, v1, v2);
147: }
148: var v1$0 = e1[1];
149: if(0 === e2[0]) /*<<test.ml:81:23>>*/ return 1;
150: var v2$0 = e2[1];
151: /*<<test.ml:79:26>>*/ return /*<<test.ml:79:26>>*/ caml_call2
152: (right, v1$0, v2$0);
153: /*<<test.ml:81:24>>*/ }
154: /*<<test.ml:75:16>>*/ var
155: /*<<test.ml:75:16>>*/ Either = [0, compare],
156: Test =
157: [0,
158: executable_name,
159: os_type,
160: backend_type,
161: big_endian,
162: word_size,
163: int_size,
164: unix,
165: win32,
166: cygwin,
167: max_array_length,
168: max_floatarray_length,
169: max_string_length,
170: Unhandled,
171: format_backtrace_slot,
172: print_exception_backtrace,
173: Either];
174: runtime.caml_register_global(12, Test, "Test");
175: return;
176: /*<<?>>*/ }
177: (globalThis));
178:
179: //# sourceMappingURL=test.map |}]
4 changes: 2 additions & 2 deletions compiler/tests-compiler/global_deadcode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ let%expect_test "Eliminates unused functions from functor" =
function add(x, t){
if(! t) return [0, 0, x, 0, 1];
var r = t[3], v = t[2], l = t[1], c = caml_call2(Ord[1], x, v);
if(0 === c) return t;
if(Object.is(0, c)) return t;
if(0 <= c){var rr = add(x, r); return Object.is(r, rr) ? t : bal(l, v, rr);}
var ll = add(x, l);
return Object.is(l, ll) ? t : bal(ll, v, r);
Expand All @@ -84,7 +84,7 @@ let%expect_test "Eliminates unused functions from functor" =
v = param$0[2],
l = param$0[1],
c = caml_call2(Ord[1], x, v);
if(0 === c) return v;
if(Object.is(0, c)) return v;
var r$0 = 0 <= c ? r : l, param$0 = r$0;
}
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/tests-compiler/lazy.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ let%expect_test "static eval of string get" =
[%expect
{|
function do_the_lazy_rec(n){
if(0 === n) return 0;
if(Object.is(0, n)) return 0;
var _b_ = do_the_lazy_rec(n - 1 | 0), _c_ = runtime.caml_obj_tag(lz);
a:
if(250 === _c_)
if(Object.is(250, _c_))
var _d_ = lz[1];
else{
if(246 !== _c_ && 244 !== _c_){var _d_ = lz; break a;}
if(! Object.is(246, _c_) && ! Object.is(244, _c_)){var _d_ = lz; break a;}
var _d_ = caml_call1(CamlinternalLazy[2], lz);
}
return [0, _d_, _b_];
Expand Down
Loading

0 comments on commit 683da36

Please sign in to comment.