Skip to content

Commit 0eaf76e

Browse files
committed
clean a bit
1 parent 333cd9f commit 0eaf76e

33 files changed

+131
-172
lines changed

jscomp/core/lam_compile_primitive.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ let translate output_prefix loc (cxt : Lam_compile_context.t)
150150
assert false (* already handled by {!Lam_compile} *)
151151
| Pstringadd -> (
152152
match args with [ a; b ] -> E.string_append a b | _ -> assert false)
153-
| Pinit_mod -> E.runtime_call Primitive_modules.module_ "init_mod" args
154-
| Pupdate_mod -> E.runtime_call Primitive_modules.module_ "update_mod" args
153+
| Pinit_mod -> E.runtime_call Primitive_modules.module_ "init" args
154+
| Pupdate_mod -> E.runtime_call Primitive_modules.module_ "update" args
155155
| Psome -> (
156156
let arg = Ext_list.singleton_exn args in
157157
match arg.expression_desc with

jscomp/ext/primitive_modules.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,5 @@ let exceptions = "Primitive_exceptions"
5353
let curry = "Primitive_curry"
5454

5555
let util = "Primitive_util"
56+
57+
let pervasives = "Pervasives"

jscomp/frontend/ast_literal.ml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,28 @@ module Lid = struct
4949

5050
let type_bool : t = Lident "bool" (* use *predef* *)
5151

52+
let pervasives : t = Lident Primitive_modules.pervasives
53+
54+
(* FIXME: Use primitive module *)
5255
let js_oo : t = Lident "Js_OO"
5356

57+
(* FIXME: Use primitive module *)
5458
let js_meth_callback : t = Ldot (js_oo, "Callback")
5559

56-
let ignore_id : t = Ldot (Lident "Pervasives", "ignore")
60+
let ignore_id : t = Ldot (pervasives, "ignore")
5761

5862
let hidden_field n : t = Lident ("I" ^ n)
5963

64+
(* FIXME: Use primitive module *)
6065
let js_null : t = Ldot (Lident "Js", "null")
6166

67+
(* FIXME: Use primitive module *)
6268
let js_undefined : t = Ldot (Lident "Js", "undefined")
6369

70+
(* FIXME: Use primitive module *)
6471
let js_null_undefined : t = Ldot (Lident "Js", "null_undefined")
6572

73+
(* FIXME: Use primitive module *)
6674
let js_re_id : t = Ldot (Ldot (Lident "Js", "Re"), "t")
6775
end
6876

jscomp/frontend/ast_literal.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ module Lid : sig
4141

4242
val type_bigint : t
4343

44+
val pervasives : t
45+
4446
val js_oo : t
4547

4648
val js_meth_callback : t

jscomp/runtime/array.res

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22
// This exists for compatibility reason.
33
// Move this into Pervasives or Core
44

5-
// Note: Array.get/set is implicitly used by `array[idx]` syntax
5+
// Caution: `Array.get` is implicitly used by `array[idx]` syntax
66
external get: (array<'a>, int) => 'a = "%array_safe_get"
7+
8+
// Caution: `Array.set` is implicitly used by `array[idx]` syntax
79
external set: (array<'a>, int, 'a) => unit = "%array_safe_set"
810

911
// Below is all deprecated and should be removed in v13
1012

11-
let length = Primitive_array_extern.length
13+
external length: array<'a> => int = "%array_length"
1214

13-
let unsafe_get = Primitive_array_extern.getUnsafe
15+
external unsafe_get: (array<'a>, int) => 'a = "%array_unsafe_get"
1416

15-
let unsafe_set = Primitive_array_extern.setUnsafe
17+
external unsafe_set: (array<'a>, int, 'a) => unit = "%array_unsafe_set"
1618

1719
let init: (int, int => 'a) => array<'a> = %raw(`(length, f) => Array.from({ length }, f)`)
1820

jscomp/runtime/array.resi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ external set: (array<'a>, int, 'a) => unit = "%array_safe_set"
1212

1313
/** Return the length (number of elements) of the given array. */
1414
@deprecated("Use Core instead. This will be removed in v13")
15-
let length: array<'a> => int
15+
external length: array<'a> => int = "%array_length"
1616

1717
/** [Array.make n x] returns a fresh array of length [n],
1818
initialized with [x].
@@ -243,7 +243,7 @@ let stable_sort: (('a, 'a) => int, array<'a>) => unit
243243
let fast_sort: (('a, 'a) => int, array<'a>) => unit
244244

245245
@deprecated("Use Core instead. This will be removed in v13")
246-
let unsafe_get: (array<'a>, int) => 'a
246+
external unsafe_get: (array<'a>, int) => 'a = "%array_unsafe_get"
247247

248248
@deprecated("Use Core instead. This will be removed in v13")
249-
let unsafe_set: (array<'a>, int, 'a) => unit
249+
external unsafe_set: (array<'a>, int, 'a) => unit = "%array_unsafe_set"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
external toInt: float => int = "%intoffloat"

jscomp/runtime/primitive_hash.res

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
2424

25+
module Float = Primitive_float_extern
2526
module Obj = Primitive_object_extern
2627
module Js = Primitive_js_extern
28+
module String = Primitive_string_extern
2729

28-
external int_of_float: float => int = "%intoffloat"
2930
@send external charCodeAt: (string, int) => int = "charCodeAt"
30-
@get external stringLength: string => int = "length"
3131

3232
type rec cell<'a> = {
3333
content: 'a,
@@ -102,7 +102,7 @@ let hash_final_mix = h => {
102102
}
103103

104104
let hash_mix_string = (h, s) => {
105-
let len = stringLength(s)
105+
let len = String.length(s)
106106
let block = len / 4 - 1
107107
let hash = ref(h)
108108
for i in 0 to block {
@@ -136,7 +136,7 @@ let hash_mix_string = (h, s) => {
136136
let hash = (count: int, _limit, seed: int, obj: Obj.t): int => {
137137
let s = ref(seed)
138138
if Js.typeof(obj) == "number" {
139-
let u = int_of_float(Obj.magic(obj))
139+
let u = Float.toInt(Obj.magic(obj))
140140
s.contents = hash_mix_int(s.contents, u + u + 1)
141141
hash_final_mix(s.contents)
142142
} else if Js.typeof(obj) == "string" {
@@ -155,7 +155,7 @@ let hash = (count: int, _limit, seed: int, obj: Obj.t): int => {
155155
while !is_empty_queue(queue) && num.contents > 0 {
156156
let obj = unsafe_pop(queue)
157157
if Js.typeof(obj) == "number" {
158-
let u = int_of_float(Obj.magic(obj))
158+
let u = Float.toInt(Obj.magic(obj))
159159
s.contents = hash_mix_int(s.contents, u + u + 1)
160160
num.contents = num.contents - 1
161161
} else if Js.typeof(obj) == "string" {

jscomp/runtime/primitive_int.res

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,16 @@ let max = (x: int, y: int): int =>
2121
y
2222
}
2323

24-
external div: (int, int) => int = "%divint"
25-
2624
let div = (x: int, y: int) =>
2725
if y == 0 {
2826
raise(Division_by_zero)
2927
} else {
30-
div(x, y)
28+
Primitive_int_extern.div(x, y)
3129
}
3230

33-
external mod_: (int, int) => int = "%modint"
34-
3531
let mod_ = (x: int, y: int) =>
3632
if y == 0 {
3733
raise(Division_by_zero)
3834
} else {
39-
mod_(x, y)
35+
Primitive_int_extern.mod_(x, y)
4036
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
external div: (int, int) => int = "%divint"
2+
3+
external mod_: (int, int) => int = "%modint"
Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,32 @@
1-
/**
2-
Nullable value of this type can be either null or 'a. This type is equivalent to Js.Null.t.
3-
*/
41
@unboxed
52
type null<+'a> = Value('a) | @as(null) Null
63

7-
/**
8-
A value of this type can be either undefined or 'a. This type is equivalent to Js.Undefined.t.
9-
*/
104
type undefined<+'a>
115

126
@unboxed type nullable<+'a> = Value('a) | @as(null) Null | @as(undefined) Undefined
137

14-
/***
15-
A value of this type can be undefined, null or 'a. This type is equivalent to Js.Null_undefined.t.
16-
*/
17-
188
type null_undefined<+'a> = nullable<'a>
199

20-
/**
21-
The same as empty in `Js.Null`. Compiles to `null`.
22-
*/
2310
external null: null<'a> = "%null"
2411

25-
/**
26-
The same as empty `Js.Undefined`. Compiles to `undefined`.
27-
*/
2812
external undefined: undefined<'a> = "%undefined"
2913

3014
external isNullable: nullable<'a> => bool = "%is_nullable"
3115

32-
/** The same as {!test} except that it is more permissive on the types of input */
3316
external testAny: 'a => bool = "%is_nullable"
3417

35-
/**
36-
`typeof x` will be compiled as `typeof x` in JS. Please consider functions in
37-
`Js.Types` for a type safe way of reflection.
38-
*/
3918
external typeof: 'a => string = "%typeof"
4019

4120
external eqNull: ('a, null<'a>) => bool = "%equal_null"
21+
4222
external eqUndefined: ('a, undefined<'a>) => bool = "%equal_undefined"
43-
external eqNullable: ('a, nullable<'a>) => bool = "%equal_nullable"
4423

45-
/* ## Operators */
24+
external eqNullable: ('a, nullable<'a>) => bool = "%equal_nullable"
4625

47-
/**
48-
`unsafe_lt(a, b)` will be compiled as `a < b`.
49-
It is marked as unsafe, since it is impossible
50-
to give a proper semantics for comparision which applies to any type
51-
*/
52-
external unsafe_lt: ('a, 'a) => bool = "%unsafe_lt"
26+
external lt: ('a, 'a) => bool = "%unsafe_lt"
5327

54-
/**
55-
`unsafe_le(a, b)` will be compiled as `a <= b`.
56-
See also `Js.unsafe_lt`.
57-
*/
58-
external unsafe_le: ('a, 'a) => bool = "%unsafe_le"
28+
external le: ('a, 'a) => bool = "%unsafe_le"
5929

60-
/**
61-
`unsafe_gt(a, b)` will be compiled as `a > b`.
62-
See also `Js.unsafe_lt`.
63-
*/
64-
external unsafe_gt: ('a, 'a) => bool = "%unsafe_gt"
30+
external gt: ('a, 'a) => bool = "%unsafe_gt"
6531

66-
/**
67-
`unsafe_ge(a, b)` will be compiled as `a >= b`.
68-
See also `Js.unsafe_lt`.
69-
*/
70-
external unsafe_ge: ('a, 'a) => bool = "%unsafe_ge"
32+
external ge: ('a, 'a) => bool = "%unsafe_ge"

jscomp/runtime/primitive_module.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module type Empty = {}
1818
spit out ("CamlinternalMod".[init_mod|update_mod] unless we intercept it
1919
in the lambda layer
2020
*/
21-
let init_mod = (loc: (string, int, int), shape: shape) => {
21+
let init = (loc: (string, int, int), shape: shape) => {
2222
let undef_module = _ => raise(Undefined_recursive_module(loc))
2323
let rec loop = (shape: shape, struct_: Obj.t, idx) =>
2424
switch shape {
@@ -44,7 +44,7 @@ let init_mod = (loc: (string, int, int), shape: shape) => {
4444
/* Note the [shape] passed between [init_mod] and [update_mod] is always the same
4545
and we assume [module] is encoded as an array
4646
*/
47-
let update_mod = (shape: shape, o: Obj.t, n: Obj.t): unit => {
47+
let update = (shape: shape, o: Obj.t, n: Obj.t): unit => {
4848
let rec aux = (shape: shape, o, n, parent, i) =>
4949
switch shape {
5050
| Function => Obj.setField(parent, i, n)

jscomp/runtime/primitive_module.resi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
external import: 'a => promise<'a> = "%import"
22

33
type shape
4-
let init_mod: ((string, int, int), shape) => Primitive_object.t
5-
let update_mod: (shape, Primitive_object.t, Primitive_object.t) => unit
4+
5+
let init: ((string, int, int), shape) => Primitive_object.t
6+
7+
let update: (shape, Primitive_object.t, Primitive_object.t) => unit

jscomp/runtime/primitive_object.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ let rec equal = (a: t, b: t): bool =>
288288
if O.isArray(a) {
289289
aux_equal_length((magic(a): array<t>), (magic(b): array<t>), 0, len_a)
290290
} else if %raw(`a instanceof Date && b instanceof Date`) {
291-
!(Js.unsafe_gt(a, b) || Js.unsafe_lt(a, b))
291+
!(Js.gt(a, b) || Js.lt(a, b))
292292
} else {
293293
aux_obj_equal(a, b)
294294
}

0 commit comments

Comments
 (0)