Skip to content

Commit 20f2060

Browse files
committed
move cppo script
1 parent 8d4874a commit 20f2060

File tree

6 files changed

+69
-51
lines changed

6 files changed

+69
-51
lines changed

packages/@rescript/runtime/cppo/internal_map.res.cppo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ let rec getUndefined = (n, x: key) =>
7171

7272
let rec getExn = (n, x: key) =>
7373
switch n {
74-
| None => raise(Not_found)
74+
| None => throw(Not_found)
7575
| Some(n) =>
7676
let v = n.N.key
7777
if x == v {

packages/@rescript/runtime/cppo/internal_set.res.cppo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ let rec getUndefined = (n: t, x: value) =>
113113

114114
let rec getExn = (n: t, x: value) =>
115115
switch n {
116-
| None => raise(Not_found)
116+
| None => throw(Not_found)
117117
| Some(t) =>
118118
let v = t.value
119119
if x == v {

packages/@rescript/runtime/cppo/map.resi.cppo

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,24 @@ let findFirstByU: (t<'v>, (key, 'v) => bool) => option<(key, 'v)>
3636
`findFirstBy(m, p)` uses funcion `f` to find the first key value pair
3737
to match predicate `p`.
3838

39+
## Examples
40+
3941
```rescript
40-
let s0 = fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2,"(3, ""))])
41-
findFirstBy(s0, (k, v) => k == 4) == option((4, "4"))
42+
#ifdef TYPE_STRING
43+
let mapString = Belt.Map.String.fromArray([("1", "one"), ("2", "two"), ("3", "three")])
44+
45+
mapString->
46+
Belt.Map.String.findFirstBy((k, v) => k == "1" && v == "one")
47+
->assertEqual(Some("1", "one"))
48+
#elif defined TYPE_INT
49+
let mapInt = Belt.Map.Int.fromArray([(1, "one"), (2, "two"), (3, "three")])
50+
51+
mapInt->
52+
Belt.Map.Int.findFirstBy((k, v) => k == 1 && v == "one")
53+
->assertEqual(Some(1, "one"))
54+
#else
55+
[%error "unknown type"]
56+
#endif
4257
```
4358
*/
4459
let findFirstBy: (t<'v>, (key, 'v) => bool) => option<(key, 'v)>

packages/@rescript/runtime/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
"clean:rewatch": "rewatch clean",
4545
"build:rewatch": "rewatch build",
4646
"clean:bsb": "rescript clean",
47-
"build:bsb": "rescript build"
47+
"build:bsb": "rescript build",
48+
"cppo": "node scripts/cppo.js"
4849
},
4950
"devDependencies": {
5051
"rescript": "workspace:^"
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// @ts-check
2+
3+
import * as path from "node:path";
4+
import { execFileSync } from "node:child_process";
5+
6+
const targets = [
7+
["Belt_HashSetString.res", "hashset.res.cppo", "TYPE_STRING"],
8+
["Belt_HashSetString.resi", "hashset.resi.cppo", "TYPE_STRING"],
9+
["Belt_HashSetInt.res", "hashset.res.cppo", "TYPE_INT"],
10+
["Belt_HashSetInt.resi", "hashset.resi.cppo", "TYPE_INT"],
11+
["Belt_HashMapString.res", "hashmap.res.cppo", "TYPE_STRING"],
12+
["Belt_HashMapString.resi", "hashmap.resi.cppo", "TYPE_STRING"],
13+
["Belt_HashMapInt.res", "hashmap.res.cppo", "TYPE_INT"],
14+
["Belt_HashMapInt.resi", "hashmap.resi.cppo", "TYPE_INT"],
15+
["Belt_MapString.res", "map.res.cppo", "TYPE_STRING"],
16+
["Belt_MapString.resi", "map.resi.cppo", "TYPE_STRING"],
17+
["Belt_MapInt.res", "map.res.cppo", "TYPE_INT"],
18+
["Belt_MapInt.resi", "map.resi.cppo", "TYPE_INT"],
19+
["Belt_SetString.res", "belt_Set.res.cppo", "TYPE_STRING"],
20+
["Belt_SetString.resi", "belt_Set.resi.cppo", "TYPE_STRING"],
21+
["Belt_SetInt.res", "belt_Set.res.cppo", "TYPE_INT"],
22+
["Belt_SetInt.resi", "belt_Set.resi.cppo", "TYPE_INT"],
23+
["Belt_MutableMapString.res", "mapm.res.cppo", "TYPE_STRING"],
24+
["Belt_MutableMapString.resi", "mapm.resi.cppo", "TYPE_STRING"],
25+
["Belt_MutableMapInt.res", "mapm.res.cppo", "TYPE_INT"],
26+
["Belt_MutableMapInt.resi", "mapm.resi.cppo", "TYPE_INT"],
27+
["Belt_MutableSetString.res", "setm.res.cppo", "TYPE_STRING"],
28+
["Belt_MutableSetString.resi", "setm.resi.cppo", "TYPE_STRING"],
29+
["Belt_MutableSetInt.res", "setm.res.cppo", "TYPE_INT"],
30+
["Belt_MutableSetInt.resi", "setm.resi.cppo", "TYPE_INT"],
31+
["Belt_SortArrayString.res", "sort.res.cppo", "TYPE_STRING"],
32+
["Belt_SortArrayString.resi", "sort.resi.cppo", "TYPE_STRING"],
33+
["Belt_SortArrayInt.res", "sort.res.cppo", "TYPE_INT"],
34+
["Belt_SortArrayInt.resi", "sort.resi.cppo", "TYPE_INT"],
35+
["Belt_internalMapString.res", "internal_map.res.cppo", "TYPE_STRING"],
36+
["Belt_internalMapInt.res", "internal_map.res.cppo", "TYPE_INT"],
37+
["Belt_internalSetString.res", "internal_set.res.cppo", "TYPE_STRING"],
38+
["Belt_internalSetInt.res", "internal_set.res.cppo", "TYPE_INT"],
39+
];
40+
41+
const runtimePath = path.join(import.meta.dirname, "..");
42+
for (const [output, input, type] of targets) {
43+
const inputPath = path.join(runtimePath, "cppo", input);
44+
const outputPath = path.join(runtimePath, output);
45+
execFileSync("cppo", ["-n", "-D", type, inputPath, "-o", outputPath], {
46+
stdio: "inherit",
47+
});
48+
}

scripts/cppo.js

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

0 commit comments

Comments
 (0)