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