Skip to content

Commit 8a04464

Browse files
committed
[code gen] continue refinement
1 parent beae522 commit 8a04464

File tree

9 files changed

+164
-52
lines changed

9 files changed

+164
-52
lines changed

jscomp/bin/whole_compiler.ml

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70962,6 +70962,23 @@ let rec eq_expression
7096270962
p0 = p1 && b0 = b1 && eq_expression e0 e1
7096370963
| _ -> false
7096470964
end
70965+
| Dump (l0,es0) ->
70966+
begin match y0 with
70967+
| Dump(l1,es1) ->
70968+
l0 = l1 && eq_expression_list es0 es1
70969+
| _ -> false
70970+
end
70971+
| Seq (a0,b0) ->
70972+
begin match y0 with
70973+
| Seq(a1,b1) ->
70974+
eq_expression a0 a1 && eq_expression b0 b1
70975+
| _ -> false
70976+
end
70977+
| Bool a0 ->
70978+
begin match y0 with
70979+
| Bool b0 -> a0 = b0
70980+
| _ -> false
70981+
end
7096570982
| Length _
7096670983
| Char_of_int _
7096770984
| Char_to_int _
@@ -70972,15 +70989,15 @@ let rec eq_expression
7097270989
| String_append _
7097370990
| Int_of_boolean _
7097470991
| Anything_to_number _
70975-
| Bool _
70992+
7097670993
| Typeof _
7097770994
| Caml_not _
7097870995
| Js_not _
7097970996
| String_of_small_int_array _
7098070997
| Json_stringify _
7098170998
| Anything_to_string _
70982-
| Dump _
70983-
| Seq _
70999+
71000+
7098471001
| Cond _
7098571002
| FlatCall _
7098671003
| Bind _
@@ -71010,13 +71027,49 @@ and eq_expression_list xs ys =
7101071027
| x::xs, y::ys -> eq_expression x y && aux xs ys
7101171028
in
7101271029
aux xs ys
71013-
71014-
and eq_statement (x : J.statement) (y : J.statement) =
71015-
match x.statement_desc, y.statement_desc with
71016-
| Exp a, Exp b
71017-
| Return { return_value = a ; _} , Return { return_value = b; _} ->
71018-
eq_expression a b
71019-
| _, _ ->
71030+
and eq_statement_list xs ys =
71031+
let rec aux xs ys =
71032+
match xs,ys with
71033+
| [], [] -> true
71034+
| [], _ -> false
71035+
| _ , [] -> false
71036+
| x::xs, y::ys -> eq_statement x y && aux xs ys
71037+
in
71038+
aux xs ys
71039+
and eq_statement
71040+
({statement_desc = x0} : J.statement)
71041+
({statement_desc = y0} : J.statement) =
71042+
match x0 with
71043+
| Exp a ->
71044+
begin match y0 with
71045+
| Exp b -> eq_expression a b
71046+
| _ -> false
71047+
end
71048+
| Return { return_value = a ; _} ->
71049+
begin match y0 with
71050+
| Return { return_value = b; _} ->
71051+
eq_expression a b
71052+
| _ -> false
71053+
end
71054+
| Debugger -> y0 = Debugger
71055+
| Break -> y0 = Break
71056+
| Block xs0 ->
71057+
begin match y0 with
71058+
| Block ys0 ->
71059+
eq_statement_list xs0 ys0
71060+
| _ -> false
71061+
end
71062+
| Variable _
71063+
| If _
71064+
| While _
71065+
| ForRange _
71066+
| Continue _
71067+
71068+
| Int_switch _
71069+
| String_switch _
71070+
| Throw _
71071+
| Try _
71072+
->
7102071073
false
7102171074

7102271075
let rev_flatten_seq (x : J.expression) =

jscomp/core/js_analyzer.ml

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,23 @@ let rec eq_expression
246246
p0 = p1 && b0 = b1 && eq_expression e0 e1
247247
| _ -> false
248248
end
249+
| Dump (l0,es0) ->
250+
begin match y0 with
251+
| Dump(l1,es1) ->
252+
l0 = l1 && eq_expression_list es0 es1
253+
| _ -> false
254+
end
255+
| Seq (a0,b0) ->
256+
begin match y0 with
257+
| Seq(a1,b1) ->
258+
eq_expression a0 a1 && eq_expression b0 b1
259+
| _ -> false
260+
end
261+
| Bool a0 ->
262+
begin match y0 with
263+
| Bool b0 -> a0 = b0
264+
| _ -> false
265+
end
249266
| Length _
250267
| Char_of_int _
251268
| Char_to_int _
@@ -256,15 +273,15 @@ let rec eq_expression
256273
| String_append _
257274
| Int_of_boolean _
258275
| Anything_to_number _
259-
| Bool _
276+
260277
| Typeof _
261278
| Caml_not _
262279
| Js_not _
263280
| String_of_small_int_array _
264281
| Json_stringify _
265282
| Anything_to_string _
266-
| Dump _
267-
| Seq _
283+
284+
268285
| Cond _
269286
| FlatCall _
270287
| Bind _
@@ -294,13 +311,49 @@ and eq_expression_list xs ys =
294311
| x::xs, y::ys -> eq_expression x y && aux xs ys
295312
in
296313
aux xs ys
297-
298-
and eq_statement (x : J.statement) (y : J.statement) =
299-
match x.statement_desc, y.statement_desc with
300-
| Exp a, Exp b
301-
| Return { return_value = a ; _} , Return { return_value = b; _} ->
302-
eq_expression a b
303-
| _, _ ->
314+
and eq_statement_list xs ys =
315+
let rec aux xs ys =
316+
match xs,ys with
317+
| [], [] -> true
318+
| [], _ -> false
319+
| _ , [] -> false
320+
| x::xs, y::ys -> eq_statement x y && aux xs ys
321+
in
322+
aux xs ys
323+
and eq_statement
324+
({statement_desc = x0} : J.statement)
325+
({statement_desc = y0} : J.statement) =
326+
match x0 with
327+
| Exp a ->
328+
begin match y0 with
329+
| Exp b -> eq_expression a b
330+
| _ -> false
331+
end
332+
| Return { return_value = a ; _} ->
333+
begin match y0 with
334+
| Return { return_value = b; _} ->
335+
eq_expression a b
336+
| _ -> false
337+
end
338+
| Debugger -> y0 = Debugger
339+
| Break -> y0 = Break
340+
| Block xs0 ->
341+
begin match y0 with
342+
| Block ys0 ->
343+
eq_statement_list xs0 ys0
344+
| _ -> false
345+
end
346+
| Variable _
347+
| If _
348+
| While _
349+
| ForRange _
350+
| Continue _
351+
352+
| Int_switch _
353+
| String_switch _
354+
| Throw _
355+
| Try _
356+
->
304357
false
305358

306359
let rev_flatten_seq (x : J.expression) =

jscomp/test/.depend

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ gpr_1760_test.cmj : mt.cmj ../stdlib/int64.cmj ../stdlib/int32.cmj
244244
gpr_1762_test.cmj : mt.cmj
245245
gpr_1817_test.cmj : mt.cmj ../runtime/js.cmj
246246
gpr_1822_test.cmj : mt.cmj
247-
gpr_1891_test.cmj :
247+
gpr_1891_test.cmj : ../runtime/js.cmj
248248
gpr_405_test.cmj : ../stdlib/hashtbl.cmj gpr_405_test.cmi
249249
gpr_441.cmj :
250250
gpr_459_test.cmj : mt.cmj

jscomp/test/gpr_1891_test.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
'use strict';
22

3+
var Curry = require("../../lib/js/curry.js");
34

45
function foo(x) {
5-
if (typeof x === "number") {
6-
console.log("2");
7-
return /* () */0;
8-
} else if (x[0] !== 3505894) {
9-
console.log("2");
10-
return /* () */0;
11-
} else if (x[1] !== 3) {
6+
if (typeof x === "number" || x[0] !== 3505894 || x[1] !== 3) {
127
console.log("2");
138
return /* () */0;
149
} else {
@@ -33,7 +28,27 @@ function foo3(x) {
3328
}
3429
}
3530

31+
function foo4(x, h) {
32+
if (typeof x === "number" || x[0] !== 3505894 || x[1] !== 3) {
33+
return /* () */0;
34+
} else {
35+
return Curry._1(h, /* () */0);
36+
}
37+
}
38+
39+
function foo5(x) {
40+
if (typeof x === "number" || x[0] !== 3505894 || x[1] !== 3) {
41+
console.log("x");
42+
return /* () */0;
43+
} else {
44+
console.log("hi");
45+
return /* () */0;
46+
}
47+
}
48+
3649
exports.foo = foo;
3750
exports.foo2 = foo2;
3851
exports.foo3 = foo3;
52+
exports.foo4 = foo4;
53+
exports.foo5 = foo5;
3954
/* No side effect */

jscomp/test/gpr_1891_test.ml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,12 @@ let foo3 x =
2020

2121

2222

23-
23+
let foo4 x h =
24+
match x with
25+
| `Foo 3 -> h ()
26+
| _ -> ()
27+
28+
let foo5 x =
29+
match x with
30+
| `Foo 3 -> Js.log "hi"
31+
| _ -> Js.log "x"

jscomp/test/ocaml_typedtree_test.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12024,10 +12024,7 @@ function components_of_module_maker(param) {
1202412024
pos[0]
1202512025
], c[/* comp_values */0]);
1202612026
var match = decl[/* val_kind */1];
12027-
if (typeof match === "number") {
12028-
pos[0] = pos[0] + 1 | 0;
12029-
return /* () */0;
12030-
} else if (match.tag) {
12027+
if (typeof match === "number" || match.tag) {
1203112028
pos[0] = pos[0] + 1 | 0;
1203212029
return /* () */0;
1203312030
} else {

jscomp/test/test_ramification.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,7 @@ function f3(x) {
4848
var v = 0;
4949
var y;
5050
v = 1;
51-
if (x.tag) {
52-
y = 4;
53-
} else {
54-
y = 3;
55-
}
51+
y = x.tag ? 4 : 3;
5652
return y + 32 | 0;
5753
}
5854

jscomp/test/test_require.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@ if (match !== undefined) {
88
var match$1 = typeof (module) === "undefined" ? undefined : (module);
99
var match$2 = match.main;
1010
if (match$1 !== undefined) {
11-
if (match$2 !== undefined) {
12-
if (match$1 === match$2) {
13-
console.log("is main");
14-
} else {
15-
console.log("not main");
16-
}
11+
if (match$2 !== undefined && match$1 === match$2) {
12+
console.log("is main");
1713
} else {
1814
console.log("not main");
1915
}

lib/js/genlex.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -484,14 +484,8 @@ function make_lexer(keywords) {
484484
var match = Stream.peek(strm__);
485485
if (match) {
486486
var c = match[0];
487-
if (c !== 43) {
488-
if (c !== 45) {
489-
return end_exponent_part(strm__);
490-
} else {
491-
Stream.junk(strm__);
492-
store(c);
493-
return end_exponent_part(strm__);
494-
}
487+
if (c !== 43 && c !== 45) {
488+
return end_exponent_part(strm__);
495489
} else {
496490
Stream.junk(strm__);
497491
store(c);

0 commit comments

Comments
 (0)