Skip to content

Commit 062452f

Browse files
authored
Convert most of jscomp/runtime to .res (#6318)
1 parent 2781656 commit 062452f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+2657
-2715
lines changed

jscomp/runtime/bs_stdlib_mini.mli

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

jscomp/runtime/bs_stdlib_mini.resi

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
Since [others] depend on this file, its public mli files **should not
3+
export types** introduced here, otherwise it would cause
4+
conflicts here.
5+
6+
If the type exported here is also exported in modules from others,
7+
you will get a type not equivalent.
8+
9+
10+
Types defined here but should not export:
11+
- ref (make sure not exported in *.mli in others folder)
12+
*/
13+
external \"^": (string, string) => string = "#string_append"
14+
external \"=": ('a, 'a) => bool = "%equal"
15+
external \"<>": ('a, 'a) => bool = "%notequal"
16+
external \"==": ('a, 'a) => bool = "%eq"
17+
external \"!=": ('a, 'a) => bool = "%noteq"
18+
external \"<": ('a, 'a) => bool = "%lessthan"
19+
external \">": ('a, 'a) => bool = "%greaterthan"
20+
external \"<=": ('a, 'a) => bool = "%lessequal"
21+
external \">=": ('a, 'a) => bool = "%greaterequal"
22+
external \"+": (int, int) => int = "%addint"
23+
external \"-": (int, int) => int = "%subint"
24+
external \"~-": int => int = "%negint"
25+
external \"*": (int, int) => int = "%mulint"
26+
external \"/": (int, int) => int = "%divint"
27+
external lsl: (int, int) => int = "%lslint"
28+
external lor: (int, int) => int = "%orint"
29+
external land: (int, int) => int = "%andint"
30+
external mod: (int, int) => int = "%modint"
31+
external lsr: (int, int) => int = "%lsrint"
32+
external lxor: (int, int) => int = "%xorint"
33+
external asr: (int, int) => int = "%asrint"
34+
type ref<'a> = {mutable contents: 'a}
35+
external ref: 'a => ref<'a> = "%makemutable"
36+
37+
external \"||": (bool, bool) => bool = "%sequor"
38+
external \"&&": (bool, bool) => bool = "%sequand"
39+
external not: bool => bool = "%boolnot"
40+
41+
external raise: exn => 'a = "%raise"
42+
external ignore: 'a => unit = "%ignore"
43+
external \"|>": ('a, 'a => 'b) => 'b = "%revapply"
44+
external \"@@": ('a => 'b, 'a) => 'b = "%apply"
45+
46+
@val @scope("Math") external \"**": (float, float) => float = "pow"
47+
external \"~-.": float => float = "%negfloat"
48+
external \"+.": (float, float) => float = "%addfloat"
49+
external \"-.": (float, float) => float = "%subfloat"
50+
external \"*.": (float, float) => float = "%mulfloat"
51+
external \"/.": (float, float) => float = "%divfloat"
52+
53+
module Obj: {
54+
type t
55+
external field: (t, int) => t = "%obj_field"
56+
external set_field: (t, int, t) => unit = "%obj_set_field"
57+
external tag: t => int = "?obj_tag"
58+
external repr: 'a => t = "%identity"
59+
external obj: t => 'a = "%identity"
60+
external magic: 'a => 'b = "%identity"
61+
external size: t => int = "#obj_length"
62+
}
63+
64+
module Pervasives: {
65+
external compare: ('a, 'a) => int = "%compare"
66+
external not: bool => bool = "%boolnot"
67+
external min: ('a, 'a) => 'a = "%bs_min"
68+
external max: ('a, 'a) => 'a = "%bs_max"
69+
external \"=": ('a, 'a) => bool = "%equal"
70+
}

jscomp/runtime/caml.ml

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

jscomp/runtime/caml.res

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/* Copyright (C) 2015-2016 Bloomberg Finance L.P.
2+
*
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU Lesser General Public License as published by
5+
* the Free Software Foundation, either version 3 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* In addition to the permissions granted to you by the LGPL, you may combine
9+
* or link a "work that uses the Library" with a publicly distributed version
10+
* of this file to produce a combined library or application, then distribute
11+
* that combined work under the terms of your choosing, with no requirement
12+
* to comply with the obligations normally placed on you by section 4 of the
13+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
14+
* should you choose to use a later version).
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Lesser General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Lesser General Public License
22+
* along with this program; if not, write to the Free Software
23+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24+
25+
let int_compare = (x: int, y: int): int =>
26+
if x < y {
27+
-1
28+
} else if x == y {
29+
0
30+
} else {
31+
1
32+
}
33+
let bool_compare = (x: bool, y: bool): int =>
34+
switch (x, y) {
35+
| (true, true) | (false, false) => 0
36+
| (true, false) => 1
37+
| (false, true) => -1
38+
}
39+
40+
let float_compare = (x: float, y: float) =>
41+
if x == y {
42+
0
43+
} else if x < y {
44+
-1
45+
} else if x > y {
46+
1
47+
} else if x == x {
48+
1
49+
} else if y == y {
50+
-1
51+
} else {
52+
0
53+
}
54+
55+
/* Lexical order */
56+
let string_compare = (s1: string, s2: string): int =>
57+
if s1 == s2 {
58+
0
59+
} else if s1 < s2 {
60+
-1
61+
} else {
62+
1
63+
}
64+
65+
type selector<'a> = ('a, 'a) => 'a
66+
67+
/* could be replaced by [Math.min], but it seems those built-ins are slower */
68+
let bool_min = (x: bool, y): bool =>
69+
if x {
70+
y
71+
} else {
72+
x
73+
}
74+
let int_min = (x: int, y: int): int =>
75+
if x < y {
76+
x
77+
} else {
78+
y
79+
}
80+
let float_min = (x: float, y) =>
81+
if x < y {
82+
x
83+
} else {
84+
y
85+
}
86+
let string_min = (x: string, y) =>
87+
if x < y {
88+
x
89+
} else {
90+
y
91+
}
92+
93+
let bool_max = (x: bool, y): bool =>
94+
if x {
95+
x
96+
} else {
97+
y
98+
}
99+
let int_max = (x: int, y: int): int =>
100+
if x > y {
101+
x
102+
} else {
103+
y
104+
}
105+
let float_max = (x: float, y) =>
106+
if x > y {
107+
x
108+
} else {
109+
y
110+
}
111+
let string_max = (x: string, y) =>
112+
if x > y {
113+
x
114+
} else {
115+
y
116+
}
117+
type i64 = Caml_int64_extern.t
118+
let i64_eq = (x: i64, y: i64) => x.lo == y.lo && x.hi == y.hi
119+
120+
let i64_ge = ({hi, lo}: i64, {hi: other_hi, lo: other_lo}: i64): bool =>
121+
if hi > other_hi {
122+
true
123+
} else if hi < other_hi {
124+
false
125+
} else {
126+
lo >= other_lo
127+
}
128+
129+
let i64_neq = (x, y) => Pervasives.not(i64_eq(x, y))
130+
let i64_lt = (x, y) => Pervasives.not(i64_ge(x, y))
131+
let i64_gt = (x: i64, y: i64) =>
132+
if x.hi > y.hi {
133+
true
134+
} else if x.hi < y.hi {
135+
false
136+
} else {
137+
x.lo > y.lo
138+
}
139+
140+
let i64_le = (x, y) => Pervasives.not(i64_gt(x, y))
141+
142+
let i64_min = (x, y) =>
143+
if i64_lt(x, y) {
144+
x
145+
} else {
146+
y
147+
}
148+
let i64_max = (x, y) =>
149+
if i64_gt(x, y) {
150+
x
151+
} else {
152+
y
153+
}

0 commit comments

Comments
 (0)