@@ -215,15 +215,31 @@ module Generate (Target : Target_sig.S) = struct
215
215
(transl_prim_arg ctx ~typ: (Int Normalized ) x)
216
216
(transl_prim_arg ctx ~typ: (Int Normalized ) y)
217
217
218
- let translate_int_equality ctx op op' x y =
218
+ let translate_int_equality ctx ~ negate x y =
219
219
match get_type ctx x, get_type ctx y with
220
220
| (Int Normalized as typ ), Int Normalized ->
221
- op (transl_prim_arg ctx ~typ x) (transl_prim_arg ctx ~typ y)
221
+ (if negate then Arith. ( <> ) else Arith. ( = ))
222
+ (transl_prim_arg ctx ~typ x)
223
+ (transl_prim_arg ctx ~typ y)
222
224
| Int (Normalized | Unnormalized ), Int (Normalized | Unnormalized ) ->
223
- op
225
+ ( if negate then Arith. ( <> ) else Arith. ( = ))
224
226
Arith. (transl_prim_arg ctx ~typ: (Int Unnormalized ) x lsl const 1l )
225
227
Arith. (transl_prim_arg ctx ~typ: (Int Unnormalized ) y lsl const 1l )
226
- | _ -> op' (transl_prim_arg ctx ~typ: Top x) (transl_prim_arg ctx ~typ: Top y)
228
+ | Top , Top ->
229
+ Value. js_eqeqeq
230
+ ~negate
231
+ (transl_prim_arg ctx ~typ: Top x)
232
+ (transl_prim_arg ctx ~typ: Top y)
233
+ | Bot , _ | _ , Bot ->
234
+ (* this is deadcode *)
235
+ (if negate then Value. phys_neq else Value. phys_eq)
236
+ (transl_prim_arg ctx ~typ: Top x)
237
+ (transl_prim_arg ctx ~typ: Top y)
238
+ | (Int _ | Number _ | Tuple _ ), _ | _ , (Int _ | Number _ | Tuple _ ) ->
239
+ (* Only Top may contain JavaScript values *)
240
+ (if negate then Value. phys_neq else Value. phys_eq)
241
+ (transl_prim_arg ctx ~typ: Top x)
242
+ (transl_prim_arg ctx ~typ: Top y)
227
243
228
244
let internal_primitives =
229
245
let h = String.Hashtbl. create 128 in
@@ -864,8 +880,8 @@ module Generate (Target : Target_sig.S) = struct
864
880
| Prim (Lt, [ x ; y ]) -> translate_int_comparison ctx Arith. ( < ) x y
865
881
| Prim (Le, [ x ; y ]) -> translate_int_comparison ctx Arith. ( < = ) x y
866
882
| Prim (Ult, [ x ; y ]) -> translate_int_comparison ctx Arith. ult x y
867
- | Prim (Eq, [ x ; y ]) -> translate_int_equality ctx Arith. ( = ) Value. eq x y
868
- | Prim (Neq, [ x ; y ]) -> translate_int_equality ctx Arith. ( <> ) Value. neq x y
883
+ | Prim (Eq, [ x ; y ]) -> translate_int_equality ctx ~negate: false x y
884
+ | Prim (Neq, [ x ; y ]) -> translate_int_equality ctx ~negate: true x y
869
885
| Prim (Array_get, [ x ; y ]) ->
870
886
Memory. array_get
871
887
(transl_prim_arg ctx x)
0 commit comments