Commit | Line | Data |
---|---|---|
7f918cf1 CE |
1 | (* Copyright (C) 1999-2007 Henry Cejtin, Matthew Fluet, Suresh |
2 | * Jagannathan, and Stephen Weeks. | |
3 | * Copyright (C) 1997-2000 NEC Research Institute. | |
4 | * | |
5 | * MLton is released under a BSD-style license. | |
6 | * See the file MLton-LICENSE for details. | |
7 | *) | |
8 | ||
9 | (* Primitive names are special -- see atoms/prim.fun. *) | |
10 | ||
11 | signature PRIM_INTEGER = | |
12 | sig | |
13 | eqtype int | |
14 | type t = int | |
15 | ||
16 | val sizeInBits: Primitive.Int32.int | |
17 | val sizeInBitsWord: Primitive.Word32.word | |
18 | val precision: Primitive.Int32.int option | |
19 | ||
20 | val +! : int * int -> int | |
21 | val +? : int * int -> int | |
22 | val + : int * int -> int | |
23 | val *! : int * int -> int | |
24 | val *? : int * int -> int | |
25 | val * : int * int -> int | |
26 | val ~! : int -> int | |
27 | val ~? : int -> int | |
28 | val ~ : int -> int | |
29 | val quotUnsafe: int * int -> int | |
30 | val -! : int * int -> int | |
31 | val -? : int * int -> int | |
32 | val - : int * int -> int | |
33 | val remUnsafe: int * int -> int | |
34 | ||
35 | val < : int * int -> bool | |
36 | val <= : int * int -> bool | |
37 | val > : int * int -> bool | |
38 | val >= : int * int -> bool | |
39 | val compare: int * int -> Primitive.Order.order | |
40 | val min: int * int -> int | |
41 | val max: int * int -> int | |
42 | end | |
43 | ||
44 | structure Primitive = struct | |
45 | ||
46 | open Primitive | |
47 | ||
48 | structure Int1 = | |
49 | struct | |
50 | open Int1 | |
51 | type big = Int8.int | |
52 | val fromBigUnsafe = _prim "WordU8_extdToWord1": big -> int; | |
53 | val sizeInBits: Int32.int = 1 | |
54 | val toBig = _prim "WordU1_extdToWord8": int -> big; | |
55 | end | |
56 | structure Int2 = | |
57 | struct | |
58 | open Int2 | |
59 | type big = Int8.int | |
60 | val fromBigUnsafe = _prim "WordU8_extdToWord2": big -> int; | |
61 | val sizeInBits: Int32.int = 2 | |
62 | val toBig = _prim "WordU2_extdToWord8": int -> big; | |
63 | end | |
64 | structure Int3 = | |
65 | struct | |
66 | open Int3 | |
67 | type big = Int8.int | |
68 | val fromBigUnsafe = _prim "WordU8_extdToWord3": big -> int; | |
69 | val sizeInBits: Int32.int = 3 | |
70 | val toBig = _prim "WordU3_extdToWord8": int -> big; | |
71 | end | |
72 | structure Int4 = | |
73 | struct | |
74 | open Int4 | |
75 | type big = Int8.int | |
76 | val fromBigUnsafe = _prim "WordU8_extdToWord4": big -> int; | |
77 | val sizeInBits: Int32.int = 4 | |
78 | val toBig = _prim "WordU4_extdToWord8": int -> big; | |
79 | end | |
80 | structure Int5 = | |
81 | struct | |
82 | open Int5 | |
83 | type big = Int8.int | |
84 | val fromBigUnsafe = _prim "WordU8_extdToWord5": big -> int; | |
85 | val sizeInBits: Int32.int = 5 | |
86 | val toBig = _prim "WordU5_extdToWord8": int -> big; | |
87 | end | |
88 | structure Int6 = | |
89 | struct | |
90 | open Int6 | |
91 | type big = Int8.int | |
92 | val fromBigUnsafe = _prim "WordU8_extdToWord6": big -> int; | |
93 | val sizeInBits: Int32.int = 6 | |
94 | val toBig = _prim "WordU6_extdToWord8": int -> big; | |
95 | end | |
96 | structure Int7 = | |
97 | struct | |
98 | open Int7 | |
99 | type big = Int8.int | |
100 | val fromBigUnsafe = _prim "WordU8_extdToWord7": big -> int; | |
101 | val sizeInBits: Int32.int = 7 | |
102 | val toBig = _prim "WordU7_extdToWord8": int -> big; | |
103 | end | |
104 | structure Int8 = | |
105 | struct | |
106 | open Int8 | |
107 | ||
108 | val sizeInBits: Int32.int = 8 | |
109 | val sizeInBitsWord: Word32.word = | |
110 | IntWordConv.zextdFromInt32ToWord32 sizeInBits | |
111 | val precision = SOME sizeInBits | |
112 | ||
113 | val +! = Exn.wrapOverflow (_prim "WordS8_addCheck": int * int -> int;) | |
114 | val +? = _prim "Word8_add": int * int -> int; | |
115 | val + = | |
116 | if Controls.detectOverflow | |
117 | then +! | |
118 | else +? | |
119 | val *! = Exn.wrapOverflow (_prim "WordS8_mulCheck": int * int -> int;) | |
120 | val *? = _prim "WordS8_mul": int * int -> int; | |
121 | val * = | |
122 | if Controls.detectOverflow | |
123 | then *! | |
124 | else *? | |
125 | val ~! = Exn.wrapOverflow (_prim "Word8_negCheck": int -> int;) | |
126 | val ~? = _prim "Word8_neg": int -> int; | |
127 | val ~ = | |
128 | if Controls.detectOverflow | |
129 | then ~! | |
130 | else ~? | |
131 | val quotUnsafe = _prim "WordS8_quot": int * int -> int; | |
132 | val -! = Exn.wrapOverflow (_prim "WordS8_subCheck": int * int -> int;) | |
133 | val -? = _prim "Word8_sub": int * int -> int; | |
134 | val - = | |
135 | if Controls.detectOverflow | |
136 | then -! | |
137 | else -? | |
138 | val remUnsafe = _prim "WordS8_rem": int * int -> int; | |
139 | ||
140 | val < = _prim "WordS8_lt": int * int -> bool; | |
141 | end | |
142 | structure Int8 : PRIM_INTEGER = | |
143 | struct | |
144 | open Int8 | |
145 | local | |
146 | structure S = IntegralComparisons(Int8) | |
147 | in | |
148 | open S | |
149 | end | |
150 | end | |
151 | structure Int9 = | |
152 | struct | |
153 | open Int9 | |
154 | type big = Int16.int | |
155 | val fromBigUnsafe = _prim "WordU16_extdToWord9": big -> int; | |
156 | val sizeInBits: Int32.int = 9 | |
157 | val toBig = _prim "WordU9_extdToWord16": int -> big; | |
158 | end | |
159 | structure Int10 = | |
160 | struct | |
161 | open Int10 | |
162 | type big = Int16.int | |
163 | val fromBigUnsafe = _prim "WordU16_extdToWord10": big -> int; | |
164 | val sizeInBits: Int32.int = 10 | |
165 | val toBig = _prim "WordU10_extdToWord16": int -> big; | |
166 | end | |
167 | structure Int11 = | |
168 | struct | |
169 | open Int11 | |
170 | type big = Int16.int | |
171 | val fromBigUnsafe = _prim "WordU16_extdToWord11": big -> int; | |
172 | val sizeInBits: Int32.int = 11 | |
173 | val toBig = _prim "WordU11_extdToWord16": int -> big; | |
174 | end | |
175 | structure Int12 = | |
176 | struct | |
177 | open Int12 | |
178 | type big = Int16.int | |
179 | val fromBigUnsafe = _prim "WordU16_extdToWord12": big -> int; | |
180 | val sizeInBits: Int32.int = 12 | |
181 | val toBig = _prim "WordU12_extdToWord16": int -> big; | |
182 | end | |
183 | structure Int13 = | |
184 | struct | |
185 | open Int13 | |
186 | type big = Int16.int | |
187 | val fromBigUnsafe = _prim "WordU16_extdToWord13": big -> int; | |
188 | val sizeInBits: Int32.int = 13 | |
189 | val toBig = _prim "WordU13_extdToWord16": int -> big; | |
190 | end | |
191 | structure Int14 = | |
192 | struct | |
193 | open Int14 | |
194 | type big = Int16.int | |
195 | val fromBigUnsafe = _prim "WordU16_extdToWord14": big -> int; | |
196 | val sizeInBits: Int32.int = 14 | |
197 | val toBig = _prim "WordU14_extdToWord16": int -> big; | |
198 | end | |
199 | structure Int15 = | |
200 | struct | |
201 | open Int15 | |
202 | type big = Int16.int | |
203 | val fromBigUnsafe = _prim "WordU16_extdToWord15": big -> int; | |
204 | val sizeInBits: Int32.int = 15 | |
205 | val toBig = _prim "WordU15_extdToWord16": int -> big; | |
206 | end | |
207 | structure Int16 = | |
208 | struct | |
209 | open Int16 | |
210 | ||
211 | val sizeInBits: Int32.int = 16 | |
212 | val sizeInBitsWord: Word32.word = | |
213 | IntWordConv.zextdFromInt32ToWord32 sizeInBits | |
214 | val precision = SOME sizeInBits | |
215 | ||
216 | val +! = Exn.wrapOverflow (_prim "WordS16_addCheck": int * int -> int;) | |
217 | val +? = _prim "Word16_add": int * int -> int; | |
218 | val + = | |
219 | if Controls.detectOverflow | |
220 | then +! | |
221 | else +? | |
222 | val *! = Exn.wrapOverflow (_prim "WordS16_mulCheck": int * int -> int;) | |
223 | val *? = _prim "WordS16_mul": int * int -> int; | |
224 | val * = | |
225 | if Controls.detectOverflow | |
226 | then *! | |
227 | else *? | |
228 | val ~! = Exn.wrapOverflow (_prim "Word16_negCheck": int -> int;) | |
229 | val ~? = _prim "Word16_neg": int -> int; | |
230 | val ~ = | |
231 | if Controls.detectOverflow | |
232 | then ~! | |
233 | else ~? | |
234 | val quotUnsafe = _prim "WordS16_quot": int * int -> int; | |
235 | val -! = Exn.wrapOverflow (_prim "WordS16_subCheck": int * int -> int;) | |
236 | val -? = _prim "Word16_sub": int * int -> int; | |
237 | val - = | |
238 | if Controls.detectOverflow | |
239 | then -! | |
240 | else -? | |
241 | val remUnsafe = _prim "WordS16_rem": int * int -> int; | |
242 | ||
243 | val < = _prim "WordS16_lt": int * int -> bool; | |
244 | end | |
245 | structure Int16 : PRIM_INTEGER = | |
246 | struct | |
247 | open Int16 | |
248 | local | |
249 | structure S = IntegralComparisons(Int16) | |
250 | in | |
251 | open S | |
252 | end | |
253 | end | |
254 | structure Int17 = | |
255 | struct | |
256 | open Int17 | |
257 | type big = Int32.int | |
258 | val fromBigUnsafe = _prim "WordU32_extdToWord17": big -> int; | |
259 | val sizeInBits: Int32.int = 17 | |
260 | val toBig = _prim "WordU17_extdToWord32": int -> big; | |
261 | end | |
262 | structure Int18 = | |
263 | struct | |
264 | open Int18 | |
265 | type big = Int32.int | |
266 | val fromBigUnsafe = _prim "WordU32_extdToWord18": big -> int; | |
267 | val sizeInBits: Int32.int = 18 | |
268 | val toBig = _prim "WordU18_extdToWord32": int -> big; | |
269 | end | |
270 | structure Int19 = | |
271 | struct | |
272 | open Int19 | |
273 | type big = Int32.int | |
274 | val fromBigUnsafe = _prim "WordU32_extdToWord19": big -> int; | |
275 | val sizeInBits: Int32.int = 19 | |
276 | val toBig = _prim "WordU19_extdToWord32": int -> big; | |
277 | end | |
278 | structure Int20 = | |
279 | struct | |
280 | open Int20 | |
281 | type big = Int32.int | |
282 | val fromBigUnsafe = _prim "WordU32_extdToWord20": big -> int; | |
283 | val sizeInBits: Int32.int = 20 | |
284 | val toBig = _prim "WordU20_extdToWord32": int -> big; | |
285 | end | |
286 | structure Int21 = | |
287 | struct | |
288 | open Int21 | |
289 | type big = Int32.int | |
290 | val fromBigUnsafe = _prim "WordU32_extdToWord21": big -> int; | |
291 | val sizeInBits: Int32.int = 21 | |
292 | val toBig = _prim "WordU21_extdToWord32": int -> big; | |
293 | end | |
294 | structure Int22 = | |
295 | struct | |
296 | open Int22 | |
297 | type big = Int32.int | |
298 | val fromBigUnsafe = _prim "WordU32_extdToWord22": big -> int; | |
299 | val sizeInBits: Int32.int = 22 | |
300 | val toBig = _prim "WordU22_extdToWord32": int -> big; | |
301 | end | |
302 | structure Int23 = | |
303 | struct | |
304 | open Int23 | |
305 | type big = Int32.int | |
306 | val fromBigUnsafe = _prim "WordU32_extdToWord23": big -> int; | |
307 | val sizeInBits: Int32.int = 23 | |
308 | val toBig = _prim "WordU23_extdToWord32": int -> big; | |
309 | end | |
310 | structure Int24 = | |
311 | struct | |
312 | open Int24 | |
313 | type big = Int32.int | |
314 | val fromBigUnsafe = _prim "WordU32_extdToWord24": big -> int; | |
315 | val sizeInBits: Int32.int = 24 | |
316 | val toBig = _prim "WordU24_extdToWord32": int -> big; | |
317 | end | |
318 | structure Int25 = | |
319 | struct | |
320 | open Int25 | |
321 | type big = Int32.int | |
322 | val fromBigUnsafe = _prim "WordU32_extdToWord25": big -> int; | |
323 | val sizeInBits: Int32.int = 25 | |
324 | val toBig = _prim "WordU25_extdToWord32": int -> big; | |
325 | end | |
326 | structure Int26 = | |
327 | struct | |
328 | open Int26 | |
329 | type big = Int32.int | |
330 | val fromBigUnsafe = _prim "WordU32_extdToWord26": big -> int; | |
331 | val sizeInBits: Int32.int = 26 | |
332 | val toBig = _prim "WordU26_extdToWord32": int -> big; | |
333 | end | |
334 | structure Int27 = | |
335 | struct | |
336 | open Int27 | |
337 | type big = Int32.int | |
338 | val fromBigUnsafe = _prim "WordU32_extdToWord27": big -> int; | |
339 | val sizeInBits: Int32.int = 27 | |
340 | val toBig = _prim "WordU27_extdToWord32": int -> big; | |
341 | end | |
342 | structure Int28 = | |
343 | struct | |
344 | open Int28 | |
345 | type big = Int32.int | |
346 | val fromBigUnsafe = _prim "WordU32_extdToWord28": big -> int; | |
347 | val sizeInBits: Int32.int = 28 | |
348 | val toBig = _prim "WordU28_extdToWord32": int -> big; | |
349 | end | |
350 | structure Int29 = | |
351 | struct | |
352 | open Int29 | |
353 | type big = Int32.int | |
354 | val fromBigUnsafe = _prim "WordU32_extdToWord29": big -> int; | |
355 | val sizeInBits: Int32.int = 29 | |
356 | val toBig = _prim "WordU29_extdToWord32": int -> big; | |
357 | end | |
358 | structure Int30 = | |
359 | struct | |
360 | open Int30 | |
361 | type big = Int32.int | |
362 | val fromBigUnsafe = _prim "WordU32_extdToWord30": big -> int; | |
363 | val sizeInBits: Int32.int = 30 | |
364 | val toBig = _prim "WordU30_extdToWord32": int -> big; | |
365 | end | |
366 | structure Int31 = | |
367 | struct | |
368 | open Int31 | |
369 | type big = Int32.int | |
370 | val fromBigUnsafe = _prim "WordU32_extdToWord31": big -> int; | |
371 | val sizeInBits: Int32.int = 31 | |
372 | val toBig = _prim "WordU31_extdToWord32": int -> big; | |
373 | end | |
374 | structure Int32 = | |
375 | struct | |
376 | open Int32 | |
377 | ||
378 | val sizeInBits: Int32.int = 32 | |
379 | val sizeInBitsWord: Word32.word = | |
380 | IntWordConv.zextdFromInt32ToWord32 sizeInBits | |
381 | val precision = SOME sizeInBits | |
382 | ||
383 | val +! = Exn.wrapOverflow (_prim "WordS32_addCheck": int * int -> int;) | |
384 | val +? = _prim "Word32_add": int * int -> int; | |
385 | val + = | |
386 | if Controls.detectOverflow | |
387 | then +! | |
388 | else +? | |
389 | val *! = Exn.wrapOverflow (_prim "WordS32_mulCheck": int * int -> int;) | |
390 | val *? = _prim "WordS32_mul": int * int -> int; | |
391 | val * = | |
392 | if Controls.detectOverflow | |
393 | then *! | |
394 | else *? | |
395 | val ~! = Exn.wrapOverflow (_prim "Word32_negCheck": int -> int;) | |
396 | val ~? = _prim "Word32_neg": int -> int; | |
397 | val ~ = | |
398 | if Controls.detectOverflow | |
399 | then ~! | |
400 | else ~? | |
401 | val quotUnsafe = _prim "WordS32_quot": int * int -> int; | |
402 | val -! = Exn.wrapOverflow (_prim "WordS32_subCheck": int * int -> int;) | |
403 | val -? = _prim "Word32_sub": int * int -> int; | |
404 | val - = | |
405 | if Controls.detectOverflow | |
406 | then -! | |
407 | else -? | |
408 | val remUnsafe = _prim "WordS32_rem": int * int -> int; | |
409 | ||
410 | val < = _prim "WordS32_lt": int * int -> bool; | |
411 | end | |
412 | structure Int32 : PRIM_INTEGER = | |
413 | struct | |
414 | open Int32 | |
415 | local | |
416 | structure S = IntegralComparisons(Int32) | |
417 | in | |
418 | open S | |
419 | end | |
420 | end | |
421 | structure Int64 = | |
422 | struct | |
423 | open Int64 | |
424 | ||
425 | val sizeInBits: Int32.int = 64 | |
426 | val sizeInBitsWord: Word32.word = | |
427 | IntWordConv.zextdFromInt32ToWord32 sizeInBits | |
428 | val precision = SOME sizeInBits | |
429 | ||
430 | val +! = Exn.wrapOverflow (_prim "WordS64_addCheck": int * int -> int;) | |
431 | val +? = _prim "Word64_add": int * int -> int; | |
432 | val + = | |
433 | if Controls.detectOverflow | |
434 | then +! | |
435 | else +? | |
436 | val *! = Exn.wrapOverflow (_prim "WordS64_mulCheck": int * int -> int;) | |
437 | val *? = _prim "WordS64_mul": int * int -> int; | |
438 | val * = | |
439 | if Controls.detectOverflow | |
440 | then *! | |
441 | else *? | |
442 | val ~! = Exn.wrapOverflow (_prim "Word64_negCheck": int -> int;) | |
443 | val ~? = _prim "Word64_neg": int -> int; | |
444 | val ~ = | |
445 | if Controls.detectOverflow | |
446 | then ~! | |
447 | else ~? | |
448 | val quotUnsafe = _prim "WordS64_quot": int * int -> int; | |
449 | val -! = Exn.wrapOverflow (_prim "WordS64_subCheck": int * int -> int;) | |
450 | val -? = _prim "Word64_sub": int * int -> int; | |
451 | val - = | |
452 | if Controls.detectOverflow | |
453 | then -! | |
454 | else -? | |
455 | val remUnsafe = _prim "WordS64_rem": int * int -> int; | |
456 | ||
457 | val < = _prim "WordS64_lt": int * int -> bool; | |
458 | end | |
459 | structure Int64 : PRIM_INTEGER = | |
460 | struct | |
461 | open Int64 | |
462 | local | |
463 | structure S = IntegralComparisons(Int64) | |
464 | in | |
465 | open S | |
466 | end | |
467 | end | |
468 | ||
469 | end |