-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathtranslprim.ml
2079 lines (1990 loc) · 91.9 KB
/
translprim.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(**************************************************************************)
(* *)
(* OCaml *)
(* *)
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
(* *)
(* Copyright 1996 Institut National de Recherche en Informatique et *)
(* en Automatique. *)
(* *)
(* All rights reserved. This file is distributed under the terms of *)
(* the GNU Lesser General Public License version 2.1, with the *)
(* special exception on linking described in the file LICENSE. *)
(* *)
(**************************************************************************)
(* Translation of primitives *)
open Primitive
open Types
open Typedtree
open Typeopt
open Lambda
open Debuginfo.Scoped_location
open Translmode
module String = Misc.Stdlib.String
type invalid_stack_primitive =
| Not_primitive
| Not_allocating
| Allocating_on_heap
type error =
| Unknown_builtin_primitive of string
| Wrong_arity_builtin_primitive of string
| Wrong_layout_for_peek_or_poke of string
| Invalid_floatarray_glb
| Product_iarrays_unsupported
| Invalid_array_kind_for_uninitialized_makearray_dynamic
| Invalid_stack_primitive of invalid_stack_primitive
exception Error of Location.t * error
(* CR layouts v7.1: This is temporary - we should support iarrays of unboxed
products. *)
let unboxed_product_iarray_check loc kind mut =
match kind, mut with
| (Pgcscannableproductarray _ | Pgcignorableproductarray _),
(Immutable | Immutable_unique) ->
raise (Error (loc, Product_iarrays_unsupported))
| _, Mutable
| (Pgenarray | Paddrarray | Pintarray | Pfloatarray | Punboxedfloatarray _
| Punboxedintarray _ | Punboxedvectorarray _), _ ->
()
let unboxed_product_uninitialized_array_check loc array_kind =
(* See comments in lambda_to_lambda_transforms.ml in Flambda 2 for more
details on this restriction. *)
match array_kind with
| Pgcignorableproductarray igns
when not (List.exists
Lambda.ignorable_product_element_kind_involves_int igns) -> ()
| Punboxedfloatarray _ | Punboxedintarray _ | Punboxedvectorarray _ ->
()
| Pgenarray | Paddrarray | Pintarray | Pfloatarray
| Pgcscannableproductarray _ | Pgcignorableproductarray _ ->
raise (Error (loc, Invalid_array_kind_for_uninitialized_makearray_dynamic))
(* Insertion of debugging events *)
let event_before loc exp lam = match lam with
| Lstaticraise (_,_) -> lam
| _ ->
if !Clflags.debug && not !Clflags.native_code
then Levent(lam, {lev_loc = loc;
lev_kind = Lev_before;
lev_repr = None;
lev_env = exp.exp_env})
else lam
let event_after loc exp lam =
if !Clflags.debug && not !Clflags.native_code
then Levent(lam, {lev_loc = loc;
lev_kind = Lev_after exp.exp_type;
lev_repr = None;
lev_env = exp.exp_env})
else lam
type comparison =
| Equal
| Not_equal
| Less_equal
| Less_than
| Greater_equal
| Greater_than
| Compare
type comparison_kind =
| Compare_generic
| Compare_ints
| Compare_floats
| Compare_float32s
| Compare_strings
| Compare_bytes
| Compare_nativeints
| Compare_int32s
| Compare_int64s
type loc_kind =
| Loc_FILE
| Loc_LINE
| Loc_MODULE
| Loc_LOC
| Loc_POS
| Loc_FUNCTION
type prim =
| Primitive of Lambda.primitive * int
| External of Lambda.external_call_description
| Sys_argv
| Comparison of comparison * comparison_kind
| Raise of Lambda.raise_kind
| Raise_with_backtrace
| Lazy_force of Lambda.region_close
| Loc of loc_kind
| Send of Lambda.region_close * Lambda.layout
| Send_self of Lambda.region_close * Lambda.layout
| Send_cache of Lambda.region_close * Lambda.layout
| Frame_pointers
| Identity
| Apply of Lambda.region_close * Lambda.layout
| Revapply of Lambda.region_close * Lambda.layout
| Peek of Lambda.peek_or_poke option
| Poke of Lambda.peek_or_poke option
(* For [Peek] and [Poke] the [option] is [None] until the primitive
specialization code (below) has been run. *)
| Unsupported of Lambda.primitive
let units_with_used_primitives = Hashtbl.create 7
let add_used_primitive loc env path =
match path with
Some (Path.Pdot (path, _)) ->
let address = Env.find_module_address path env in
begin match Env.address_head address with
| AHunit cu ->
if not (Hashtbl.mem units_with_used_primitives cu)
then Hashtbl.add units_with_used_primitives cu loc
| AHlocal _ -> ()
end
| _ -> ()
let clear_used_primitives () = Hashtbl.clear units_with_used_primitives
let get_units_with_used_primitives () =
Hashtbl.fold (fun path _ acc -> path :: acc) units_with_used_primitives []
let gen_array_kind =
if Config.flat_float_array then Pgenarray else Paddrarray
let gen_array_ref_kind mode =
if Config.flat_float_array then Pgenarray_ref mode else Paddrarray_ref
let gen_array_set_kind mode =
if Config.flat_float_array then Pgenarray_set mode else Paddrarray_set mode
let prim_sys_argv =
Lambda.simple_prim_on_values ~name:"caml_sys_argv" ~arity:1 ~alloc:true
let to_locality ~poly = function
| Prim_global, _ -> alloc_heap
| Prim_local, _ -> alloc_local
| Prim_poly, _ ->
match poly with
| None -> assert false
| Some locality -> transl_locality_mode_l locality
let to_modify_mode ~poly = function
| Prim_global, _ -> modify_heap
| Prim_local, _ -> modify_maybe_stack
| Prim_poly, _ ->
match poly with
| None -> assert false
| Some mode -> transl_modify_mode mode
let extern_repr_of_native_repr:
poly_sort:Jkind.Sort.t option -> Primitive.native_repr -> Lambda.extern_repr
= fun ~poly_sort r -> match r, poly_sort with
| Repr_poly, Some s ->
Same_as_ocaml_repr (Jkind.Sort.default_to_value_and_get s)
| Repr_poly, None -> Misc.fatal_error "Unexpected Repr_poly"
| Same_as_ocaml_repr s, _ -> Same_as_ocaml_repr s
| Unboxed_float f, _ -> Unboxed_float f
| Unboxed_integer i, _ -> Unboxed_integer i
| Unboxed_vector i, _ -> Unboxed_vector i
| Untagged_immediate, _ -> Untagged_int
let sort_of_native_repr ~poly_sort repr =
match extern_repr_of_native_repr ~poly_sort repr with
| Same_as_ocaml_repr s -> s
| (Unboxed_float _ | Unboxed_integer _ | Untagged_int |
Unboxed_vector _) ->
Jkind.Sort.Const.Base Value
let to_lambda_prim prim ~poly_sort =
let native_repr_args =
List.map
(fun (m, r) -> m, extern_repr_of_native_repr ~poly_sort r)
prim.prim_native_repr_args
in
let native_repr_res =
let (m, r) = prim.prim_native_repr_res in
m, extern_repr_of_native_repr ~poly_sort r
in
Primitive.make
~name:prim.prim_name
~alloc:prim.prim_alloc
~c_builtin:prim.prim_c_builtin
~effects:prim.prim_effects
~coeffects:prim.prim_coeffects
~native_name:prim.prim_native_name
~native_repr_args
~native_repr_res
~is_layout_poly:prim.prim_is_layout_poly
let indexing_primitives =
let types_and_widths =
[
( (fun unsafe _boxed index_kind ->
Printf.sprintf "%%caml_bigstring_get16%s%s" unsafe index_kind),
fun ~unsafe ~boxed:_ ~index_kind ~mode:_ ->
Pbigstring_load_16 { unsafe; index_kind } );
( Printf.sprintf "%%caml_bigstring_get32%s%s%s",
fun ~unsafe ~boxed ~index_kind ~mode ->
Pbigstring_load_32 { unsafe; index_kind; mode; boxed } );
( Printf.sprintf "%%caml_bigstring_getf32%s%s%s",
fun ~unsafe ~boxed ~index_kind ~mode ->
Pbigstring_load_f32 { unsafe; index_kind; mode; boxed } );
( Printf.sprintf "%%caml_bigstring_get64%s%s%s",
fun ~unsafe ~boxed ~index_kind ~mode ->
Pbigstring_load_64 { unsafe; index_kind; mode; boxed } );
( Printf.sprintf "%%caml_bigstring_getu128%s%s%s",
fun ~unsafe ~boxed ~index_kind ~mode ->
Pbigstring_load_128
{ aligned = false; unsafe; index_kind; mode; boxed } );
( Printf.sprintf "%%caml_bigstring_geta128%s%s%s",
fun ~unsafe ~boxed ~index_kind ~mode ->
Pbigstring_load_128
{ aligned = true; unsafe; index_kind; mode; boxed } );
( (fun unsafe _boxed index_kind ->
Printf.sprintf "%%caml_bigstring_set16%s%s" unsafe index_kind),
fun ~unsafe ~boxed:_ ~index_kind ~mode:_ ->
Pbigstring_set_16 { unsafe; index_kind } );
( Printf.sprintf "%%caml_bigstring_set32%s%s%s",
fun ~unsafe ~boxed ~index_kind ~mode:_ ->
Pbigstring_set_32 { unsafe; index_kind; boxed } );
( Printf.sprintf "%%caml_bigstring_setf32%s%s%s",
fun ~unsafe ~boxed ~index_kind ~mode:_ ->
Pbigstring_set_f32 { unsafe; index_kind; boxed } );
( Printf.sprintf "%%caml_bigstring_set64%s%s%s",
fun ~unsafe ~boxed ~index_kind ~mode:_ ->
Pbigstring_set_64 { unsafe; index_kind; boxed } );
( Printf.sprintf "%%caml_bigstring_setu128%s%s%s",
fun ~unsafe ~boxed ~index_kind ~mode:_ ->
Pbigstring_set_128 { aligned = false; unsafe; index_kind; boxed } );
( Printf.sprintf "%%caml_bigstring_seta128%s%s%s",
fun ~unsafe ~boxed ~index_kind ~mode:_ ->
Pbigstring_set_128 { aligned = true; unsafe; index_kind; boxed } );
( (fun unsafe _boxed index_kind ->
Printf.sprintf "%%caml_bytes_get16%s%s" unsafe index_kind),
fun ~unsafe ~boxed:_ ~index_kind ~mode:_ ->
Pbytes_load_16 { unsafe; index_kind } );
( Printf.sprintf "%%caml_bytes_get32%s%s%s",
fun ~unsafe ~boxed ~index_kind ~mode ->
Pbytes_load_32 { unsafe; index_kind; mode; boxed } );
( Printf.sprintf "%%caml_bytes_getf32%s%s%s",
fun ~unsafe ~boxed ~index_kind ~mode ->
Pbytes_load_f32 { unsafe; index_kind; mode; boxed } );
( Printf.sprintf "%%caml_bytes_get64%s%s%s",
fun ~unsafe ~boxed ~index_kind ~mode ->
Pbytes_load_64 { unsafe; index_kind; mode; boxed } );
( Printf.sprintf "%%caml_bytes_getu128%s%s%s",
fun ~unsafe ~boxed ~index_kind ~mode ->
Pbytes_load_128 { unsafe; index_kind; mode; boxed } );
( (fun unsafe _boxed index_kind ->
Printf.sprintf "%%caml_bytes_set16%s%s" unsafe index_kind),
fun ~unsafe ~boxed:_ ~index_kind ~mode:_ ->
Pbytes_set_16 { unsafe; index_kind } );
( Printf.sprintf "%%caml_bytes_set32%s%s%s",
fun ~unsafe ~boxed ~index_kind ~mode:_ ->
Pbytes_set_32 { unsafe; index_kind; boxed } );
( Printf.sprintf "%%caml_bytes_setf32%s%s%s",
fun ~unsafe ~boxed ~index_kind ~mode:_ ->
Pbytes_set_f32 { unsafe; index_kind; boxed } );
( Printf.sprintf "%%caml_bytes_set64%s%s%s",
fun ~unsafe ~boxed ~index_kind ~mode:_ ->
Pbytes_set_64 { unsafe; index_kind; boxed } );
( Printf.sprintf "%%caml_bytes_setu128%s%s%s",
fun ~unsafe ~boxed ~index_kind ~mode:_ ->
Pbytes_set_128 { unsafe; index_kind; boxed } );
( (fun unsafe _boxed index_kind ->
Printf.sprintf "%%caml_string_get16%s%s" unsafe index_kind),
fun ~unsafe ~boxed:_ ~index_kind ~mode:_ ->
Pstring_load_16 { unsafe; index_kind } );
( Printf.sprintf "%%caml_string_get32%s%s%s",
fun ~unsafe ~boxed ~index_kind ~mode ->
Pstring_load_32 { unsafe; index_kind; mode; boxed } );
( Printf.sprintf "%%caml_string_getf32%s%s%s",
fun ~unsafe ~boxed ~index_kind ~mode ->
Pstring_load_f32 { unsafe; index_kind; mode; boxed } );
( Printf.sprintf "%%caml_string_get64%s%s%s",
fun ~unsafe ~boxed ~index_kind ~mode ->
Pstring_load_64 { unsafe; index_kind; mode; boxed } );
( Printf.sprintf "%%caml_string_getu128%s%s%s",
fun ~unsafe ~boxed ~index_kind ~mode ->
Pstring_load_128 { unsafe; index_kind; mode; boxed } );
(* We encourage respecting the immutability of [string]s and so do not add
new [string] setters. However, we keep existing setting primitives for
upstream compatibility. *)
( (fun unsafe _boxed _index_kind ->
Printf.sprintf "%%caml_string_set16%s" unsafe),
fun ~unsafe ~boxed:_ ~index_kind:_ ~mode:_ ->
Pbytes_set_16 { unsafe; index_kind = Ptagged_int_index } );
( (fun unsafe _boxed _index_kind ->
Printf.sprintf "%%caml_string_set32%s" unsafe ),
fun ~unsafe ~boxed:_ ~index_kind:_ ~mode:_ ->
Pbytes_set_32
{ unsafe; index_kind = Ptagged_int_index; boxed = true } ) ;
( (fun unsafe _boxed _index_kind ->
Printf.sprintf "%%caml_string_set64%s" unsafe ),
fun ~unsafe ~boxed:_ ~index_kind:_ ~mode:_ ->
Pbytes_set_64
{ unsafe; index_kind = Ptagged_int_index; boxed = true } )
]
in
let index_kinds =
[
(Ptagged_int_index, "");
(Punboxed_int_index Unboxed_nativeint, "_indexed_by_nativeint#");
(Punboxed_int_index Unboxed_int32, "_indexed_by_int32#");
(Punboxed_int_index Unboxed_int64, "_indexed_by_int64#");
]
in
(let ( let* ) x f = List.concat_map f x in
let* string_gen, primitive_gen = types_and_widths in
let* index_kind, index_kind_sigil = index_kinds in
let* unsafe, unsafe_sigil = [ (true, "u"); (false, "") ] in
let* boxed, boxed_sigil = [ (true, ""); (false, "#") ] in
let string = string_gen unsafe_sigil boxed_sigil index_kind_sigil in
let primitive = primitive_gen ~unsafe ~boxed ~index_kind in
let arity = if String.is_substring string ~substring:"get" then 2 else 3 in
[ (string, fun ~mode -> Primitive (primitive ~mode, arity)) ])
|> List.to_seq
|> fun seq -> String.Map.add_seq seq String.Map.empty
let lookup_primitive loc ~poly_mode ~poly_sort pos p =
let runtime5 = Config.runtime5 in
let mode = to_locality ~poly:poly_mode p.prim_native_repr_res in
let arg_modes =
List.map (to_modify_mode ~poly:poly_mode) p.prim_native_repr_args
in
let get_first_arg_mode () =
match arg_modes with
| mode :: _ -> mode
| [] ->
Misc.fatal_errorf "Primitive \"%s\" unexpectedly had zero arguments"
p.prim_name
in
let get_third_arg_mode () =
match arg_modes with
| _ :: _ :: mode :: _ -> mode
| _ ->
Misc.fatal_errorf "Primitive \"%s\" unexpectedly had fewer than three \
arguments"
p.prim_name
in
let lambda_prim = to_lambda_prim p ~poly_sort in
let layout =
(* Extract the result layout of the primitive. This can be a non-value
layout even without the use of [@layout_poly]. For example:
{[ external id : float# -> float# = "%opaque" ]}
We don't allow non-value layouts for most primitives. This is checked by
[prim_has_valid_reprs] in [typing/primitive.ml].
We don't extract the argument layouts just because it is not needed by
the middle-end. *)
let (_, repr) = lambda_prim.prim_native_repr_res in
Lambda.layout_of_extern_repr repr
in
let prim = match p.prim_name with
| "%identity" -> Identity
| "%bytes_to_string" -> Primitive (Pbytes_to_string, 1)
| "%bytes_of_string" -> Primitive (Pbytes_of_string, 1)
| "%ignore" -> Primitive (Pignore, 1)
| "%revapply" -> Revapply (pos, layout)
| "%apply" -> Apply (pos, layout)
| "%loc_LOC" -> Loc Loc_LOC
| "%loc_FILE" -> Loc Loc_FILE
| "%loc_LINE" -> Loc Loc_LINE
| "%loc_POS" -> Loc Loc_POS
| "%loc_MODULE" -> Loc Loc_MODULE
| "%loc_FUNCTION" -> Loc Loc_FUNCTION
| "%field0" -> Primitive (Pfield (0, Pointer, Reads_vary), 1)
| "%field1" -> Primitive (Pfield (1, Pointer, Reads_vary), 1)
| "%field0_immut" -> Primitive ((Pfield (0, Pointer, Reads_agree)), 1)
| "%field1_immut" -> Primitive ((Pfield (1, Pointer, Reads_agree)), 1)
| "%setfield0" ->
let mode = get_first_arg_mode () in
Primitive ((Psetfield(0, Pointer, Assignment mode)), 2)
| "%setfield1" ->
let mode = get_first_arg_mode () in
Primitive ((Psetfield(1, Pointer, Assignment mode)), 2);
| "%makeblock" -> Primitive ((Pmakeblock(0, Immutable, None, mode)), 1)
| "%makemutable" -> Primitive ((Pmakeblock(0, Mutable, None, mode)), 1)
| "%raise" -> Raise Raise_regular
| "%reraise" -> Raise Raise_reraise
| "%raise_notrace" -> Raise Raise_notrace
| "%raise_with_backtrace" -> Raise_with_backtrace
| "%sequand" -> Primitive (Psequand, 2)
| "%sequor" -> Primitive (Psequor, 2)
| "%boolnot" -> Primitive (Pnot, 1)
| "%big_endian" -> Primitive ((Pctconst Big_endian), 1)
| "%backend_type" -> Primitive ((Pctconst Backend_type), 1)
| "%word_size" -> Primitive ((Pctconst Word_size), 1)
| "%int_size" -> Primitive ((Pctconst Int_size), 1)
| "%max_wosize" -> Primitive ((Pctconst Max_wosize), 1)
| "%ostype_unix" -> Primitive ((Pctconst Ostype_unix), 1)
| "%ostype_win32" -> Primitive ((Pctconst Ostype_win32), 1)
| "%ostype_cygwin" -> Primitive ((Pctconst Ostype_cygwin), 1)
| "%runtime5" -> Primitive ((Pctconst Runtime5), 1)
| "%frame_pointers" -> Frame_pointers
| "%negint" -> Primitive (Pnegint, 1)
| "%succint" -> Primitive ((Poffsetint 1), 1)
| "%predint" -> Primitive ((Poffsetint(-1)), 1)
| "%addint" -> Primitive (Paddint, 2)
| "%subint" -> Primitive (Psubint, 2)
| "%mulint" -> Primitive (Pmulint, 2)
| "%divint" -> Primitive ((Pdivint Safe), 2)
| "%modint" -> Primitive ((Pmodint Safe), 2)
| "%andint" -> Primitive (Pandint, 2)
| "%orint" -> Primitive (Porint, 2)
| "%xorint" -> Primitive (Pxorint, 2)
| "%lslint" -> Primitive (Plslint, 2)
| "%lsrint" -> Primitive (Plsrint, 2)
| "%asrint" -> Primitive (Pasrint, 2)
| "%eq" -> Primitive ((Pintcomp Ceq), 2)
| "%noteq" -> Primitive ((Pintcomp Cne), 2)
| "%ltint" -> Primitive ((Pintcomp Clt), 2)
| "%leint" -> Primitive ((Pintcomp Cle), 2)
| "%gtint" -> Primitive ((Pintcomp Cgt), 2)
| "%geint" -> Primitive ((Pintcomp Cge), 2)
| "%incr" -> Primitive ((Poffsetref(1)), 1)
| "%decr" -> Primitive ((Poffsetref(-1)), 1)
| "%floatoffloat32" -> Primitive (Pfloatoffloat32 mode, 1)
| "%float32offloat" -> Primitive (Pfloat32offloat mode, 1)
| "%intoffloat32" -> Primitive (Pintoffloat Boxed_float32, 1)
| "%float32ofint" -> Primitive (Pfloatofint (Boxed_float32, mode), 1)
| "%negfloat32" -> Primitive (Pnegfloat (Boxed_float32, mode), 1)
| "%absfloat32" -> Primitive (Pabsfloat (Boxed_float32, mode), 1)
| "%addfloat32" -> Primitive (Paddfloat (Boxed_float32, mode), 2)
| "%subfloat32" -> Primitive (Psubfloat (Boxed_float32, mode), 2)
| "%mulfloat32" -> Primitive (Pmulfloat (Boxed_float32, mode), 2)
| "%divfloat32" -> Primitive (Pdivfloat (Boxed_float32, mode), 2)
| "%eqfloat32" -> Primitive ((Pfloatcomp (Boxed_float32, CFeq)), 2)
| "%noteqfloat32" -> Primitive ((Pfloatcomp (Boxed_float32, CFneq)), 2)
| "%ltfloat32" -> Primitive ((Pfloatcomp (Boxed_float32, CFlt)), 2)
| "%lefloat32" -> Primitive ((Pfloatcomp (Boxed_float32, CFle)), 2)
| "%gtfloat32" -> Primitive ((Pfloatcomp (Boxed_float32, CFgt)), 2)
| "%gefloat32" -> Primitive ((Pfloatcomp (Boxed_float32, CFge)), 2)
| "%intoffloat" -> Primitive (Pintoffloat Boxed_float64, 1)
| "%floatofint" -> Primitive (Pfloatofint (Boxed_float64, mode), 1)
| "%negfloat" -> Primitive (Pnegfloat (Boxed_float64, mode), 1)
| "%absfloat" -> Primitive (Pabsfloat (Boxed_float64, mode), 1)
| "%addfloat" -> Primitive (Paddfloat (Boxed_float64, mode), 2)
| "%subfloat" -> Primitive (Psubfloat (Boxed_float64, mode), 2)
| "%mulfloat" -> Primitive (Pmulfloat (Boxed_float64, mode), 2)
| "%divfloat" -> Primitive (Pdivfloat (Boxed_float64, mode), 2)
| "%eqfloat" -> Primitive ((Pfloatcomp (Boxed_float64, CFeq)), 2)
| "%noteqfloat" -> Primitive ((Pfloatcomp (Boxed_float64, CFneq)), 2)
| "%ltfloat" -> Primitive ((Pfloatcomp (Boxed_float64, CFlt)), 2)
| "%lefloat" -> Primitive ((Pfloatcomp (Boxed_float64, CFle)), 2)
| "%gtfloat" -> Primitive ((Pfloatcomp (Boxed_float64, CFgt)), 2)
| "%gefloat" -> Primitive ((Pfloatcomp (Boxed_float64, CFge)), 2)
| "%string_length" -> Primitive (Pstringlength, 1)
| "%string_safe_get" -> Primitive (Pstringrefs, 2)
| "%string_safe_set" -> Primitive (Pbytessets, 3)
| "%string_unsafe_get" -> Primitive (Pstringrefu, 2)
| "%string_unsafe_set" -> Primitive (Pbytessetu, 3)
| "%bytes_length" -> Primitive (Pbyteslength, 1)
| "%bytes_safe_get" -> Primitive (Pbytesrefs, 2)
| "%bytes_safe_set" -> Primitive (Pbytessets, 3)
| "%bytes_unsafe_get" -> Primitive (Pbytesrefu, 2)
| "%bytes_unsafe_set" -> Primitive (Pbytessetu, 3)
| "%array_length" -> Primitive ((Parraylength gen_array_kind), 1)
| "%array_safe_get" ->
Primitive
((Parrayrefs (gen_array_ref_kind mode, Ptagged_int_index, Mutable)), 2)
| "%array_safe_set" ->
Primitive
(Parraysets (gen_array_set_kind (get_first_arg_mode ()), Ptagged_int_index),
3)
| "%array_unsafe_get" ->
Primitive
(Parrayrefu (gen_array_ref_kind mode, Ptagged_int_index, Mutable), 2)
| "%array_unsafe_set" ->
Primitive
((Parraysetu (gen_array_set_kind (get_first_arg_mode ()), Ptagged_int_index)),
3)
| "%array_safe_get_indexed_by_int64#" ->
Primitive
((Parrayrefs (gen_array_ref_kind mode, Punboxed_int_index Unboxed_int64, Mutable)), 2)
| "%array_safe_set_indexed_by_int64#" ->
Primitive
(Parraysets
(gen_array_set_kind (get_first_arg_mode ()), Punboxed_int_index Unboxed_int64),
3)
| "%array_unsafe_get_indexed_by_int64#" ->
Primitive
(Parrayrefu (gen_array_ref_kind mode, Punboxed_int_index Unboxed_int64, Mutable), 2)
| "%array_unsafe_set_indexed_by_int64#" ->
Primitive
((Parraysetu
(gen_array_set_kind (get_first_arg_mode ()), Punboxed_int_index Unboxed_int64)),
3)
| "%array_safe_get_indexed_by_int32#" ->
Primitive
((Parrayrefs (gen_array_ref_kind mode, Punboxed_int_index Unboxed_int32, Mutable)), 2)
| "%array_safe_set_indexed_by_int32#" ->
Primitive
(Parraysets
(gen_array_set_kind (get_first_arg_mode ()), Punboxed_int_index Unboxed_int32),
3)
| "%array_unsafe_get_indexed_by_int32#" ->
Primitive
(Parrayrefu (gen_array_ref_kind mode, Punboxed_int_index Unboxed_int32, Mutable), 2)
| "%array_unsafe_set_indexed_by_int32#" ->
Primitive
((Parraysetu
(gen_array_set_kind (get_first_arg_mode ()), Punboxed_int_index Unboxed_int32)),
3)
| "%array_safe_get_indexed_by_nativeint#" ->
Primitive
((Parrayrefs (gen_array_ref_kind mode, Punboxed_int_index Unboxed_nativeint, Mutable)), 2)
| "%array_safe_set_indexed_by_nativeint#" ->
Primitive
(Parraysets
(gen_array_set_kind (get_first_arg_mode ()), Punboxed_int_index Unboxed_nativeint),
3)
| "%array_unsafe_get_indexed_by_nativeint#" ->
Primitive
(Parrayrefu (gen_array_ref_kind mode, Punboxed_int_index Unboxed_nativeint, Mutable), 2)
| "%array_unsafe_set_indexed_by_nativeint#" ->
Primitive
((Parraysetu
(gen_array_set_kind (get_first_arg_mode ()), Punboxed_int_index Unboxed_nativeint)),
3)
| "%makearray_dynamic" ->
Language_extension.assert_enabled ~loc Layouts Language_extension.Beta;
Primitive (Pmakearray_dynamic (gen_array_kind, mode, With_initializer), 2)
| "%makearray_dynamic_uninit" ->
Language_extension.assert_enabled ~loc Layouts Language_extension.Beta;
Primitive (Pmakearray_dynamic (gen_array_kind, mode, Uninitialized), 1)
| "%arrayblit" ->
Language_extension.assert_enabled ~loc Layouts Language_extension.Beta;
Primitive (Parrayblit {
src_mutability = Mutable;
dst_array_set_kind = gen_array_set_kind (get_third_arg_mode ())
}, 5);
| "%arrayblit_src_immut" ->
Language_extension.assert_enabled ~loc Layouts Language_extension.Beta;
Primitive (Parrayblit {
src_mutability = Immutable;
dst_array_set_kind = gen_array_set_kind (get_third_arg_mode ())
}, 5);
| "%array_element_size_in_bytes" ->
(* The array kind will be filled in later *)
Primitive (Parray_element_size_in_bytes Pgenarray, 1)
| "%obj_size" -> Primitive ((Parraylength Pgenarray), 1)
| "%obj_field" -> Primitive ((Parrayrefu (Pgenarray_ref mode, Ptagged_int_index, Mutable)), 2)
| "%obj_set_field" ->
Primitive
((Parraysetu (Pgenarray_set (get_first_arg_mode ()), Ptagged_int_index)), 3)
| "%floatarray_length" -> Primitive ((Parraylength Pfloatarray), 1)
| "%floatarray_safe_get" ->
Primitive ((Parrayrefs (Pfloatarray_ref mode, Ptagged_int_index, Mutable)), 2)
| "%floatarray_safe_set" ->
Primitive (Parraysets (Pfloatarray_set, Ptagged_int_index), 3)
| "%floatarray_unsafe_get" ->
Primitive ((Parrayrefu (Pfloatarray_ref mode, Ptagged_int_index, Mutable)), 2)
| "%floatarray_unsafe_set" ->
Primitive ((Parraysetu (Pfloatarray_set, Ptagged_int_index)), 3)
| "%obj_is_int" -> Primitive (Pisint { variant_only = false }, 1)
| "%is_null" -> Primitive (Pisnull, 1)
| "%lazy_force" -> Lazy_force pos
| "%nativeint_of_int" -> Primitive ((Pbintofint (Boxed_nativeint, mode)), 1)
| "%nativeint_to_int" -> Primitive ((Pintofbint Boxed_nativeint), 1)
| "%nativeint_neg" -> Primitive ((Pnegbint (Boxed_nativeint, mode)), 1)
| "%nativeint_add" -> Primitive ((Paddbint (Boxed_nativeint, mode)), 2)
| "%nativeint_sub" -> Primitive ((Psubbint (Boxed_nativeint, mode)), 2)
| "%nativeint_mul" -> Primitive ((Pmulbint (Boxed_nativeint, mode)), 2)
| "%nativeint_div" ->
Primitive ((Pdivbint { size = Boxed_nativeint; is_safe = Safe; mode }), 2);
| "%nativeint_mod" ->
Primitive ((Pmodbint { size = Boxed_nativeint; is_safe = Safe; mode }), 2);
| "%nativeint_and" -> Primitive ((Pandbint (Boxed_nativeint, mode)), 2)
| "%nativeint_or" -> Primitive ( (Porbint (Boxed_nativeint, mode)), 2)
| "%nativeint_xor" -> Primitive ((Pxorbint (Boxed_nativeint, mode)), 2)
| "%nativeint_lsl" -> Primitive ((Plslbint (Boxed_nativeint, mode)), 2)
| "%nativeint_lsr" -> Primitive ((Plsrbint (Boxed_nativeint, mode)), 2)
| "%nativeint_asr" -> Primitive ((Pasrbint (Boxed_nativeint, mode)), 2)
| "%int32_of_int" -> Primitive ((Pbintofint (Boxed_int32, mode)), 1)
| "%int32_to_int" -> Primitive ((Pintofbint Boxed_int32), 1)
| "%int32_neg" -> Primitive ((Pnegbint (Boxed_int32, mode)), 1)
| "%int32_add" -> Primitive ((Paddbint (Boxed_int32, mode)), 2)
| "%int32_sub" -> Primitive ((Psubbint (Boxed_int32, mode)), 2)
| "%int32_mul" -> Primitive ((Pmulbint (Boxed_int32, mode)), 2)
| "%int32_div" ->
Primitive ((Pdivbint { size = Boxed_int32; is_safe = Safe; mode }), 2)
| "%int32_mod" ->
Primitive ((Pmodbint { size = Boxed_int32; is_safe = Safe; mode }), 2)
| "%int32_and" -> Primitive ((Pandbint (Boxed_int32, mode)), 2)
| "%int32_or" -> Primitive ( (Porbint (Boxed_int32, mode)), 2)
| "%int32_xor" -> Primitive ((Pxorbint (Boxed_int32, mode)), 2)
| "%int32_lsl" -> Primitive ((Plslbint (Boxed_int32, mode)), 2)
| "%int32_lsr" -> Primitive ((Plsrbint (Boxed_int32, mode)), 2)
| "%int32_asr" -> Primitive ((Pasrbint (Boxed_int32, mode)), 2)
| "%int64_of_int" -> Primitive ((Pbintofint (Boxed_int64, mode)), 1)
| "%int64_to_int" -> Primitive ((Pintofbint Boxed_int64), 1)
| "%int64_neg" -> Primitive ((Pnegbint (Boxed_int64, mode)), 1)
| "%int64_add" -> Primitive ((Paddbint (Boxed_int64, mode)), 2)
| "%int64_sub" -> Primitive ((Psubbint (Boxed_int64, mode)), 2)
| "%int64_mul" -> Primitive ((Pmulbint (Boxed_int64, mode)), 2)
| "%int64_div" ->
Primitive ((Pdivbint { size = Boxed_int64; is_safe = Safe; mode }), 2)
| "%int64_mod" ->
Primitive ((Pmodbint { size = Boxed_int64; is_safe = Safe; mode }), 2)
| "%int64_and" -> Primitive ((Pandbint (Boxed_int64, mode)), 2)
| "%int64_or" -> Primitive ( (Porbint (Boxed_int64, mode)), 2)
| "%int64_xor" -> Primitive ((Pxorbint (Boxed_int64, mode)), 2)
| "%int64_lsl" -> Primitive ((Plslbint (Boxed_int64, mode)), 2)
| "%int64_lsr" -> Primitive ((Plsrbint (Boxed_int64, mode)), 2)
| "%int64_asr" -> Primitive ((Pasrbint (Boxed_int64, mode)), 2)
| "%nativeint_of_int32" -> Primitive ((Pcvtbint(Boxed_int32, Boxed_nativeint, mode)), 1)
| "%nativeint_to_int32" -> Primitive ((Pcvtbint(Boxed_nativeint, Boxed_int32, mode)), 1)
| "%int64_of_int32" -> Primitive ((Pcvtbint(Boxed_int32, Boxed_int64, mode)), 1)
| "%int64_to_int32" -> Primitive ((Pcvtbint(Boxed_int64, Boxed_int32, mode)), 1)
| "%int64_of_nativeint" -> Primitive ((Pcvtbint(Boxed_nativeint, Boxed_int64, mode)), 1)
| "%int64_to_nativeint" -> Primitive ((Pcvtbint(Boxed_int64, Boxed_nativeint, mode)), 1)
| "%caml_ba_ref_1" ->
Primitive
((Pbigarrayref(false, 1, Pbigarray_unknown, Pbigarray_unknown_layout)),
2);
| "%caml_ba_ref_2" ->
Primitive
((Pbigarrayref(false, 2, Pbigarray_unknown, Pbigarray_unknown_layout)),
3);
| "%caml_ba_ref_3" ->
Primitive
((Pbigarrayref(false, 3, Pbigarray_unknown, Pbigarray_unknown_layout)),
4);
| "%caml_ba_set_1" ->
Primitive
((Pbigarrayset(false, 1, Pbigarray_unknown, Pbigarray_unknown_layout)),
3);
| "%caml_ba_set_2" ->
Primitive
((Pbigarrayset(false, 2, Pbigarray_unknown, Pbigarray_unknown_layout)),
4);
| "%caml_ba_set_3" ->
Primitive
((Pbigarrayset(false, 3, Pbigarray_unknown, Pbigarray_unknown_layout)),
5);
| "%caml_ba_unsafe_ref_1" ->
Primitive
((Pbigarrayref(true, 1, Pbigarray_unknown, Pbigarray_unknown_layout)),
2);
| "%caml_ba_unsafe_ref_2" ->
Primitive
((Pbigarrayref(true, 2, Pbigarray_unknown, Pbigarray_unknown_layout)),
3);
| "%caml_ba_unsafe_ref_3" ->
Primitive
((Pbigarrayref(true, 3, Pbigarray_unknown, Pbigarray_unknown_layout)),
4);
| "%caml_ba_unsafe_set_1" ->
Primitive
((Pbigarrayset(true, 1, Pbigarray_unknown, Pbigarray_unknown_layout)),
3);
| "%caml_ba_unsafe_set_2" ->
Primitive
((Pbigarrayset(true, 2, Pbigarray_unknown, Pbigarray_unknown_layout)),
4);
| "%caml_ba_unsafe_set_3" ->
Primitive
((Pbigarrayset(true, 3, Pbigarray_unknown, Pbigarray_unknown_layout)),
5);
| "%caml_ba_float32_ref_1" ->
Primitive
((Pbigarrayref(false, 1, Pbigarray_float32_t, Pbigarray_unknown_layout)),
2);
| "%caml_ba_float32_ref_2" ->
Primitive
((Pbigarrayref(false, 2, Pbigarray_float32_t, Pbigarray_unknown_layout)),
3);
| "%caml_ba_float32_ref_3" ->
Primitive
((Pbigarrayref(false, 3, Pbigarray_float32_t, Pbigarray_unknown_layout)),
4);
| "%caml_ba_float32_set_1" ->
Primitive
((Pbigarrayset(false, 1, Pbigarray_float32_t, Pbigarray_unknown_layout)),
3);
| "%caml_ba_float32_set_2" ->
Primitive
((Pbigarrayset(false, 2, Pbigarray_float32_t, Pbigarray_unknown_layout)),
4);
| "%caml_ba_float32_set_3" ->
Primitive
((Pbigarrayset(false, 3, Pbigarray_float32_t, Pbigarray_unknown_layout)),
5);
| "%caml_ba_float32_unsafe_ref_1" ->
Primitive
((Pbigarrayref(true, 1, Pbigarray_float32_t, Pbigarray_unknown_layout)),
2);
| "%caml_ba_float32_unsafe_ref_2" ->
Primitive
((Pbigarrayref(true, 2, Pbigarray_float32_t, Pbigarray_unknown_layout)),
3);
| "%caml_ba_float32_unsafe_ref_3" ->
Primitive
((Pbigarrayref(true, 3, Pbigarray_float32_t, Pbigarray_unknown_layout)),
4);
| "%caml_ba_float32_unsafe_set_1" ->
Primitive
((Pbigarrayset(true, 1, Pbigarray_float32_t, Pbigarray_unknown_layout)),
3);
| "%caml_ba_float32_unsafe_set_2" ->
Primitive
((Pbigarrayset(true, 2, Pbigarray_float32_t, Pbigarray_unknown_layout)),
4);
| "%caml_ba_float32_unsafe_set_3" ->
Primitive
((Pbigarrayset(true, 3, Pbigarray_float32_t, Pbigarray_unknown_layout)),
5);
| "%caml_ba_dim_1" -> Primitive ((Pbigarraydim(1)), 1)
| "%caml_ba_dim_2" -> Primitive ((Pbigarraydim(2)), 1)
| "%caml_ba_dim_3" -> Primitive ((Pbigarraydim(3)), 1)
| "%caml_float_array_get128" ->
Primitive ((Pfloat_array_load_128 {unsafe = false; mode; boxed = true}), 2)
| "%caml_float_array_get128u" ->
Primitive ((Pfloat_array_load_128 {unsafe = true; mode; boxed = true}), 2)
| "%caml_floatarray_get128" ->
Primitive ((Pfloatarray_load_128 {unsafe = false; mode; boxed = true}), 2)
| "%caml_floatarray_get128u" ->
Primitive ((Pfloatarray_load_128 {unsafe = true; mode; boxed = true}), 2)
| "%caml_unboxed_float_array_get128" ->
Primitive ((Punboxed_float_array_load_128 {unsafe = false; mode; boxed = true}), 2)
| "%caml_unboxed_float_array_get128u" ->
Primitive ((Punboxed_float_array_load_128 {unsafe = true; mode; boxed = true}), 2)
| "%caml_unboxed_float32_array_get128" ->
Primitive ((Punboxed_float32_array_load_128 {unsafe = false; mode; boxed = true}), 2)
| "%caml_unboxed_float32_array_get128u" ->
Primitive ((Punboxed_float32_array_load_128 {unsafe = true; mode; boxed = true}), 2)
| "%caml_int_array_get128" ->
Primitive ((Pint_array_load_128 {unsafe = false; mode; boxed = true}), 2)
| "%caml_int_array_get128u" ->
Primitive ((Pint_array_load_128 {unsafe = true; mode; boxed = true}), 2)
| "%caml_unboxed_int64_array_get128" ->
Primitive ((Punboxed_int64_array_load_128 {unsafe = false; mode; boxed = true}), 2)
| "%caml_unboxed_int64_array_get128u" ->
Primitive ((Punboxed_int64_array_load_128 {unsafe = true; mode; boxed = true}), 2)
| "%caml_unboxed_int32_array_get128" ->
Primitive ((Punboxed_int32_array_load_128 {unsafe = false; mode; boxed = true}), 2)
| "%caml_unboxed_int32_array_get128u" ->
Primitive ((Punboxed_int32_array_load_128 {unsafe = true; mode; boxed = true}), 2)
| "%caml_unboxed_nativeint_array_get128" ->
Primitive ((Punboxed_nativeint_array_load_128 {unsafe = false; mode; boxed = true}), 2)
| "%caml_unboxed_nativeint_array_get128u" ->
Primitive ((Punboxed_nativeint_array_load_128 {unsafe = true; mode; boxed = true}), 2)
| "%caml_float_array_set128" ->
Primitive ((Pfloat_array_set_128 {unsafe = false; boxed = true}), 3)
| "%caml_float_array_set128u" ->
Primitive ((Pfloat_array_set_128 {unsafe = true; boxed = true}), 3)
| "%caml_floatarray_set128" ->
Primitive ((Pfloatarray_set_128 {unsafe = false; boxed = true}), 3)
| "%caml_floatarray_set128u" ->
Primitive ((Pfloatarray_set_128 {unsafe = true; boxed = true}), 3)
| "%caml_unboxed_float_array_set128" ->
Primitive ((Punboxed_float_array_set_128 {unsafe = false; boxed = true}), 3)
| "%caml_unboxed_float_array_set128u" ->
Primitive ((Punboxed_float_array_set_128 {unsafe = true; boxed = true}), 3)
| "%caml_unboxed_float32_array_set128" ->
Primitive ((Punboxed_float32_array_set_128 {unsafe = false; boxed = true}), 3)
| "%caml_unboxed_float32_array_set128u" ->
Primitive ((Punboxed_float32_array_set_128 {unsafe = true; boxed = true}), 3)
| "%caml_int_array_set128" ->
Primitive ((Pint_array_set_128 {unsafe = false; boxed = true}), 3)
| "%caml_int_array_set128u" ->
Primitive ((Pint_array_set_128 {unsafe = true; boxed = true}), 3)
| "%caml_unboxed_int64_array_set128" ->
Primitive ((Punboxed_int64_array_set_128 {unsafe = false; boxed = true}), 3)
| "%caml_unboxed_int64_array_set128u" ->
Primitive ((Punboxed_int64_array_set_128 {unsafe = true; boxed = true}), 3)
| "%caml_unboxed_int32_array_set128" ->
Primitive ((Punboxed_int32_array_set_128 {unsafe = false; boxed = true}), 3)
| "%caml_unboxed_int32_array_set128u" ->
Primitive ((Punboxed_int32_array_set_128 {unsafe = true; boxed = true}), 3)
| "%caml_unboxed_nativeint_array_set128" ->
Primitive ((Punboxed_nativeint_array_set_128 {unsafe = false; boxed = true}), 3)
| "%caml_unboxed_nativeint_array_set128u" ->
Primitive ((Punboxed_nativeint_array_set_128 {unsafe = true; boxed = true}), 3)
| "%caml_float_array_get128#" ->
Primitive ((Pfloat_array_load_128 {unsafe = false; mode; boxed = false}), 2)
| "%caml_float_array_get128u#" ->
Primitive ((Pfloat_array_load_128 {unsafe = true; mode; boxed = false}), 2)
| "%caml_floatarray_get128#" ->
Primitive ((Pfloatarray_load_128 {unsafe = false; mode; boxed = false}), 2)
| "%caml_floatarray_get128u#" ->
Primitive ((Pfloatarray_load_128 {unsafe = true; mode; boxed = false}), 2)
| "%caml_unboxed_float_array_get128#" ->
Primitive ((Punboxed_float_array_load_128 {unsafe = false; mode; boxed = false}), 2)
| "%caml_unboxed_float_array_get128u#" ->
Primitive ((Punboxed_float_array_load_128 {unsafe = true; mode; boxed = false}), 2)
| "%caml_unboxed_float32_array_get128#" ->
Primitive ((Punboxed_float32_array_load_128 {unsafe = false; mode; boxed = false}), 2)
| "%caml_unboxed_float32_array_get128u#" ->
Primitive ((Punboxed_float32_array_load_128 {unsafe = true; mode; boxed = false}), 2)
| "%caml_int_array_get128#" ->
Primitive ((Pint_array_load_128 {unsafe = false; mode; boxed = false}), 2)
| "%caml_int_array_get128u#" ->
Primitive ((Pint_array_load_128 {unsafe = true; mode; boxed = false}), 2)
| "%caml_unboxed_int64_array_get128#" ->
Primitive ((Punboxed_int64_array_load_128 {unsafe = false; mode; boxed = false}), 2)
| "%caml_unboxed_int64_array_get128u#" ->
Primitive ((Punboxed_int64_array_load_128 {unsafe = true; mode; boxed = false}), 2)
| "%caml_unboxed_int32_array_get128#" ->
Primitive ((Punboxed_int32_array_load_128 {unsafe = false; mode; boxed = false}), 2)
| "%caml_unboxed_int32_array_get128u#" ->
Primitive ((Punboxed_int32_array_load_128 {unsafe = true; mode; boxed = false}), 2)
| "%caml_unboxed_nativeint_array_get128#" ->
Primitive ((Punboxed_nativeint_array_load_128 {unsafe = false; mode; boxed = false}), 2)
| "%caml_unboxed_nativeint_array_get128u#" ->
Primitive ((Punboxed_nativeint_array_load_128 {unsafe = true; mode; boxed = false}), 2)
| "%caml_float_array_set128#" ->
Primitive ((Pfloat_array_set_128 {unsafe = false; boxed = false}), 3)
| "%caml_float_array_set128u#" ->
Primitive ((Pfloat_array_set_128 {unsafe = true; boxed = false}), 3)
| "%caml_floatarray_set128#" ->
Primitive ((Pfloatarray_set_128 {unsafe = false; boxed = false}), 3)
| "%caml_floatarray_set128u#" ->
Primitive ((Pfloatarray_set_128 {unsafe = true; boxed = false}), 3)
| "%caml_unboxed_float_array_set128#" ->
Primitive ((Punboxed_float_array_set_128 {unsafe = false; boxed = false}), 3)
| "%caml_unboxed_float_array_set128u#" ->
Primitive ((Punboxed_float_array_set_128 {unsafe = true; boxed = false}), 3)
| "%caml_unboxed_float32_array_set128#" ->
Primitive ((Punboxed_float32_array_set_128 {unsafe = false; boxed = false}), 3)
| "%caml_unboxed_float32_array_set128u#" ->
Primitive ((Punboxed_float32_array_set_128 {unsafe = true; boxed = false}), 3)
| "%caml_int_array_set128#" ->
Primitive ((Pint_array_set_128 {unsafe = false; boxed = false}), 3)
| "%caml_int_array_set128u#" ->
Primitive ((Pint_array_set_128 {unsafe = true; boxed = false}), 3)
| "%caml_unboxed_int64_array_set128#" ->
Primitive ((Punboxed_int64_array_set_128 {unsafe = false; boxed = false}), 3)
| "%caml_unboxed_int64_array_set128u#" ->
Primitive ((Punboxed_int64_array_set_128 {unsafe = true; boxed = false}), 3)
| "%caml_unboxed_int32_array_set128#" ->
Primitive ((Punboxed_int32_array_set_128 {unsafe = false; boxed = false}), 3)
| "%caml_unboxed_int32_array_set128u#" ->
Primitive ((Punboxed_int32_array_set_128 {unsafe = true; boxed = false}), 3)
| "%caml_unboxed_nativeint_array_set128#" ->
Primitive ((Punboxed_nativeint_array_set_128 {unsafe = false; boxed = false}), 3)
| "%caml_unboxed_nativeint_array_set128u#" ->
Primitive ((Punboxed_nativeint_array_set_128 {unsafe = true; boxed = false}), 3)
| "%bswap16" -> Primitive (Pbswap16, 1)
| "%bswap_int32" -> Primitive ((Pbbswap(Boxed_int32, mode)), 1)
| "%bswap_int64" -> Primitive ((Pbbswap(Boxed_int64, mode)), 1)
| "%bswap_native" -> Primitive ((Pbbswap(Boxed_nativeint, mode)), 1)
| "%int_as_pointer" -> Primitive (Pint_as_pointer mode, 1)
| "%opaque" -> Primitive (Popaque layout, 1)
| "%sys_argv" -> Sys_argv
| "%send" -> Send (pos, layout)
| "%sendself" -> Send_self (pos, layout)
| "%sendcache" -> Send_cache (pos, layout)
| "%equal" -> Comparison(Equal, Compare_generic)
| "%notequal" -> Comparison(Not_equal, Compare_generic)
| "%lessequal" -> Comparison(Less_equal, Compare_generic)
| "%lessthan" -> Comparison(Less_than, Compare_generic)
| "%greaterequal" -> Comparison(Greater_equal, Compare_generic)
| "%greaterthan" -> Comparison(Greater_than, Compare_generic)
| "%compare" -> Comparison(Compare, Compare_generic)
| "%obj_dup" -> Primitive(Pobj_dup, 1)
| "%obj_magic" -> Primitive(Pobj_magic layout, 1)
| "%array_to_iarray" -> Primitive (Parray_to_iarray, 1)
| "%array_of_iarray" -> Primitive (Parray_of_iarray, 1)
| "%unbox_float" -> Primitive(Punbox_float Boxed_float64, 1)
| "%box_float" -> Primitive(Pbox_float (Boxed_float64, mode), 1)
| "%unbox_float32" -> Primitive(Punbox_float Boxed_float32, 1)
| "%box_float32" -> Primitive(Pbox_float (Boxed_float32, mode), 1)
| "%unbox_vec128" -> Primitive(Punbox_vector Boxed_vec128, 1)
| "%box_vec128" -> Primitive(Pbox_vector (Boxed_vec128, mode), 1)
| "%get_header" -> Primitive (Pget_header mode, 1)
| "%atomic_load" ->
Primitive ((Patomic_load {immediate_or_pointer=Pointer}), 1)
| "%atomic_set" ->
Primitive (Patomic_set {immediate_or_pointer=Pointer}, 2)
| "%atomic_exchange" ->
Primitive (Patomic_exchange {immediate_or_pointer=Pointer}, 2)
| "%atomic_compare_exchange" ->
Primitive (Patomic_compare_exchange {immediate_or_pointer=Pointer}, 3)
| "%atomic_cas" ->
Primitive (Patomic_compare_set {immediate_or_pointer=Pointer}, 3)
| "%atomic_fetch_add" -> Primitive (Patomic_fetch_add, 2)
| "%atomic_add" -> Primitive (Patomic_add, 2)
| "%atomic_sub" -> Primitive (Patomic_sub, 2)
| "%atomic_land" -> Primitive (Patomic_land, 2)
| "%atomic_lor" -> Primitive (Patomic_lor, 2)
| "%atomic_lxor" -> Primitive (Patomic_lxor, 2)
| "%runstack" ->
if runtime5 then Primitive (Prunstack, 3) else Unsupported Prunstack
| "%reperform" ->
if runtime5 then Primitive (Preperform, 3) else Unsupported Preperform
| "%perform" ->
if runtime5 then Primitive (Pperform, 1) else Unsupported Pperform
| "%resume" ->
if runtime5 then Primitive (Presume, 4) else Unsupported Presume
| "%dls_get" -> Primitive (Pdls_get, 1)
| "%poll" -> Primitive (Ppoll, 1)
| "%unbox_nativeint" -> Primitive(Punbox_int Boxed_nativeint, 1)
| "%box_nativeint" -> Primitive(Pbox_int (Boxed_nativeint, mode), 1)
| "%unbox_int32" -> Primitive(Punbox_int Boxed_int32, 1)
| "%box_int32" -> Primitive(Pbox_int (Boxed_int32, mode), 1)
| "%unbox_int64" -> Primitive(Punbox_int Boxed_int64, 1)
| "%box_int64" -> Primitive(Pbox_int (Boxed_int64, mode), 1)
| "%reinterpret_tagged_int63_as_unboxed_int64" ->
Primitive(Preinterpret_tagged_int63_as_unboxed_int64, 1)
| "%reinterpret_unboxed_int64_as_tagged_int63" ->
Primitive(Preinterpret_unboxed_int64_as_tagged_int63, 1)
| "%peek" -> Peek None
| "%poke" -> Poke None
| s when String.length s > 0 && s.[0] = '%' ->
(match String.Map.find_opt s indexing_primitives with
| Some prim -> prim ~mode
| None -> raise (Error (loc, Unknown_builtin_primitive s)))
| _ -> External lambda_prim
in
prim
let lookup_primitive_and_mark_used loc ~poly_mode ~poly_sort pos p env path =
match lookup_primitive loc ~poly_mode ~poly_sort pos p with
| External _ as e -> add_used_primitive loc env path; e
| x -> x
let simplify_constant_constructor = function
| Equal -> true
| Not_equal -> true
| Less_equal -> false
| Less_than -> false
| Greater_equal -> false
| Greater_than -> false
| Compare -> false
(* See [glb_array_type] *)
let rec glb_scannable_kinds kinds1 kinds2 =
if List.length kinds1 = List.length kinds2 then
Misc.Stdlib.List.map2_option glb_scannable_kind kinds1 kinds2
else
None
and glb_scannable_kind kind1 kind2 =
match kind1, kind2 with
| Pint_scannable, (Paddr_scannable | Pint_scannable)
| Paddr_scannable, Pint_scannable -> Some Pint_scannable
| Paddr_scannable, Paddr_scannable -> Some Paddr_scannable
| Pproduct_scannable kinds1, Pproduct_scannable kinds2 ->
Option.map (fun x -> Pproduct_scannable x)
(glb_scannable_kinds kinds1 kinds2)
| (Pint_scannable | Paddr_scannable | Pproduct_scannable _), _ -> None
(* The following function computes the greatest lower bound of array kinds:
gen unboxed-float unboxed-int32 unboxed-int64 unboxed-nativeint
|
/------\
| |
addr float
|
int
For product kinds, we take the product of this lattice.
Note that the GLB is not guaranteed to exist.
In case of array kinds working with layout value, we return
our first argument instead of raising a fatal error because, although
it cannot happen in a well-typed program, (ab)use of Obj.magic can
probably trigger it. For other layouts, we raise an error.
*)
let glb_array_type loc t1 t2 =