Skip to content

Commit 17299e4

Browse files
committed
experimental support for code points
- use the new native backend with relaxed chars - TODO: check the pattern ranges
1 parent 651977d commit 17299e4

12 files changed

+3942
-4962
lines changed

jscomp/core/js_exp_make.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1250,14 +1250,14 @@ let int32_lsl ?comment (e1 : J.expression) (e2 : J.expression) : J.expression =
12501250
}
12511251

12521252
let is_pos_pow n =
1253-
let module M = struct exception E end in
1253+
let exception E in
12541254
let rec aux c (n : Int32.t) =
12551255
if n <= 0l then -2
12561256
else if n = 1l then c
12571257
else if Int32.logand n 1l = 0l then
12581258
aux (c + 1) (Int32.shift_right n 1 )
1259-
else raise_notrace M.E in
1260-
try aux 0 n with M.E -> -1
1259+
else raise_notrace E in
1260+
try aux 0 n with E -> -1
12611261

12621262
let int32_mul ?comment
12631263
(e1 : J.expression)

jscomp/main/builtin_cmi_datasets.ml

+2-2
Large diffs are not rendered by default.

jscomp/test/build.ninja

+1-1
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ o test/string_runtime_test.cmi test/string_runtime_test.cmj : cc test/string_run
567567
o test/string_set.cmi test/string_set.cmj : cc test/string_set.ml | test/set_gen.cmj $stdlib
568568
o test/string_set_test.cmi test/string_set_test.cmj : cc test/string_set_test.ml | test/mt.cmj test/string_set.cmj $stdlib
569569
o test/string_test.cmi test/string_test.cmj : cc test/string_test.ml | test/ext_string_test.cmj test/mt.cmj $stdlib
570-
o test/string_unicode_test.cmi test/string_unicode_test.cmj : cc test/string_unicode_test.ml | $stdlib
570+
o test/string_unicode_test.cmi test/string_unicode_test.cmj : cc test/string_unicode_test.ml | test/mt.cmj $stdlib
571571
o test/stringmatch_test.cmi test/stringmatch_test.cmj : cc test/stringmatch_test.ml | $stdlib
572572
o test/submodule.cmi test/submodule.cmj : cc test/submodule.ml | $stdlib
573573
o test/submodule_call.cmi test/submodule_call.cmj : cc test/submodule_call.ml | test/submodule.cmj $stdlib

jscomp/test/ocaml_re_test.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -435,19 +435,25 @@ function $plus$plus(x, y) {
435435

436436
function from_char(param) {
437437
if (param >= 170) {
438-
if (param >= 187) {
439-
if (param > 246 || param < 192) {
440-
if (param >= 248) {
441-
return 2;
442-
} else {
438+
if (param >= 192) {
439+
if (param > 255 || param < 216) {
440+
if (param >= 215) {
443441
return 4;
442+
} else {
443+
return 2;
444444
}
445-
} else if (param !== 215) {
445+
} else if (param !== 247) {
446446
return 2;
447447
} else {
448448
return 4;
449449
}
450-
} else if (!(param > 185 || param < 171) && param !== 181) {
450+
} else if (param > 185 || param < 171) {
451+
if (param >= 187) {
452+
return 4;
453+
} else {
454+
return 2;
455+
}
456+
} else if (param !== 181) {
451457
return 4;
452458
} else {
453459
return 2;

jscomp/test/string_unicode_test.js

+51
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,61 @@
11
'use strict';
22

3+
var Mt = require("./mt.js");
4+
5+
var suites = {
6+
contents: /* [] */0
7+
};
8+
9+
var test_id = {
10+
contents: 0
11+
};
12+
13+
function eq(loc, x, y) {
14+
test_id.contents = test_id.contents + 1 | 0;
15+
suites.contents = {
16+
hd: [
17+
loc + (" id " + String(test_id.contents)),
18+
(function (param) {
19+
return {
20+
TAG: /* Eq */0,
21+
_0: x,
22+
_1: y
23+
};
24+
})
25+
],
26+
tl: suites.contents
27+
};
28+
29+
}
330

431
console.log("\xe4\xbd\xa0\xe5\xa5\xbd");
532

633
console.log("你好");
734

835
console.log("你好");
936

37+
function f(x) {
38+
if (x !== 333) {
39+
if (x >= 256) {
40+
return 3;
41+
} else {
42+
return 0;
43+
}
44+
} else {
45+
return 2;
46+
}
47+
}
48+
49+
eq("File \"string_unicode_test.ml\", line 27, characters 7-14", f(/* '{' */123), 0);
50+
51+
eq("File \"string_unicode_test.ml\", line 28, characters 7-14", f(/* '\333' */333), 2);
52+
53+
eq("File \"string_unicode_test.ml\", line 29, characters 7-14", f(/* '\444' */444), 3);
54+
55+
Mt.from_pair_suites("string_unicode_test.ml", suites.contents);
56+
57+
exports.suites = suites;
58+
exports.test_id = test_id;
59+
exports.eq = eq;
60+
exports.f = f;
1061
/* Not a pure module */

jscomp/test/string_unicode_test.ml

+20-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
let suites : Mt.pair_suites ref = ref []
2+
let test_id = ref 0
3+
let eq loc x y =
4+
incr test_id ;
5+
suites :=
6+
(loc ^" id " ^ (string_of_int !test_id), (fun _ -> Mt.Eq(x,y))) :: !suites
7+
18

29

310

@@ -8,8 +15,16 @@ let () = Js.log {js|你好|js}
815
let () =
916
Js.log [%raw {|"你好"|}]
1017

11-
#if 0 then
12-
let f = function
13-
| {j| hello |j} -> 0
14-
| _ -> 1
15-
#end
18+
19+
20+
let f x =
21+
match x with
22+
| '\000' .. '\255' -> 0
23+
| '\333' -> 2
24+
| _ -> 3
25+
26+
let () =
27+
eq __LOC__ (f '\123') 0 ;
28+
eq __LOC__ (f '\333') 2 ;
29+
eq __LOC__ (f '\444') 3
30+
;; Mt.from_pair_suites __FILE__ !suites

0 commit comments

Comments
 (0)