Skip to content

Commit 84d5a11

Browse files
committed
add Stdlib Bool and Char modules
1 parent f6d36b5 commit 84d5a11

18 files changed

+378
-107
lines changed

analysis/reanalyze/src/ExnLib.ml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ let raisesLibTable : (Name.t, Exceptions.t) Hashtbl.t =
5151
]
5252
in
5353
let stdlibBigInt = [("fromStringExn", [jsExnError])] in
54+
let stdlibBool = [("fromStringExn", [invalidArgument])] in
55+
let stdlibChar = [("fromIntExn", [invalidArgument])] in
5456
let stdlibError = [("raise", [jsExnError])] in
5557
let stdlibExn =
5658
[
@@ -140,7 +142,8 @@ let raisesLibTable : (Name.t, Exceptions.t) Hashtbl.t =
140142
("Belt_SetInt", beltSet);
141143
("Belt_SetString", beltSet);
142144
("BigInt", stdlibBigInt);
143-
("Char", [("chr", [invalidArgument])]);
145+
("Bool", stdlibBool);
146+
("Char", stdlibChar);
144147
("Error", stdlibError);
145148
("Exn", stdlibExn);
146149
("Js.Json", [("parseExn", [jsExnError])]);
@@ -159,6 +162,10 @@ let raisesLibTable : (Name.t, Exceptions.t) Hashtbl.t =
159162
("Stdlib", stdlib);
160163
("Stdlib_BigInt", stdlibBigInt);
161164
("Stdlib.BigInt", stdlibBigInt);
165+
("Stdlib_Bool", stdlibBool);
166+
("Stdlib.Bool", stdlibBool);
167+
("Stdlib_Char", stdlibChar);
168+
("Stdlib.Char", stdlibChar);
162169
("Stdlib_Error", stdlibError);
163170
("Stdlib.Error", stdlibError);
164171
("Stdlib_Exn", stdlibExn);

lib/es6/Stdlib.js

Lines changed: 7 additions & 1 deletion
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-
117,
15+
119,
1616
4
1717
],
1818
Error: new Error()
@@ -27,6 +27,10 @@ let $$Array;
2727

2828
let $$BigInt;
2929

30+
let Bool;
31+
32+
let Char;
33+
3034
let Console;
3135

3236
let $$DataView;
@@ -118,6 +122,8 @@ export {
118122
IntervalId,
119123
$$Array,
120124
$$BigInt,
125+
Bool,
126+
Char,
121127
Console,
122128
$$DataView,
123129
$$Date,

lib/es6/Stdlib_Bool.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
3+
4+
function toString(b) {
5+
if (b) {
6+
return "true";
7+
} else {
8+
return "false";
9+
}
10+
}
11+
12+
function fromString(s) {
13+
switch (s) {
14+
case "false" :
15+
return false;
16+
case "true" :
17+
return true;
18+
default:
19+
return;
20+
}
21+
}
22+
23+
function fromStringExn(param) {
24+
switch (param) {
25+
case "false" :
26+
return false;
27+
case "true" :
28+
return true;
29+
default:
30+
throw {
31+
RE_EXN_ID: "Invalid_argument",
32+
_1: "Bool.fromStringExn: value is neither \"true\" nor \"false\"",
33+
Error: new Error()
34+
};
35+
}
36+
}
37+
38+
export {
39+
toString,
40+
fromString,
41+
fromStringExn,
42+
}
43+
/* No side effect */

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

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
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+
423
function escaped(param) {
524
let exit = 0;
625
if (param >= 40) {
@@ -54,35 +73,33 @@ function escaped(param) {
5473
}
5574
}
5675

57-
function lowercase_ascii(c) {
76+
function toLowerCaseAscii(c) {
5877
if (c >= /* 'A' */65 && c <= /* 'Z' */90) {
5978
return c + 32 | 0;
6079
} else {
6180
return c;
6281
}
6382
}
6483

65-
function uppercase_ascii(c) {
84+
function toUpperCaseAscii(c) {
6685
if (c >= /* 'a' */97 && c <= /* 'z' */122) {
6786
return c - 32 | 0;
6887
} else {
6988
return c;
7089
}
7190
}
7291

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

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

8196
export {
8297
escaped,
8398
lowercase_ascii,
8499
uppercase_ascii,
85-
compare,
86-
equal,
100+
toLowerCaseAscii,
101+
toUpperCaseAscii,
102+
fromIntExn,
103+
fromInt,
87104
}
88105
/* No side effect */

lib/js/Stdlib.js

Lines changed: 7 additions & 1 deletion
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-
117,
15+
119,
1616
4
1717
],
1818
Error: new Error()
@@ -27,6 +27,10 @@ let $$Array;
2727

2828
let $$BigInt;
2929

30+
let Bool;
31+
32+
let Char;
33+
3034
let Console;
3135

3236
let $$DataView;
@@ -117,6 +121,8 @@ exports.TimeoutId = TimeoutId;
117121
exports.IntervalId = IntervalId;
118122
exports.$$Array = $$Array;
119123
exports.$$BigInt = $$BigInt;
124+
exports.Bool = Bool;
125+
exports.Char = Char;
120126
exports.Console = Console;
121127
exports.$$DataView = $$DataView;
122128
exports.$$Date = $$Date;

lib/js/Stdlib_Bool.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use strict';
2+
3+
4+
function toString(b) {
5+
if (b) {
6+
return "true";
7+
} else {
8+
return "false";
9+
}
10+
}
11+
12+
function fromString(s) {
13+
switch (s) {
14+
case "false" :
15+
return false;
16+
case "true" :
17+
return true;
18+
default:
19+
return;
20+
}
21+
}
22+
23+
function fromStringExn(param) {
24+
switch (param) {
25+
case "false" :
26+
return false;
27+
case "true" :
28+
return true;
29+
default:
30+
throw {
31+
RE_EXN_ID: "Invalid_argument",
32+
_1: "Bool.fromStringExn: value is neither \"true\" nor \"false\"",
33+
Error: new Error()
34+
};
35+
}
36+
}
37+
38+
exports.toString = toString;
39+
exports.fromString = fromString;
40+
exports.fromStringExn = fromStringExn;
41+
/* No side effect */

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

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
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+
423
function escaped(param) {
524
let exit = 0;
625
if (param >= 40) {
@@ -54,33 +73,31 @@ function escaped(param) {
5473
}
5574
}
5675

57-
function lowercase_ascii(c) {
76+
function toLowerCaseAscii(c) {
5877
if (c >= /* 'A' */65 && c <= /* 'Z' */90) {
5978
return c + 32 | 0;
6079
} else {
6180
return c;
6281
}
6382
}
6483

65-
function uppercase_ascii(c) {
84+
function toUpperCaseAscii(c) {
6685
if (c >= /* 'a' */97 && c <= /* 'z' */122) {
6786
return c - 32 | 0;
6887
} else {
6988
return c;
7089
}
7190
}
7291

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

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

8196
exports.escaped = escaped;
8297
exports.lowercase_ascii = lowercase_ascii;
8398
exports.uppercase_ascii = uppercase_ascii;
84-
exports.compare = compare;
85-
exports.equal = equal;
99+
exports.toLowerCaseAscii = toLowerCaseAscii;
100+
exports.toUpperCaseAscii = toUpperCaseAscii;
101+
exports.fromIntExn = fromIntExn;
102+
exports.fromInt = fromInt;
86103
/* No side effect */

runtime/Char.resi

Lines changed: 0 additions & 54 deletions
This file was deleted.

runtime/Stdlib.res

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ include Stdlib_Global
22

33
module Array = Stdlib_Array
44
module BigInt = Stdlib_BigInt
5+
module Bool = Stdlib_Bool
6+
module Char = Stdlib_Char
57
module Console = Stdlib_Console
68
module DataView = Stdlib_DataView
79
module Date = Stdlib_Date

0 commit comments

Comments
 (0)