@@ -59,182 +59,157 @@ let translate_unified_application (env : Env.t) (prim : Primitive.description)
59
59
*)
60
60
61
61
type specialized = {
62
- obj : Lambda .primitive ;
63
- int : Lambda .primitive ;
64
- bool : Lambda .primitive ;
65
- float : Lambda .primitive ;
66
- string : Lambda .primitive ;
67
- bigint : Lambda .primitive ;
62
+ objcomp : Lambda .primitive ;
63
+ intcomp : Lambda .primitive ;
64
+ boolcomp : Lambda .primitive ;
65
+ floatcomp : Lambda .primitive ;
66
+ stringcomp : Lambda .primitive ;
67
+ bigintcomp : Lambda .primitive ;
68
68
simplify_constant_constructor : bool ;
69
69
}
70
70
71
- let infix_table =
72
- create_hashtable
73
- [|
74
- ( " %add" ,
75
- {
76
- obj = Paddint ;
77
- int = Paddint ;
78
- bool = Pinfix Inf_invariant ;
79
- float = Paddfloat ;
80
- string = Pstringadd ;
81
- bigint = Paddbigint ;
82
- simplify_constant_constructor = false ;
83
- } );
84
- ( " %sub" ,
85
- {
86
- obj = Paddint ;
87
- int = Psubint ;
88
- bool = Pinfix Inf_invariant ;
89
- float = Psubfloat ;
90
- string = Pinfix Inf_invariant ;
91
- bigint = Psubbigint ;
92
- simplify_constant_constructor = false ;
93
- } );
94
- |]
95
-
96
71
let comparisons_table =
97
72
create_hashtable
98
73
[|
99
74
( " %equal" ,
100
75
{
101
- obj = Pobjcomp Ceq ;
102
- int = Pintcomp Ceq ;
103
- bool = Pboolcomp Ceq ;
104
- float = Pfloatcomp Ceq ;
105
- string = Pstringcomp Ceq ;
106
- bigint = Pbigintcomp Ceq ;
76
+ objcomp = Pobjcomp Ceq ;
77
+ intcomp = Pintcomp Ceq ;
78
+ boolcomp = Pboolcomp Ceq ;
79
+ floatcomp = Pfloatcomp Ceq ;
80
+ stringcomp = Pstringcomp Ceq ;
81
+ bigintcomp = Pbigintcomp Ceq ;
107
82
simplify_constant_constructor = true ;
108
83
} );
109
84
( " %notequal" ,
110
85
{
111
- obj = Pobjcomp Cneq ;
112
- int = Pintcomp Cneq ;
113
- bool = Pboolcomp Cneq ;
114
- float = Pfloatcomp Cneq ;
115
- string = Pstringcomp Cneq ;
116
- bigint = Pbigintcomp Cneq ;
86
+ objcomp = Pobjcomp Cneq ;
87
+ intcomp = Pintcomp Cneq ;
88
+ boolcomp = Pboolcomp Cneq ;
89
+ floatcomp = Pfloatcomp Cneq ;
90
+ stringcomp = Pstringcomp Cneq ;
91
+ bigintcomp = Pbigintcomp Cneq ;
117
92
simplify_constant_constructor = true ;
118
93
} );
119
94
( " %lessthan" ,
120
95
{
121
- obj = Pobjcomp Clt ;
122
- int = Pintcomp Clt ;
123
- bool = Pboolcomp Clt ;
124
- float = Pfloatcomp Clt ;
125
- string = Pstringcomp Clt ;
126
- bigint = Pbigintcomp Clt ;
96
+ objcomp = Pobjcomp Clt ;
97
+ intcomp = Pintcomp Clt ;
98
+ boolcomp = Pboolcomp Clt ;
99
+ floatcomp = Pfloatcomp Clt ;
100
+ stringcomp = Pstringcomp Clt ;
101
+ bigintcomp = Pbigintcomp Clt ;
127
102
simplify_constant_constructor = false ;
128
103
} );
129
104
( " %greaterthan" ,
130
105
{
131
- obj = Pobjcomp Cgt ;
132
- int = Pintcomp Cgt ;
133
- bool = Pboolcomp Cgt ;
134
- float = Pfloatcomp Cgt ;
135
- string = Pstringcomp Cgt ;
136
- bigint = Pbigintcomp Cgt ;
106
+ objcomp = Pobjcomp Cgt ;
107
+ intcomp = Pintcomp Cgt ;
108
+ boolcomp = Pboolcomp Cgt ;
109
+ floatcomp = Pfloatcomp Cgt ;
110
+ stringcomp = Pstringcomp Cgt ;
111
+ bigintcomp = Pbigintcomp Cgt ;
137
112
simplify_constant_constructor = false ;
138
113
} );
139
114
( " %lessequal" ,
140
115
{
141
- obj = Pobjcomp Cle ;
142
- int = Pintcomp Cle ;
143
- bool = Pboolcomp Cle ;
144
- float = Pfloatcomp Cle ;
145
- string = Pstringcomp Cle ;
146
- bigint = Pbigintcomp Cle ;
116
+ objcomp = Pobjcomp Cle ;
117
+ intcomp = Pintcomp Cle ;
118
+ boolcomp = Pboolcomp Cle ;
119
+ floatcomp = Pfloatcomp Cle ;
120
+ stringcomp = Pstringcomp Cle ;
121
+ bigintcomp = Pbigintcomp Cle ;
147
122
simplify_constant_constructor = false ;
148
123
} );
149
124
( " %greaterequal" ,
150
125
{
151
- obj = Pobjcomp Cge ;
152
- int = Pintcomp Cge ;
153
- bool = Pboolcomp Cge ;
154
- float = Pfloatcomp Cge ;
155
- string = Pstringcomp Cge ;
156
- bigint = Pbigintcomp Cge ;
126
+ objcomp = Pobjcomp Cge ;
127
+ intcomp = Pintcomp Cge ;
128
+ boolcomp = Pboolcomp Cge ;
129
+ floatcomp = Pfloatcomp Cge ;
130
+ stringcomp = Pstringcomp Cge ;
131
+ bigintcomp = Pbigintcomp Cge ;
157
132
simplify_constant_constructor = false ;
158
133
} );
159
134
( " %compare" ,
160
135
{
161
- obj = Pobjorder ;
162
- int = Pintorder ;
163
- bool = Pboolorder ;
164
- float = Pfloatorder ;
165
- string = Pstringorder ;
166
- bigint = Pbigintorder ;
136
+ objcomp = Pobjorder ;
137
+ intcomp = Pintorder ;
138
+ boolcomp = Pboolorder ;
139
+ floatcomp = Pfloatorder ;
140
+ stringcomp = Pstringorder ;
141
+ bigintcomp = Pbigintorder ;
167
142
simplify_constant_constructor = false ;
168
143
} );
169
144
( " %max" ,
170
145
{
171
- obj = Pobjmax ;
172
- int = Pintmax ;
173
- bool = Pboolmax ;
174
- float = Pboolmax ;
175
- string = Pstringmax ;
176
- bigint = Pbigintmax ;
146
+ objcomp = Pobjmax ;
147
+ intcomp = Pintmax ;
148
+ boolcomp = Pboolmax ;
149
+ floatcomp = Pboolmax ;
150
+ stringcomp = Pstringmax ;
151
+ bigintcomp = Pbigintmax ;
177
152
simplify_constant_constructor = false ;
178
153
} );
179
154
( " %min" ,
180
155
{
181
- obj = Pobjmin ;
182
- int = Pintmin ;
183
- bool = Pboolmin ;
184
- float = Pfloatmin ;
185
- string = Pstringmin ;
186
- bigint = Pbigintmin ;
156
+ objcomp = Pobjmin ;
157
+ intcomp = Pintmin ;
158
+ boolcomp = Pboolmin ;
159
+ floatcomp = Pfloatmin ;
160
+ stringcomp = Pstringmin ;
161
+ bigintcomp = Pbigintmin ;
187
162
simplify_constant_constructor = false ;
188
163
} );
189
164
( " %equal_null" ,
190
165
{
191
- obj = Pobjcomp Ceq ;
192
- int = Pintcomp Ceq ;
193
- bool = Pboolcomp Ceq ;
194
- float = Pfloatcomp Ceq ;
195
- string = Pstringcomp Ceq ;
196
- bigint = Pbigintcomp Ceq ;
166
+ objcomp = Pobjcomp Ceq ;
167
+ intcomp = Pintcomp Ceq ;
168
+ boolcomp = Pboolcomp Ceq ;
169
+ floatcomp = Pfloatcomp Ceq ;
170
+ stringcomp = Pstringcomp Ceq ;
171
+ bigintcomp = Pbigintcomp Ceq ;
197
172
simplify_constant_constructor = false ;
198
173
} );
199
174
( " %equal_undefined" ,
200
175
{
201
- obj = Pobjcomp Ceq ;
202
- int = Pintcomp Ceq ;
203
- bool = Pboolcomp Ceq ;
204
- float = Pfloatcomp Ceq ;
205
- string = Pstringcomp Ceq ;
206
- bigint = Pbigintcomp Ceq ;
176
+ objcomp = Pobjcomp Ceq ;
177
+ intcomp = Pintcomp Ceq ;
178
+ boolcomp = Pboolcomp Ceq ;
179
+ floatcomp = Pfloatcomp Ceq ;
180
+ stringcomp = Pstringcomp Ceq ;
181
+ bigintcomp = Pbigintcomp Ceq ;
207
182
simplify_constant_constructor = false ;
208
183
} );
209
184
( " %equal_nullable" ,
210
185
{
211
- obj = Pobjcomp Ceq ;
212
- int = Pintcomp Ceq ;
213
- bool = Pboolcomp Ceq ;
214
- float = Pfloatcomp Ceq ;
215
- string = Pstringcomp Ceq ;
216
- bigint = Pbigintcomp Ceq ;
186
+ objcomp = Pobjcomp Ceq ;
187
+ intcomp = Pintcomp Ceq ;
188
+ boolcomp = Pboolcomp Ceq ;
189
+ floatcomp = Pfloatcomp Ceq ;
190
+ stringcomp = Pstringcomp Ceq ;
191
+ bigintcomp = Pbigintcomp Ceq ;
217
192
simplify_constant_constructor = false ;
218
193
} );
219
194
(* FIXME: Core compatibility *)
220
195
( " %bs_min" ,
221
196
{
222
- obj = Pobjmax ;
223
- int = Pintmax ;
224
- bool = Pboolmax ;
225
- float = Pboolmax ;
226
- string = Pstringmax ;
227
- bigint = Pbigintmax ;
197
+ objcomp = Pobjmax ;
198
+ intcomp = Pintmax ;
199
+ boolcomp = Pboolmax ;
200
+ floatcomp = Pboolmax ;
201
+ stringcomp = Pstringmax ;
202
+ bigintcomp = Pbigintmax ;
228
203
simplify_constant_constructor = false ;
229
204
} );
230
205
( " %bs_max" ,
231
206
{
232
- obj = Pobjmin ;
233
- int = Pintmin ;
234
- bool = Pboolmin ;
235
- float = Pfloatmin ;
236
- string = Pstringmin ;
237
- bigint = Pbigintmin ;
207
+ objcomp = Pobjmin ;
208
+ intcomp = Pintmin ;
209
+ boolcomp = Pboolmin ;
210
+ floatcomp = Pfloatmin ;
211
+ stringcomp = Pstringmin ;
212
+ bigintcomp = Pbigintmin ;
238
213
simplify_constant_constructor = false ;
239
214
} );
240
215
|]
@@ -409,36 +384,31 @@ let primitives_table =
409
384
410
385
let find_primitive prim_name = Hashtbl. find primitives_table prim_name
411
386
412
- let specialize_op ({obj; int; float; string; bigint; bool} : specialized ) env ty
413
- =
387
+ let specialize_comparison
388
+ ({objcomp; intcomp; floatcomp; stringcomp; bigintcomp; boolcomp} :
389
+ specialized ) env ty =
414
390
match () with
415
391
| ()
416
392
when is_base_type env ty Predef. path_int
417
393
|| is_base_type env ty Predef. path_char
418
394
|| maybe_pointer_type env ty = Immediate ->
419
- int
420
- | () when is_base_type env ty Predef. path_float -> float
421
- | () when is_base_type env ty Predef. path_string -> string
422
- | () when is_base_type env ty Predef. path_bigint -> bigint
423
- | () when is_base_type env ty Predef. path_bool -> bool
424
- | () -> obj
395
+ intcomp
396
+ | () when is_base_type env ty Predef. path_float -> floatcomp
397
+ | () when is_base_type env ty Predef. path_string -> stringcomp
398
+ | () when is_base_type env ty Predef. path_bigint -> bigintcomp
399
+ | () when is_base_type env ty Predef. path_bool -> boolcomp
400
+ | () -> objcomp
425
401
426
402
(* Specialize a primitive from available type information,
427
403
raise Not_found if primitive is unknown *)
428
404
429
405
let specialize_primitive p env ty (* ~has_constant_constructor *) =
430
406
try
431
- let table = Hashtbl. find infix_table p.prim_name in
407
+ let table = Hashtbl. find comparisons_table p.prim_name in
432
408
match is_function_type env ty with
433
- | Some (lhs , _rhs ) -> specialize_op table env lhs
434
- | None -> table.obj
435
- with Not_found -> (
436
- try
437
- let table = Hashtbl. find comparisons_table p.prim_name in
438
- match is_function_type env ty with
439
- | Some (lhs , _rhs ) -> specialize_op table env lhs
440
- | None -> table.obj
441
- with Not_found -> find_primitive p.prim_name)
409
+ | Some (lhs , _rhs ) -> specialize_comparison table env lhs
410
+ | None -> table.objcomp
411
+ with Not_found -> find_primitive p.prim_name
442
412
443
413
(* Eta-expand a primitive *)
444
414
@@ -502,9 +472,7 @@ let transl_primitive_application loc prim env ty args =
502
472
| [arg1; _]
503
473
when is_base_type env arg1.exp_type Predef. path_bool
504
474
&& Hashtbl. mem comparisons_table prim_name ->
505
- (Hashtbl. find comparisons_table prim_name).bool
506
- | [arg1; _] when Hashtbl. mem infix_table prim_name ->
507
- specialize_op (Hashtbl. find infix_table prim_name) env arg1.exp_type
475
+ (Hashtbl. find comparisons_table prim_name).boolcomp
508
476
| _ ->
509
477
let has_constant_constructor =
510
478
match args with
@@ -517,7 +485,7 @@ let transl_primitive_application loc prim env ty args =
517
485
in
518
486
if has_constant_constructor then
519
487
match Hashtbl. find_opt comparisons_table prim_name with
520
- | Some table when table.simplify_constant_constructor -> table.int
488
+ | Some table when table.simplify_constant_constructor -> table.intcomp
521
489
| Some _ | None -> specialize_primitive prim env ty
522
490
(* ~has_constant_constructor*)
523
491
else specialize_primitive prim env ty
0 commit comments