@@ -131,6 +131,10 @@ type integer_comparison =
131
131
type float_comparison =
132
132
CFeq | CFneq | CFlt | CFnlt | CFgt | CFngt | CFle | CFnle | CFge | CFnge
133
133
134
+ type taggable_integer =
135
+ | Int8
136
+ | Int16
137
+ | Immediate
134
138
135
139
type unboxed_float = Primitive .unboxed_float =
136
140
| Unboxed_float64
@@ -238,113 +242,192 @@ and scannable_product_element_kind =
238
242
239
243
240
244
module Scalar = struct
245
+ type any_locality_mode = Any_locality_mode
246
+
247
+ type tagged_immediate = Tagged_immediate
248
+
241
249
module Maybe_naked = struct
242
- type 'a t =
243
- { t : 'a
244
- ; naked : bool
245
- }
250
+ type ('a, 'b) t =
251
+ | Naked of 'a
252
+ | Value of 'b
246
253
247
- let map {t; naked} ~f =
248
- {t = f t; naked}
249
- end
254
+ module Make1 (M : sig
255
+ type 'a t
250
256
251
- type any_locality_mode = Any_locality_mode
257
+ val map : 'a t -> f :('a -> 'b ) -> 'b t
258
+ end ) = struct
259
+ type nonrec 'a t = (any_locality_mode M .t , 'a M .t ) t
260
+
261
+ let map (t : _ t ) ~f =
262
+ match t with
263
+ | Naked (_ : any_locality_mode M.t ) as t -> t
264
+ | Value t -> Value (M. map t ~f )
265
+ end
266
+ end
252
267
253
- type tagged_immediate = Tagged_immediate
254
268
255
269
module Integral = struct
256
- type 'mode t =
257
- | Tagged_int8
258
- | Tagged_int16
259
- | Tagged_immediate
260
- | Boxed_int32 of 'mode
261
- | Boxed_nativeint of 'mode
262
- | Boxed_int64 of 'mode
263
- | Naked_int8
264
- | Naked_int16
265
- | Naked_int32
266
- | Naked_nativeint
267
- | Naked_int64
270
+ module Taggable = struct
271
+ type t =
272
+ | Int8
273
+ | Int16
274
+ | Immediate
275
+
276
+ let to_unboxed_integer = function
277
+ | Int8 -> Unboxed_int8
278
+ | Int16 -> Unboxed_int16
279
+ | Immediate -> Unboxed_immediate
280
+
281
+ module Maybe_naked = struct
282
+ type nonrec t = (t , t ) Maybe_naked .t
283
+
284
+ let layout : t -> layout = function
285
+ | Naked t -> Punboxed_int (to_unboxed_integer t)
286
+ | Value (Int8 | Int16 | Immediate ) ->
287
+ Pvalue { raw_kind = Pintval ; nullable = Non_nullable }
288
+
289
+ let locality_mode : t -> locality_mode option = function
290
+ | Naked _ -> None
291
+ | Value _ -> None
292
+ end
293
+ end
268
294
269
- let locality_mode = function
270
- | Boxed_int32 locality_mode
271
- | Boxed_nativeint locality_mode
272
- | Boxed_int64 locality_mode ->
273
- Some locality_mode
274
- | Tagged_int8 | Tagged_int16 | Tagged_immediate | Naked_int8 | Naked_int16
275
- | Naked_int32 | Naked_nativeint | Naked_int64 ->
276
- None
277
-
278
- let layout = function
279
- | Tagged_int8
280
- | Tagged_int16
281
- | Tagged_immediate -> Pvalue { raw_kind = Pintval ; nullable = Non_nullable }
282
- | Boxed_int32 _ -> Pvalue { raw_kind = Pboxedintval Boxed_int32 ; nullable = Non_nullable }
283
- | Boxed_nativeint _ -> Pvalue { raw_kind = Pboxedintval Boxed_nativeint ; nullable = Non_nullable }
284
- | Boxed_int64 _ -> Pvalue { raw_kind = Pboxedintval Boxed_int64 ; nullable = Non_nullable }
285
- | Naked_int8 -> Punboxed_int Unboxed_int8
286
- | Naked_int16 -> Punboxed_int Unboxed_int16
287
- | Naked_int32 -> Punboxed_int Unboxed_int32
288
- | Naked_nativeint -> Punboxed_int Unboxed_nativeint
289
- | Naked_int64 -> Punboxed_int Unboxed_int64
295
+ module Boxable = struct
296
+ module T = struct
297
+ type 'mode t =
298
+ | Int32 of 'mode
299
+ | Nativeint of 'mode
300
+ | Int64 of 'mode
301
+
302
+ let map t ~f =
303
+ match t with
304
+ | Int32 mode -> Int32 (f mode)
305
+ | Nativeint mode -> Nativeint (f mode)
306
+ | Int64 mode -> Int64 (f mode)
307
+
308
+ let locality_mode (Int32 mode | Nativeint mode | Int64 mode ) : locality_mode = mode
309
+ end
310
+
311
+ include T
312
+
313
+ let to_boxed_integer = function
314
+ | Int32 Any_locality_mode -> Boxed_int32
315
+ | Nativeint Any_locality_mode -> Boxed_nativeint
316
+ | Int64 Any_locality_mode -> Boxed_int64
317
+
318
+ let to_unboxed_integer = function
319
+ | Int32 Any_locality_mode -> Unboxed_int32
320
+ | Nativeint Any_locality_mode -> Unboxed_nativeint
321
+ | Int64 Any_locality_mode -> Unboxed_int64
322
+
323
+ module Maybe_naked = struct
324
+ include Maybe_naked. Make1 (T )
325
+
326
+ let layout : any_locality_mode t -> layout = function
327
+ | Value t -> Pvalue { raw_kind = Pboxedintval (to_boxed_integer t); nullable = Non_nullable }
328
+ | Naked t -> Punboxed_int (to_unboxed_integer t)
329
+
330
+ let locality_mode : locality_mode t -> locality_mode option = function
331
+ | Naked (_ : any_locality_mode T.t ) -> None
332
+ | Value t -> Some (locality_mode t)
333
+ end
334
+
335
+ end
336
+
337
+ module T = struct
338
+ type 'mode t =
339
+ | Taggable of Taggable .t
340
+ | Boxable of 'mode Boxable .t
341
+
342
+ let map t ~f =
343
+ match t with
344
+ | Taggable (Int8 | Int16 | Immediate ) as t -> t
345
+ | Boxable b -> Boxable (Boxable. map b ~f )
346
+
347
+ let locality_mode = function
348
+ | Taggable (Int8 | Int16 | Immediate ) -> None
349
+ | Boxable b -> Some (Boxable. locality_mode b)
350
+ end
351
+ include T
352
+
353
+ let to_unboxed_integer = function
354
+ | Taggable t -> Taggable. to_unboxed_integer t
355
+ | Boxable b -> Boxable. to_unboxed_integer b
356
+
357
+ module Maybe_naked = struct
358
+ include Maybe_naked. Make1 (T )
359
+
360
+ let layout : any_locality_mode t -> layout = function
361
+ | Value (Taggable t ) -> Taggable.Maybe_naked. layout (Value t)
362
+ | Naked (Taggable t ) -> Taggable.Maybe_naked. layout (Naked t)
363
+ | Value (Boxable t ) -> Boxable.Maybe_naked. layout (Value t)
364
+ | Naked (Boxable t ) -> Boxable.Maybe_naked. layout (Naked t)
365
+ ;;
366
+
367
+ let locality_mode : locality_mode t -> locality_mode option = function
368
+ | Naked (_ : any_locality_mode T.t ) -> None
369
+ | Value t -> locality_mode t
370
+ end
371
+ end
372
+
373
+ module Floating = struct
374
+ module T = struct
375
+ type 'mode t =
376
+ | Float32 of 'mode
377
+ | Float64 of 'mode
378
+ end
379
+ include T
290
380
291
381
let map t ~f =
292
382
match t with
293
- | Boxed_int32 mode -> Boxed_int32 (f mode)
294
- | Boxed_nativeint mode -> Boxed_nativeint (f mode)
295
- | Boxed_int64 mode -> Boxed_int64 (f mode)
296
- | Tagged_int8 | Tagged_int16 | Tagged_immediate | Naked_int8 | Naked_int16
297
- | Naked_int32 | Naked_nativeint | Naked_int64 as t -> t
383
+ | Float32 mode -> Float32 (f mode)
384
+ | Float64 mode -> Float64 (f mode)
385
+
386
+ let locality_mode (Float32 mode | Float64 mode ) : locality_mode = mode
387
+
388
+ let to_boxed_float = function
389
+ | Float32 Any_locality_mode -> Boxed_float32
390
+ | Float64 Any_locality_mode -> Boxed_float64
391
+
392
+ let to_unboxed_float = function
393
+ | Float32 Any_locality_mode -> Unboxed_float32
394
+ | Float64 Any_locality_mode -> Unboxed_float64
395
+
396
+ let layout : any_locality_mode Maybe_naked.M(T).t -> layout = function
397
+ | Value t -> Pvalue { raw_kind = Pboxedfloatval (to_boxed_float t); nullable = Non_nullable }
398
+ | Naked t -> Punboxed_float (to_unboxed_float t)
298
399
end
299
400
300
- module Floating = struct
401
+ module T1 = struct
301
402
type 'mode t =
302
- | Unboxed_float32
303
- | Unboxed_float64
304
- | Boxed_float32 of 'mode
305
- | Boxed_float64 of 'mode
403
+ | Floating of 'mode Floating .t
404
+ | Integral of 'mode Integral .t
306
405
307
406
let map t ~f =
308
407
match t with
309
- | Boxed_float32 mode -> Boxed_float32 (f mode)
310
- | Boxed_float64 mode -> Boxed_float64 (f mode)
311
- | Unboxed_float32 | Unboxed_float64 as t -> t
408
+ | Floating g -> Floating (Floating. map g ~f )
409
+ | Integral i -> Integral (Integral. map i ~f )
312
410
313
411
let locality_mode = function
314
- | Unboxed_float32 | Unboxed_float64 -> None
315
- | Boxed_float32 mode | Boxed_float64 mode -> Some mode
316
-
317
- let layout = function
318
- | Unboxed_float32 -> Punboxed_float Unboxed_float32
319
- | Unboxed_float64 -> Punboxed_float Unboxed_float64
320
- | Boxed_float32 _ -> Pvalue { raw_kind = Pboxedfloatval Boxed_float32 ; nullable = Non_nullable }
321
- | Boxed_float64 _ -> Pvalue { raw_kind = Pboxedfloatval Boxed_float64 ; nullable = Non_nullable }
412
+ | Floating f -> Some ( Floating. locality_mode f)
413
+ | Integral i -> Integral. locality_mode i
414
+
415
+ let layout : (any_locality_mode t, any_locality_mode t) Maybe_naked.t -> layout = function
416
+ | Value (Floating f ) -> Floating. layout ( Value f)
417
+ | Naked (Floating f ) -> Floating. layout ( Naked f)
418
+ | Value (Integral i ) -> Integral. layout ( Value i)
419
+ | Naked (Integral i ) -> Integral. layout ( Naked i)
322
420
end
323
421
324
- type 'mode t =
325
- | Floating of 'mode Floating .t
326
- | Integral of 'mode Integral .t
327
-
328
- let locality_mode = function
329
- | Floating f -> Floating. locality_mode f
330
- | Integral i -> Integral. locality_mode i
422
+ type 'mode t = 'mode Maybe_naked .M (T1 ).t
331
423
332
- let layout = function
333
- | Floating f -> Floating. layout f
334
- | Integral i -> Integral. layout i
424
+ let locality_mode : locality_mode t -> locality_mode option = function
425
+ | Naked ( _ : any_locality_mode T1.t ) -> None
426
+ | Value t -> Some (locality_mode t)
335
427
336
- type 'mode scalar = 'mode t
337
428
338
429
module Bytecode = struct
339
- type tagged_integer =
340
- | Tagged_int8
341
- | Tagged_int16
342
- | Tagged_immediate
343
-
344
- type t =
345
- | Tagged_immediate of tagged_integer
346
- | Boxed_integer of boxed_integer
347
- | Boxed_float of boxed_float
430
+ type nonrec t = Boxed of any_locality_mode t
348
431
349
432
let of_scalar : any_locality_mode scalar -> t Maybe_naked.t = function
350
433
| Integral Naked_int8 -> { t = Tagged_immediate Tagged_int8 ; naked = true }
@@ -371,7 +454,7 @@ module Scalar = struct
371
454
| Floating (Boxed_float64 Any_locality_mode) ->
372
455
{ t = Boxed_float Boxed_float64 ; naked = false }
373
456
374
- let to_scalar : t Maybe_naked.t -> any_locality_mode scalar =
457
+ let to_scalar : t Maybe_naked.t -> any_locality_mode scalar = function
375
458
| { t = Tagged_immediate Tagged_int8 ; naked = true } -> Integral Naked_int8
376
459
| { t = Tagged_immediate Tagged_int16 ; naked = true } -> Integral Naked_int16
377
460
| { t = Tagged_immediate Tagged_immediate ; naked = true } -> Integral Naked_immediate
@@ -2794,7 +2877,7 @@ module Bytecode = struct
2794
2877
[int_size; Lconst (const_int bits)], loc)
2795
2878
2796
2879
| Tagged_immediate Tagged_immediate -> Misc. fatal_error " There is no Naked_immediate type yet"
2797
- |
2880
+
2798
2881
2799
2882
(* let unwrap arg ~src ~dst =
2800
2883
* match t with
0 commit comments