Skip to content

Commit c0bfcf8

Browse files
committed
separate module
1 parent 9594d2c commit c0bfcf8

File tree

4 files changed

+128
-132
lines changed

4 files changed

+128
-132
lines changed

compiler/lib/flow.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ val the_string_of : Info.t -> Code.prim_arg -> string option
5858

5959
val the_native_string_of : Info.t -> Code.prim_arg -> Code.Native_string.t option
6060

61-
val the_int : Info.t -> Code.prim_arg -> Stdlib.Targetint.t option
61+
val the_int : Info.t -> Code.prim_arg -> Targetint.t option
6262

6363
val f : ?skip_param:bool -> Code.program -> Code.program * Info.t

compiler/lib/stdlib.ml

Lines changed: 0 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -288,137 +288,6 @@ module Nativeint = struct
288288
external equal : nativeint -> nativeint -> bool = "%equal"
289289
end
290290

291-
module Targetint : sig
292-
type t
293-
294-
val equal : t -> t -> bool
295-
296-
val compare : t -> t -> int
297-
298-
val to_string : t -> string
299-
300-
val to_int_exn : t -> int
301-
302-
val to_float : t -> float
303-
304-
val of_string : string -> t
305-
306-
val of_float : float -> t
307-
308-
val of_int_exn : int -> t
309-
310-
val of_int32_warning_on_overflow : int32 -> t
311-
312-
val of_nativeint_warning_on_overflow : nativeint -> t
313-
314-
val of_int_warning_on_overflow : int -> t
315-
316-
val succ : t -> t
317-
318-
val add : t -> t -> t
319-
320-
val sub : t -> t -> t
321-
322-
val mul : t -> t -> t
323-
324-
val div : t -> t -> t
325-
326-
val rem : t -> t -> t
327-
328-
val logand : t -> t -> t
329-
330-
val logor : t -> t -> t
331-
332-
val logxor : t -> t -> t
333-
334-
val shift_left : t -> int -> t
335-
336-
val shift_right : t -> int -> t
337-
338-
val shift_right_logical : t -> int -> t
339-
340-
val neg : t -> t
341-
342-
val abs : t -> t
343-
344-
val ( >= ) : t -> t -> bool
345-
346-
val ( <= ) : t -> t -> bool
347-
348-
val ( < ) : t -> t -> bool
349-
350-
val ( > ) : t -> t -> bool
351-
352-
val ( = ) : t -> t -> bool
353-
354-
val ( <> ) : t -> t -> bool
355-
356-
val is_zero : t -> bool
357-
358-
val num_bits : int
359-
360-
val zero : t
361-
362-
val one : t
363-
end = struct
364-
include Int32
365-
366-
let num_bits = 32
367-
368-
let is_zero x = equal x 0l
369-
370-
let of_int_exn x = of_int x
371-
372-
let to_int_exn x = to_int x
373-
374-
external ( < ) : int32 -> int32 -> bool = "%lessthan"
375-
376-
external ( <= ) : int32 -> int32 -> bool = "%lessequal"
377-
378-
external ( <> ) : int32 -> int32 -> bool = "%notequal"
379-
380-
external ( = ) : int32 -> int32 -> bool = "%equal"
381-
382-
external ( > ) : int32 -> int32 -> bool = "%greaterthan"
383-
384-
external ( >= ) : int32 -> int32 -> bool = "%greaterequal"
385-
386-
let warn_overflow ~to_dec ~to_hex i i32 =
387-
warn
388-
"Warning: integer overflow: integer 0x%s (%s) truncated to 0x%lx (%ld); the \
389-
generated code might be incorrect.@."
390-
(to_hex i)
391-
(to_dec i)
392-
i32
393-
i32
394-
395-
let convert_warning_on_overflow ~to_int32 ~of_int32 ~equal ~to_dec ~to_hex x =
396-
let i32 = to_int32 x in
397-
let x' = of_int32 i32 in
398-
if not (equal x' x) then warn_overflow ~to_dec ~to_hex x i32;
399-
i32
400-
401-
let of_int_warning_on_overflow i =
402-
convert_warning_on_overflow
403-
~to_int32:Int32.of_int
404-
~of_int32:Int32.to_int
405-
~equal:Int_replace_polymorphic_compare.( = )
406-
~to_dec:(Printf.sprintf "%d")
407-
~to_hex:(Printf.sprintf "%x")
408-
i
409-
410-
let of_int32_warning_on_overflow i = i
411-
412-
let of_nativeint_warning_on_overflow n =
413-
convert_warning_on_overflow
414-
~to_int32:Nativeint.to_int32
415-
~of_int32:Nativeint.of_int32
416-
~equal:Nativeint.equal
417-
~to_dec:(Printf.sprintf "%nd")
418-
~to_hex:(Printf.sprintf "%nx")
419-
n
420-
end
421-
422291
module Option = struct
423292
let map ~f x =
424293
match x with

compiler/lib/targetint.ml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
include Int32
2+
3+
let num_bits = 32
4+
5+
let is_zero x = equal x 0l
6+
7+
let of_int_exn x = of_int x
8+
9+
let to_int_exn x = to_int x
10+
11+
external ( < ) : int32 -> int32 -> bool = "%lessthan"
12+
13+
external ( <= ) : int32 -> int32 -> bool = "%lessequal"
14+
15+
external ( <> ) : int32 -> int32 -> bool = "%notequal"
16+
17+
external ( = ) : int32 -> int32 -> bool = "%equal"
18+
19+
external ( > ) : int32 -> int32 -> bool = "%greaterthan"
20+
21+
external ( >= ) : int32 -> int32 -> bool = "%greaterequal"
22+
23+
let warn_overflow ~to_dec ~to_hex i i32 =
24+
Stdlib.warn
25+
"Warning: integer overflow: integer 0x%s (%s) truncated to 0x%lx (%ld); the \
26+
generated code might be incorrect.@."
27+
(to_hex i)
28+
(to_dec i)
29+
i32
30+
i32
31+
32+
let convert_warning_on_overflow ~to_int32 ~of_int32 ~equal ~to_dec ~to_hex x =
33+
let i32 = to_int32 x in
34+
let x' = of_int32 i32 in
35+
if not (equal x' x) then warn_overflow ~to_dec ~to_hex x i32;
36+
i32
37+
38+
let of_int_warning_on_overflow i =
39+
convert_warning_on_overflow
40+
~to_int32:Int32.of_int
41+
~of_int32:Int32.to_int
42+
~equal:Int_replace_polymorphic_compare.( = )
43+
~to_dec:(Printf.sprintf "%d")
44+
~to_hex:(Printf.sprintf "%x")
45+
i
46+
47+
let of_int32_warning_on_overflow i = i
48+
49+
let of_nativeint_warning_on_overflow n =
50+
convert_warning_on_overflow
51+
~to_int32:Nativeint.to_int32
52+
~of_int32:Nativeint.of_int32
53+
~equal:Nativeint.equal
54+
~to_dec:(Printf.sprintf "%nd")
55+
~to_hex:(Printf.sprintf "%nx")
56+
n

compiler/lib/targetint.mli

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
type t
2+
3+
val equal : t -> t -> bool
4+
5+
val compare : t -> t -> int
6+
7+
val to_string : t -> string
8+
9+
val to_int_exn : t -> int
10+
11+
val to_float : t -> float
12+
13+
val of_string : string -> t
14+
15+
val of_float : float -> t
16+
17+
val of_int_exn : int -> t
18+
19+
val of_int32_warning_on_overflow : int32 -> t
20+
21+
val of_nativeint_warning_on_overflow : nativeint -> t
22+
23+
val of_int_warning_on_overflow : int -> t
24+
25+
val succ : t -> t
26+
27+
val add : t -> t -> t
28+
29+
val sub : t -> t -> t
30+
31+
val mul : t -> t -> t
32+
33+
val div : t -> t -> t
34+
35+
val rem : t -> t -> t
36+
37+
val logand : t -> t -> t
38+
39+
val logor : t -> t -> t
40+
41+
val logxor : t -> t -> t
42+
43+
val shift_left : t -> int -> t
44+
45+
val shift_right : t -> int -> t
46+
47+
val shift_right_logical : t -> int -> t
48+
49+
val neg : t -> t
50+
51+
val abs : t -> t
52+
53+
val ( >= ) : t -> t -> bool
54+
55+
val ( <= ) : t -> t -> bool
56+
57+
val ( < ) : t -> t -> bool
58+
59+
val ( > ) : t -> t -> bool
60+
61+
val ( = ) : t -> t -> bool
62+
63+
val ( <> ) : t -> t -> bool
64+
65+
val is_zero : t -> bool
66+
67+
val num_bits : int
68+
69+
val zero : t
70+
71+
val one : t

0 commit comments

Comments
 (0)