@@ -48,11 +48,34 @@ module Int8 = struct
48
48
i
49
49
50
50
let to_int i = i
51
+
52
+ let print ppf t = Format. pp_print_int ppf t
53
+ end
54
+
55
+ module Uint8 = struct
56
+ type t = int
57
+
58
+ let print ppf t = Format. pp_print_int ppf t
59
+
60
+ let zero = 0
61
+
62
+ let one = 1
63
+
64
+ let of_nonnegative_int_exn i =
65
+ if i < 0 || i > (1 lsl 8 ) - 1
66
+ then Misc. fatal_errorf " Uint8.of_nonnegative_int_exn: %d is out of range" i
67
+ else i
68
+
69
+ let to_int i = i
51
70
end
52
71
53
72
module Int16 = struct
54
73
type t = int
55
74
75
+ let zero = 0
76
+
77
+ let one = 1
78
+
56
79
let of_int_exn i =
57
80
if i < - (1 lsl 15 ) || i > ((1 lsl 15 ) - 1 ) then
58
81
Misc. fatal_errorf " Int16.of_int_exn: %d is out of range" i
@@ -71,8 +94,115 @@ module Int16 = struct
71
94
Int64. to_int i
72
95
73
96
let to_int t = t
97
+
98
+ let print ppf t = Format. pp_print_int ppf t
99
+ end
100
+
101
+ module Uint16 = struct
102
+ type t = int
103
+
104
+ let print ppf t = Format. pp_print_int ppf t
105
+
106
+ let of_nonnegative_int_exn i =
107
+ if i < 0 || i > (1 lsl 16 ) - 1
108
+ then Misc. fatal_errorf " Uint16.of_nonnegative_int_exn: %d is out of range" i
109
+ else i
110
+
111
+ let upper_int64 = Int64. sub (Int64. shift_left Int64. one 16 ) Int64. one
112
+
113
+ let of_nonnegative_int64_exn i =
114
+ if Int64. compare i 0L < 0 || Int64. compare i upper_int64 > 0
115
+ then
116
+ Misc. fatal_errorf " Uint16.of_nonnegative_int64_exn: %Ld is out of range" i
117
+ else Int64. to_int i
118
+
119
+ let to_int t = t
120
+ end
121
+
122
+ module Uint32 = struct
123
+ type t = Int64 .t
124
+
125
+ let zero = 0L
126
+
127
+ let print ppf t = Format. fprintf ppf " 0x%Lx" t
128
+
129
+ let upper_int64 = Int64. sub (Int64. shift_left Int64. one 32 ) Int64. one
130
+
131
+ let of_nonnegative_int_exn i =
132
+ if i < 0
133
+ then Misc. fatal_errorf " Uint32.of_nonnegative_int_exn: %d is out of range" i
134
+ else
135
+ let i64 = Int64. of_int i in
136
+ if Int64. compare i64 upper_int64 > 0
137
+ then
138
+ Misc. fatal_errorf " Uint32.of_nonnegative_int_exn: %d is out of range" i
139
+ else i64
140
+
141
+ let of_nonnegative_int64_exn i =
142
+ if Int64. compare i 0L < 0 || Int64. compare i upper_int64 > 0
143
+ then
144
+ Misc. fatal_errorf " Uint32.of_nonnegative_int64_exn: %Ld is out of range" i
145
+ else i
146
+
147
+ let of_nonnegative_int32_exn i =
148
+ if Int32. compare i 0l < 0
149
+ then
150
+ Misc. fatal_errorf " Uint32.of_nonnegative_int32_exn: %ld is out of range" i
151
+ else Int64. of_int32 i
152
+
153
+ let to_int64 t = t
154
+ end
155
+
156
+ module Uint64 = struct
157
+ type t = Int64 .t
158
+
159
+ let zero = 0L
160
+
161
+ let succ t = Int64. add 1L t
162
+
163
+ let of_nonnegative_int_exn i =
164
+ if i < 0
165
+ then Misc. fatal_errorf " Uint64.of_nonnegative_int_exn: %d is out of range" i
166
+ else Int64. of_int i
167
+
168
+ let of_uint8 i = Int64. of_int i
169
+
170
+ let of_uint16 i = Int64. of_int i
171
+
172
+ let of_uint32 i = i
173
+
174
+ let of_nonnegative_int32_exn i =
175
+ if Int32. compare i 0l < 0
176
+ then
177
+ Misc. fatal_errorf " Uint64.of_nonnegative_int32_exn: %ld is out of range" i
178
+ else Int64. of_int32 i
179
+
180
+ let of_nonnegative_int64_exn i =
181
+ if Int64. compare i 0L < 0
182
+ then
183
+ Misc. fatal_errorf " Uint64.of_nonnegative_int64_exn: %Ld is out of range" i
184
+ else i
185
+
186
+ let to_int64 t = t
187
+
188
+ include Identifiable. Make (struct
189
+ type nonrec t = t
190
+
191
+ let compare t1 t2 =
192
+ (* Only a consistent order is needed here *)
193
+ Int64. compare t1 t2
194
+
195
+ let equal t1 t2 = compare t1 t2 = 0
196
+
197
+ let hash t = Hashtbl. hash t
198
+
199
+ let print ppf t = Format. fprintf ppf " 0x%Lx" t
200
+
201
+ let output _ _ = Misc. fatal_error " Not yet implemented"
202
+ end )
74
203
end
75
204
205
+
76
206
module Float = struct
77
207
type t = float
78
208
0 commit comments