-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
128 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
include Int32 | ||
|
||
let num_bits = 32 | ||
|
||
let is_zero x = equal x 0l | ||
|
||
let of_int_exn x = of_int x | ||
|
||
let to_int_exn x = to_int x | ||
|
||
external ( < ) : int32 -> int32 -> bool = "%lessthan" | ||
|
||
external ( <= ) : int32 -> int32 -> bool = "%lessequal" | ||
|
||
external ( <> ) : int32 -> int32 -> bool = "%notequal" | ||
|
||
external ( = ) : int32 -> int32 -> bool = "%equal" | ||
|
||
external ( > ) : int32 -> int32 -> bool = "%greaterthan" | ||
|
||
external ( >= ) : int32 -> int32 -> bool = "%greaterequal" | ||
|
||
let warn_overflow ~to_dec ~to_hex i i32 = | ||
Stdlib.warn | ||
"Warning: integer overflow: integer 0x%s (%s) truncated to 0x%lx (%ld); the \ | ||
generated code might be incorrect.@." | ||
(to_hex i) | ||
(to_dec i) | ||
i32 | ||
i32 | ||
|
||
let convert_warning_on_overflow ~to_int32 ~of_int32 ~equal ~to_dec ~to_hex x = | ||
let i32 = to_int32 x in | ||
let x' = of_int32 i32 in | ||
if not (equal x' x) then warn_overflow ~to_dec ~to_hex x i32; | ||
i32 | ||
|
||
let of_int_warning_on_overflow i = | ||
convert_warning_on_overflow | ||
~to_int32:Int32.of_int | ||
~of_int32:Int32.to_int | ||
~equal:Int_replace_polymorphic_compare.( = ) | ||
~to_dec:(Printf.sprintf "%d") | ||
~to_hex:(Printf.sprintf "%x") | ||
i | ||
|
||
let of_int32_warning_on_overflow i = i | ||
|
||
let of_nativeint_warning_on_overflow n = | ||
convert_warning_on_overflow | ||
~to_int32:Nativeint.to_int32 | ||
~of_int32:Nativeint.of_int32 | ||
~equal:Nativeint.equal | ||
~to_dec:(Printf.sprintf "%nd") | ||
~to_hex:(Printf.sprintf "%nx") | ||
n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
type t | ||
|
||
val equal : t -> t -> bool | ||
|
||
val compare : t -> t -> int | ||
|
||
val to_string : t -> string | ||
|
||
val to_int_exn : t -> int | ||
|
||
val to_float : t -> float | ||
|
||
val of_string : string -> t | ||
|
||
val of_float : float -> t | ||
|
||
val of_int_exn : int -> t | ||
|
||
val of_int32_warning_on_overflow : int32 -> t | ||
|
||
val of_nativeint_warning_on_overflow : nativeint -> t | ||
|
||
val of_int_warning_on_overflow : int -> t | ||
|
||
val succ : t -> t | ||
|
||
val add : t -> t -> t | ||
|
||
val sub : t -> t -> t | ||
|
||
val mul : t -> t -> t | ||
|
||
val div : t -> t -> t | ||
|
||
val rem : t -> t -> t | ||
|
||
val logand : t -> t -> t | ||
|
||
val logor : t -> t -> t | ||
|
||
val logxor : t -> t -> t | ||
|
||
val shift_left : t -> int -> t | ||
|
||
val shift_right : t -> int -> t | ||
|
||
val shift_right_logical : t -> int -> t | ||
|
||
val neg : t -> t | ||
|
||
val abs : t -> t | ||
|
||
val ( >= ) : t -> t -> bool | ||
|
||
val ( <= ) : t -> t -> bool | ||
|
||
val ( < ) : t -> t -> bool | ||
|
||
val ( > ) : t -> t -> bool | ||
|
||
val ( = ) : t -> t -> bool | ||
|
||
val ( <> ) : t -> t -> bool | ||
|
||
val is_zero : t -> bool | ||
|
||
val num_bits : int | ||
|
||
val zero : t | ||
|
||
val one : t |