@@ -43,13 +43,13 @@ let ( & ) = Caml_nativeint_extern.logand
4343let ( << ) = Caml_nativeint_extern. shift_left
4444let lognot x = Caml_nativeint_extern. logxor x (- 1n )
4545
46- type t = Int64 of { hi : nativeint ; lo : nativeint ; }
46+ type t = { hi : nativeint ; [ @ bs. as " 0 " ] lo : nativeint ; [ @ bs. as " 1 " ] }
4747
4848external unsafe_to_int64 : t -> int64 = " %identity"
4949external unsafe_of_int64 : int64 -> t = " %identity"
5050
5151
52- let mk ~lo ~hi = Int64 {lo = lo >>> 0 ; hi}
52+ let mk ~lo ~hi = {lo = lo >>> 0 ; hi}
5353let min_int = mk ~lo: 0n ~hi: (- 0x80000000n )
5454(* The high bits are signed 0x80000000 |~ 0 *)
5555
@@ -67,10 +67,10 @@ let non_neg_signed x = (x & 0x8000_0000n) = 0n
6767let succ_aux ~x_lo ~x_hi =
6868 let lo = ( x_lo +~ 1n ) |~ 0n in
6969 mk ~lo ~hi: (( x_hi +~ if lo = 0n then 1n else 0n ) |~ 0n )
70- let succ (Int64 {lo = x_lo ; hi = x_hi } : t ) =
70+ let succ ( {lo = x_lo ; hi = x_hi } : t ) =
7171 succ_aux ~x_lo ~x_hi
7272
73- let neg (Int64 {lo;hi} ) =
73+ let neg ( {lo;hi} ) =
7474 let other_lo = (lognot lo +~ 1n ) |~ 0n in
7575 mk ~lo: other_lo
7676 ~hi: ((lognot hi +~ if other_lo = 0n then 1n else 0n ) |~ 0n )
@@ -81,7 +81,7 @@ let neg (Int64 {lo;hi} ) =
8181
8282
8383let add_aux
84- (Int64 {lo = x_lo ; hi = x_hi } : t )
84+ ( {lo = x_lo ; hi = x_hi } : t )
8585 ~y_lo ~y_hi =
8686 let lo = ( x_lo +~ y_lo) |~ 0n in
8787 let overflow =
@@ -101,13 +101,13 @@ let add_aux
101101
102102let add
103103 (self : t )
104- (Int64 {lo = y_lo ; hi = y_hi } : t ) =
104+ ( {lo = y_lo ; hi = y_hi } : t ) =
105105 add_aux self ~y_lo ~y_hi
106106
107107
108- (* let not (Int64 {lo; hi }) = mk ~lo:(lognot lo) ~hi:(lognot hi) *)
108+ (* let not ( {lo; hi }) = mk ~lo:(lognot lo) ~hi:(lognot hi) *)
109109
110- let eq (Int64 x ) (Int64 y ) = x.hi = y.hi && x.lo = y.lo
110+ let eq ( x ) ( y ) = x.hi = y.hi && x.lo = y.lo
111111
112112let equal_null x y =
113113 match Js. nullToOption y with
@@ -130,10 +130,10 @@ let sub_aux x ~lo ~hi =
130130 let y_hi = ((lognot hi +~ if y_lo = 0n then 1n else 0n ) |~ 0n ) in
131131 add_aux x ~y_lo ~y_hi
132132
133- let sub self (Int64 {lo;hi} )= sub_aux self ~lo ~hi
133+ let sub self ({lo;hi} )= sub_aux self ~lo ~hi
134134
135135
136- let lsl_ (Int64 {lo; hi} as x ) numBits =
136+ let lsl_ ( {lo; hi} as x ) numBits =
137137 if numBits = 0 then
138138 x
139139 else if numBits > = 32 then
@@ -146,7 +146,7 @@ let lsl_ (Int64 {lo; hi} as x) numBits =
146146 ( hi << numBits))
147147
148148
149- let lsr_ (Int64 {lo; hi} as x ) numBits =
149+ let lsr_ ( {lo; hi} as x ) numBits =
150150 if numBits = 0 then x
151151 else
152152 let offset = numBits - 32 in
@@ -163,7 +163,7 @@ let lsr_ (Int64 {lo; hi} as x) numBits =
163163 ( lo >>> numBits))
164164
165165
166- let asr_ (Int64 {lo; hi } as x ) numBits =
166+ let asr_ ( {lo; hi } as x ) numBits =
167167 if numBits = 0 then
168168 x
169169 else
@@ -180,25 +180,25 @@ let asr_ (Int64 {lo; hi } as x) numBits =
180180
181181
182182let is_zero = function
183- | Int64 {lo = 0n ; hi = 0n } -> true
183+ | {lo = 0n ; hi = 0n } -> true
184184 | _ -> false
185185
186186
187187
188188let rec mul this
189189 other =
190190 match this, other with
191- | Int64 {lo = 0n ; hi = 0n }, _
192- | _, Int64 {lo = 0n ; hi = 0n }
191+ | {lo = 0n ; hi = 0n }, _
192+ | _, {lo = 0n ; hi = 0n }
193193 -> zero
194- | Int64 {lo = 0n ; hi = - 0x80000000n }, Int64 {lo;_ }
195- | Int64 {lo;_}, Int64 {lo = 0n ; hi = - 0x80000000n }
194+ | {lo = 0n ; hi = - 0x80000000n }, {lo;_ }
195+ | {lo;_}, {lo = 0n ; hi = - 0x80000000n }
196196 ->
197197 if (lo & 0x1n ) = 0n then
198198 zero
199199 else min_int
200- | Int64 {lo = this_lo; hi = this_hi},
201- Int64 {lo = other_lo; hi = other_hi }
200+ | {lo = this_lo; hi = this_hi},
201+ {lo = other_lo; hi = other_hi }
202202 ->
203203 if this_hi < 0n then
204204 if other_hi < 0n then
@@ -251,18 +251,18 @@ let rec mul this
251251
252252(* Dispatched by the compiler, idea: should we do maximum sharing
253253*)
254- let xor (Int64 {lo = this_lo ; hi = this_hi } ) (Int64 {lo = other_lo ; hi = other_hi } ) =
254+ let xor ( {lo = this_lo ; hi = this_hi } ) ( {lo = other_lo ; hi = other_hi } ) =
255255 mk
256256 ~lo: (Caml_nativeint_extern. logxor this_lo other_lo)
257257 ~hi: (Caml_nativeint_extern. logxor this_hi other_hi)
258258
259259
260- let or_ (Int64 {lo = this_lo ; hi = this_hi } ) (Int64 {lo = other_lo ; hi = other_hi } ) =
260+ let or_ ( {lo = this_lo ; hi = this_hi } ) ( {lo = other_lo ; hi = other_hi } ) =
261261 mk
262262 ~lo: (Caml_nativeint_extern. logor this_lo other_lo)
263263 ~hi: (Caml_nativeint_extern. logor this_hi other_hi)
264264
265- let and_ (Int64 {lo = this_lo ; hi = this_hi } ) (Int64 {lo = other_lo ; hi = other_hi } ) =
265+ let and_ ( {lo = this_lo ; hi = this_hi } ) ( {lo = other_lo ; hi = other_hi } ) =
266266 mk
267267 ~lo: (Caml_nativeint_extern. logand this_lo other_lo)
268268 ~hi: (Caml_nativeint_extern. logand this_hi other_hi)
@@ -276,7 +276,7 @@ let and_ (Int64 {lo = this_lo; hi= this_hi}) (Int64 {lo = other_lo; hi = other_h
276276
277277type comparison = t -> t -> bool
278278
279- let ge (Int64 {hi; lo } : t ) (Int64 {hi = other_hi ; lo = other_lo } ) : bool =
279+ let ge ( {hi; lo } : t ) ( {hi = other_hi ; lo = other_lo } ) : bool =
280280 if hi > other_hi then true
281281 else if hi < other_hi then false
282282 else lo > = other_lo
@@ -285,7 +285,7 @@ let ge (Int64 {hi; lo } : t) (Int64 {hi = other_hi; lo = other_lo}) : bool =
285285
286286let neq x y = Pervasives. not (eq x y)
287287let lt x y = Pervasives. not (ge x y)
288- let gt (Int64 x ) (Int64 y ) =
288+ let gt ( x ) ( y ) =
289289 if x.hi > y.hi then
290290 true
291291 else if x.hi < y.hi then
@@ -298,7 +298,7 @@ let le x y = Pervasives.not (gt x y)
298298let min x y = if lt x y then x else y
299299let max x y = if gt x y then x else y
300300
301- let to_float (Int64 {hi; lo} : t ) =
301+ let to_float ( {hi; lo} : t ) =
302302 Caml_nativeint_extern. to_float ( hi *~ [% raw{| 0x100000000 | }] +~ lo)
303303
304304
@@ -341,15 +341,15 @@ external floor : float -> float = "floor" [@@bs.val] [@@bs.scope "Math"]
341341(* either top 11 bits are all 0 or all 1
342342 when it is all 1, we need exclude -2^53
343343*)
344- let isSafeInteger (Int64 {hi;lo} ) =
344+ let isSafeInteger ({hi;lo} ) =
345345 let top11Bits = hi >> 21 in
346346 top11Bits = 0n ||
347347 (top11Bits = - 1n &&
348348 Pervasives. not (lo = 0n && hi = (0xff_e0_00_00n |~ 0n )))
349349
350350external string_of_float : float -> string = " String" [@@ bs.val]
351351let rec to_string ( self : int64 ) =
352- let (Int64 {hi= self_hi;_} as self) = unsafe_of_int64 self in
352+ let ({hi= self_hi;_} as self) = unsafe_of_int64 self in
353353 if isSafeInteger self then
354354 string_of_float (to_float self)
355355 else
@@ -358,16 +358,16 @@ let rec to_string ( self : int64) =
358358 if eq self min_int then " -9223372036854775808"
359359 else " -" ^ to_string (unsafe_to_int64 (neg self))
360360 else (* large positive number *)
361- let (Int64 {lo ; hi} as approx_div1) = (of_float (floor (to_float self /. 10. ) )) in
362- let (Int64 { lo = rem_lo ;hi = rem_hi} ) = (* rem should be a pretty small number *)
361+ let ( {lo ; hi} as approx_div1) = (of_float (floor (to_float self /. 10. ) )) in
362+ let ( { lo = rem_lo ;hi = rem_hi} ) = (* rem should be a pretty small number *)
363363 self
364364 |. sub_aux ~lo: (lo << 3 ) ~hi: ((lo>>> 29 ) |~ (hi << 3 ))
365365 |. sub_aux ~lo: (lo << 1 ) ~hi: ((lo >>> 31 ) |~ (hi << 1 ))
366366 in
367367 if rem_lo = 0n && rem_hi = 0n then to_string (unsafe_to_int64 approx_div1) ^ " 0"
368368 else
369369 if rem_hi < 0n then
370- (* let (Int64 {lo = rem_lo}) = neg rem in *)
370+ (* let ( {lo = rem_lo}) = neg rem in *)
371371 let rem_lo = (lognot rem_lo +~ 1n ) >>> 0 |. Caml_nativeint_extern. to_float in
372372 let delta = (ceil (rem_lo /. 10. )) in
373373 let remainder = 10. *. delta -. rem_lo in
@@ -393,31 +393,31 @@ let rec to_string ( self : int64) =
393393
394394let rec div self other =
395395 match self, other with
396- | _ , Int64 {lo = 0n ; hi = 0n } ->
396+ | _ , {lo = 0n ; hi = 0n } ->
397397 raise Division_by_zero
398- | Int64 {lo = 0n ; hi = 0n }, _
398+ | {lo = 0n ; hi = 0n }, _
399399 -> zero
400- | Int64 {lo = 0n ; hi = - 0x8000_0000n }, _
400+ | {lo = 0n ; hi = - 0x8000_0000n }, _
401401 ->
402402 begin
403403 if eq other one || eq other neg_one then self
404404 else if eq other min_int then one
405405 else
406- let (Int64 {hi = other_hi;_}) = other in
406+ let ( {hi = other_hi;_}) = other in
407407 (* now |other| >= 2, so |this/other| < |MIN_VALUE|*)
408408 let half_this = asr_ self 1 in
409409 let approx = lsl_ (div half_this other) 1 in
410410 match approx with
411- | Int64 {lo = 0n ; hi = 0n }
411+ | {lo = 0n ; hi = 0n }
412412 -> if other_hi < 0n then one else neg one
413413 | _
414414 ->
415415 let rem = sub self (mul other approx) in
416416 add approx (div rem other)
417417 end
418- | _, Int64 {lo = 0n ; hi = - 0x8000_0000n }
418+ | _, {lo = 0n ; hi = - 0x8000_0000n }
419419 -> zero
420- | Int64 {lo = _; hi = self_hi}, Int64 {lo = _; hi = other_hi}
420+ | {lo = _; hi = self_hi}, {lo = _; hi = other_hi}
421421 ->
422422 if self_hi < 0n then
423423 if other_hi < 0n then
@@ -439,7 +439,7 @@ let rec div self other =
439439 else 2. ** (log2 -. 48. ) in
440440 let approxRes = ref (of_float approx.contents) in
441441 let approxRem = ref (mul approxRes.contents other) in
442- while (match approxRem.contents with Int64 {hi;_} -> hi) < 0n || gt approxRem.contents rem.contents do
442+ while (match approxRem.contents with {hi;_} -> hi) < 0n || gt approxRem.contents rem.contents do
443443 approx.contents < - approx.contents -. delta;
444444 approxRes.contents < - of_float approx.contents;
445445 approxRem.contents < - mul approxRes.contents other
@@ -459,7 +459,7 @@ let div_mod (self : int64) (other : int64) : int64 * int64 =
459459 let quotient = div (unsafe_of_int64 self) (unsafe_of_int64 other) in
460460 unsafe_to_int64 quotient, unsafe_to_int64 (sub (unsafe_of_int64 self) (mul quotient (unsafe_of_int64 other)))
461461
462- let compare (Int64 self ) (Int64 other ) =
462+ let compare ( self ) ( other ) =
463463 let v = Pervasives. compare self.hi other.hi in
464464 if v = 0 then
465465 Pervasives. compare self.lo other.lo
@@ -468,13 +468,13 @@ let compare (Int64 self) (Int64 other) =
468468let of_int32 (lo : nativeint ) =
469469 mk ~lo ~hi: (if lo < 0n then - 1n else 0n )
470470
471- let to_int32 (Int64 x ) = Caml_nativeint_extern. logor x.lo 0n (* signed integer *)
471+ let to_int32 ( x ) = Caml_nativeint_extern. logor x.lo 0n (* signed integer *)
472472
473473
474474(* width does matter, will it be relevant to endian order? *)
475475
476476let to_hex (x : int64 ) =
477- let Int64 {hi = x_hi; lo = x_lo} = unsafe_of_int64 x in
477+ let {hi = x_hi; lo = x_lo} = unsafe_of_int64 x in
478478 let aux v : string =
479479 Caml_string_extern. of_int (Caml_nativeint_extern. to_int (Caml_nativeint_extern. shift_right_logical v 0 )) ~base: 16
480480 in
@@ -494,7 +494,7 @@ let to_hex (x : int64) =
494494let discard_sign (x : int64 ) : int64 =
495495 let v = unsafe_of_int64 x in
496496 unsafe_to_int64
497- (match v with Int64 v -> Int64 { v with hi = Caml_nativeint_extern. logand 0x7fff_ffffn v.hi })
497+ (match v with v -> { v with hi = Caml_nativeint_extern. logand 0x7fff_ffffn v.hi })
498498
499499(* >>> 0 does not change its bit representation
500500 it simply makes sure it is an unsigned integer
@@ -508,7 +508,7 @@ let discard_sign (x : int64) : int64 =
508508 ]}
509509*)
510510
511- let float_of_bits (Int64 x : t ) : float =
511+ let float_of_bits ( x : t ) : float =
512512 ([% raw{| function (lo ,hi ){ return (new Float64Array(new Int32Array([lo,hi]).buffer))[0]} |}] : _ -> _ -> _ ) x.lo x.hi
513513
514514 (* let to_int32 (x : nativeint) = x |> Caml_nativeint_extern.to_int32
0 commit comments