Skip to content

Commit c0c82f0

Browse files
committed
remove Stdlib_Char module
1 parent 6f4bea0 commit c0c82f0

File tree

16 files changed

+120
-213
lines changed

16 files changed

+120
-213
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
- Fix `Error.fromException`. https://github.com/rescript-lang/rescript/pull/7364
1818

19+
#### :house: Internal
20+
21+
- Remove `Stdlib_Char` module for now. https://github.com/rescript-lang/rescript/pull/7367
22+
1923
# 12.0.0-alpha.10
2024

2125
#### :rocket: New Feature

analysis/reanalyze/src/ExnLib.ml

-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ let raisesLibTable : (Name.t, Exceptions.t) Hashtbl.t =
5252
in
5353
let stdlibBigInt = [("fromStringExn", [jsExnError])] in
5454
let stdlibBool = [("fromStringExn", [invalidArgument])] in
55-
let stdlibChar = [("fromIntExn", [invalidArgument])] in
5655
let stdlibError = [("raise", [jsExnError])] in
5756
let stdlibExn =
5857
[
@@ -143,7 +142,6 @@ let raisesLibTable : (Name.t, Exceptions.t) Hashtbl.t =
143142
("Belt_SetString", beltSet);
144143
("BigInt", stdlibBigInt);
145144
("Bool", stdlibBool);
146-
("Char", stdlibChar);
147145
("Error", stdlibError);
148146
("Exn", stdlibExn);
149147
("Js.Json", [("parseExn", [jsExnError])]);
@@ -164,8 +162,6 @@ let raisesLibTable : (Name.t, Exceptions.t) Hashtbl.t =
164162
("Stdlib.BigInt", stdlibBigInt);
165163
("Stdlib_Bool", stdlibBool);
166164
("Stdlib.Bool", stdlibBool);
167-
("Stdlib_Char", stdlibChar);
168-
("Stdlib.Char", stdlibChar);
169165
("Stdlib_Error", stdlibError);
170166
("Stdlib.Error", stdlibError);
171167
("Stdlib_Exn", stdlibExn);

lib/es6/Stdlib_Char.js renamed to lib/es6/Char.js

+10-27
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,6 @@
11

22

33

4-
function fromIntExn(n) {
5-
if (n < 0 || n > 255) {
6-
throw {
7-
RE_EXN_ID: "Invalid_argument",
8-
_1: "`Char.fromIntExn` expects an integer between 0 and 255",
9-
Error: new Error()
10-
};
11-
}
12-
return n;
13-
}
14-
15-
function fromInt(n) {
16-
if (n < 0 || n > 255) {
17-
return;
18-
} else {
19-
return n;
20-
}
21-
}
22-
234
function escaped(param) {
245
let exit = 0;
256
if (param >= 40) {
@@ -73,33 +54,35 @@ function escaped(param) {
7354
}
7455
}
7556

76-
function toLowerCaseAscii(c) {
57+
function lowercase_ascii(c) {
7758
if (c >= /* 'A' */65 && c <= /* 'Z' */90) {
7859
return c + 32 | 0;
7960
} else {
8061
return c;
8162
}
8263
}
8364

84-
function toUpperCaseAscii(c) {
65+
function uppercase_ascii(c) {
8566
if (c >= /* 'a' */97 && c <= /* 'z' */122) {
8667
return c - 32 | 0;
8768
} else {
8869
return c;
8970
}
9071
}
9172

92-
let lowercase_ascii = toLowerCaseAscii;
73+
function compare(c1, c2) {
74+
return c1 - c2 | 0;
75+
}
9376

94-
let uppercase_ascii = toUpperCaseAscii;
77+
function equal(c1, c2) {
78+
return (c1 - c2 | 0) === 0;
79+
}
9580

9681
export {
9782
escaped,
9883
lowercase_ascii,
9984
uppercase_ascii,
100-
toLowerCaseAscii,
101-
toUpperCaseAscii,
102-
fromIntExn,
103-
fromInt,
85+
compare,
86+
equal,
10487
}
10588
/* No side effect */

lib/es6/Stdlib.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function assertEqual(a, b) {
1212
RE_EXN_ID: "Assert_failure",
1313
_1: [
1414
"Stdlib.res",
15-
119,
15+
118,
1616
4
1717
],
1818
Error: new Error()
@@ -29,8 +29,6 @@ let $$BigInt;
2929

3030
let Bool;
3131

32-
let Char;
33-
3432
let Console;
3533

3634
let $$DataView;
@@ -123,7 +121,6 @@ export {
123121
$$Array,
124122
$$BigInt,
125123
Bool,
126-
Char,
127124
Console,
128125
$$DataView,
129126
$$Date,

lib/js/Stdlib_Char.js renamed to lib/js/Char.js

+10-27
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,6 @@
11
'use strict';
22

33

4-
function fromIntExn(n) {
5-
if (n < 0 || n > 255) {
6-
throw {
7-
RE_EXN_ID: "Invalid_argument",
8-
_1: "`Char.fromIntExn` expects an integer between 0 and 255",
9-
Error: new Error()
10-
};
11-
}
12-
return n;
13-
}
14-
15-
function fromInt(n) {
16-
if (n < 0 || n > 255) {
17-
return;
18-
} else {
19-
return n;
20-
}
21-
}
22-
234
function escaped(param) {
245
let exit = 0;
256
if (param >= 40) {
@@ -73,31 +54,33 @@ function escaped(param) {
7354
}
7455
}
7556

76-
function toLowerCaseAscii(c) {
57+
function lowercase_ascii(c) {
7758
if (c >= /* 'A' */65 && c <= /* 'Z' */90) {
7859
return c + 32 | 0;
7960
} else {
8061
return c;
8162
}
8263
}
8364

84-
function toUpperCaseAscii(c) {
65+
function uppercase_ascii(c) {
8566
if (c >= /* 'a' */97 && c <= /* 'z' */122) {
8667
return c - 32 | 0;
8768
} else {
8869
return c;
8970
}
9071
}
9172

92-
let lowercase_ascii = toLowerCaseAscii;
73+
function compare(c1, c2) {
74+
return c1 - c2 | 0;
75+
}
9376

94-
let uppercase_ascii = toUpperCaseAscii;
77+
function equal(c1, c2) {
78+
return (c1 - c2 | 0) === 0;
79+
}
9580

9681
exports.escaped = escaped;
9782
exports.lowercase_ascii = lowercase_ascii;
9883
exports.uppercase_ascii = uppercase_ascii;
99-
exports.toLowerCaseAscii = toLowerCaseAscii;
100-
exports.toUpperCaseAscii = toUpperCaseAscii;
101-
exports.fromIntExn = fromIntExn;
102-
exports.fromInt = fromInt;
84+
exports.compare = compare;
85+
exports.equal = equal;
10386
/* No side effect */

lib/js/Stdlib.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function assertEqual(a, b) {
1212
RE_EXN_ID: "Assert_failure",
1313
_1: [
1414
"Stdlib.res",
15-
119,
15+
118,
1616
4
1717
],
1818
Error: new Error()
@@ -29,8 +29,6 @@ let $$BigInt;
2929

3030
let Bool;
3131

32-
let Char;
33-
3432
let Console;
3533

3634
let $$DataView;
@@ -122,7 +120,6 @@ exports.IntervalId = IntervalId;
122120
exports.$$Array = $$Array;
123121
exports.$$BigInt = $$BigInt;
124122
exports.Bool = Bool;
125-
exports.Char = Char;
126123
exports.Console = Console;
127124
exports.$$DataView = $$DataView;
128125
exports.$$Date = $$Date;

packages/artifacts.txt

+8-9
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ lib/es6/Belt_internalMapString.js
7272
lib/es6/Belt_internalSetBuckets.js
7373
lib/es6/Belt_internalSetInt.js
7474
lib/es6/Belt_internalSetString.js
75+
lib/es6/Char.js
7576
lib/es6/Dom.js
7677
lib/es6/Dom_storage.js
7778
lib/es6/Dom_storage2.js
@@ -149,7 +150,6 @@ lib/es6/Stdlib_BigInt.js
149150
lib/es6/Stdlib_BigInt64Array.js
150151
lib/es6/Stdlib_BigUint64Array.js
151152
lib/es6/Stdlib_Bool.js
152-
lib/es6/Stdlib_Char.js
153153
lib/es6/Stdlib_Console.js
154154
lib/es6/Stdlib_DataView.js
155155
lib/es6/Stdlib_Date.js
@@ -244,6 +244,7 @@ lib/js/Belt_internalMapString.js
244244
lib/js/Belt_internalSetBuckets.js
245245
lib/js/Belt_internalSetInt.js
246246
lib/js/Belt_internalSetString.js
247+
lib/js/Char.js
247248
lib/js/Dom.js
248249
lib/js/Dom_storage.js
249250
lib/js/Dom_storage2.js
@@ -320,8 +321,6 @@ lib/js/Stdlib_AsyncIterator.js
320321
lib/js/Stdlib_BigInt.js
321322
lib/js/Stdlib_BigInt64Array.js
322323
lib/js/Stdlib_BigUint64Array.js
323-
lib/js/Stdlib_Bool.js
324-
lib/js/Stdlib_Char.js
325324
lib/js/Stdlib_Console.js
326325
lib/js/Stdlib_DataView.js
327326
lib/js/Stdlib_Date.js
@@ -621,6 +620,12 @@ lib/ocaml/Belt_internalSetString.cmi
621620
lib/ocaml/Belt_internalSetString.cmj
622621
lib/ocaml/Belt_internalSetString.cmt
623622
lib/ocaml/Belt_internalSetString.res
623+
lib/ocaml/Char.cmi
624+
lib/ocaml/Char.cmj
625+
lib/ocaml/Char.cmt
626+
lib/ocaml/Char.cmti
627+
lib/ocaml/Char.res
628+
lib/ocaml/Char.resi
624629
lib/ocaml/Dom.cmi
625630
lib/ocaml/Dom.cmj
626631
lib/ocaml/Dom.cmt
@@ -969,12 +974,6 @@ lib/ocaml/Stdlib_Bool.cmt
969974
lib/ocaml/Stdlib_Bool.cmti
970975
lib/ocaml/Stdlib_Bool.res
971976
lib/ocaml/Stdlib_Bool.resi
972-
lib/ocaml/Stdlib_Char.cmi
973-
lib/ocaml/Stdlib_Char.cmj
974-
lib/ocaml/Stdlib_Char.cmt
975-
lib/ocaml/Stdlib_Char.cmti
976-
lib/ocaml/Stdlib_Char.res
977-
lib/ocaml/Stdlib_Char.resi
978977
lib/ocaml/Stdlib_Console.cmi
979978
lib/ocaml/Stdlib_Console.cmj
980979
lib/ocaml/Stdlib_Console.cmt
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// FIXME:
2+
// This exists for compatibility reason.
3+
// Move this into Pervasives or Core
4+
5+
// Below is all deprecated and should be removed in v13
6+
17
type t = char
28

39
external code: t => int = "%identity"
@@ -6,22 +12,6 @@ external unsafe_chr: int => t = "%identity"
612

713
external chr: int => t = "%identity"
814

9-
external fromIntUnsafe: int => t = "%identity"
10-
11-
let fromIntExn = n =>
12-
if n < 0 || n > 255 {
13-
throw(Invalid_argument("`Char.fromIntExn` expects an integer between 0 and 255"))
14-
} else {
15-
fromIntUnsafe(n)
16-
}
17-
18-
let fromInt = n =>
19-
if n < 0 || n > 255 {
20-
None
21-
} else {
22-
Some(fromIntUnsafe(n))
23-
}
24-
2515
external bytes_create: int => array<char> = "Array"
2616

2717
external bytes_unsafe_set: (array<'a>, int, 'a) => unit = "%array_unsafe_set"
@@ -51,23 +41,19 @@ let escaped = param =>
5141
unsafe_to_string(s)
5242
}
5343

54-
let toLowerCaseAscii = c =>
44+
let lowercase_ascii = c =>
5545
if c >= 'A' && c <= 'Z' {
5646
unsafe_chr(code(c) + 32)
5747
} else {
5848
c
5949
}
6050

61-
let lowercase_ascii = toLowerCaseAscii
62-
63-
let toUpperCaseAscii = c =>
51+
let uppercase_ascii = c =>
6452
if c >= 'a' && c <= 'z' {
6553
unsafe_chr(code(c) - 32)
6654
} else {
6755
c
6856
}
6957

70-
let uppercase_ascii = toUpperCaseAscii
71-
72-
external equal: (char, char) => bool = "%equal"
73-
external compare: (char, char) => Stdlib_Ordering.t = "%compare"
58+
let compare = (c1, c2) => code(c1) - code(c2)
59+
let equal = (c1: t, c2: t) => compare(c1, c2) == 0

0 commit comments

Comments
 (0)