@@ -29,7 +29,7 @@ let set_static_env s value = Hashtbl.add static_env s value
2929
3030let get_static_env s = try Some (Hashtbl. find static_env s) with Not_found -> None
3131
32- module Int = Int32
32+ module Int = Targetint
3333
3434let int_binop l f =
3535 match l with
@@ -38,16 +38,16 @@ let int_binop l f =
3838
3939let shift l f =
4040 match l with
41- | [ Int i; Int j ] -> Some (Int (f i (Int32. to_int j land 0x1f )))
41+ | [ Int i; Int j ] -> Some (Int (f i (Targetint. to_int_exn j land 0x1f )))
4242 | _ -> None
4343
4444let float_binop_aux (l : constant list ) (f : float -> float -> 'a ) : 'a option =
4545 let args =
4646 match l with
4747 | [ Float i; Float j ] -> Some (i, j)
48- | [ Int i; Int j ] -> Some (Int32 . to_float i, Int32 . to_float j)
49- | [ Int i; Float j ] -> Some (Int32 . to_float i, j)
50- | [ Float i; Int j ] -> Some (i, Int32 . to_float j)
48+ | [ Int i; Int j ] -> Some (Targetint . to_float i, Targetint . to_float j)
49+ | [ Int i; Float j ] -> Some (Targetint . to_float i, j)
50+ | [ Float i; Int j ] -> Some (i, Targetint . to_float j)
5151 | _ -> None
5252 in
5353 match args with
@@ -62,10 +62,10 @@ let float_binop (l : constant list) (f : float -> float -> float) : constant opt
6262let float_unop (l : constant list ) (f : float -> float ) : constant option =
6363 match l with
6464 | [ Float i ] -> Some (Float (f i))
65- | [ Int i ] -> Some (Float (f (Int32 . to_float i)))
65+ | [ Int i ] -> Some (Float (f (Targetint . to_float i)))
6666 | _ -> None
6767
68- let bool' b = Int (if b then 1l else 0l )
68+ let bool' b = Int Targetint. (if b then one else zero )
6969
7070let bool b = Some (bool ' b)
7171
@@ -76,20 +76,20 @@ let float_binop_bool l f =
7676
7777let eval_prim x =
7878 match x with
79- | Not , [ Int i ] -> bool Int32. (i = 0l )
80- | Lt , [ Int i; Int j ] -> bool Int32 . (i < j)
81- | Le , [ Int i; Int j ] -> bool Int32 . (i < = j)
82- | Eq , [ Int i; Int j ] -> bool Int32 . (i = j)
83- | Neq , [ Int i; Int j ] -> bool Int32 . (i <> j)
84- | Ult , [ Int i; Int j ] -> bool (Int32 . (j < 0l ) || Int32 . (i < j))
79+ | Not , [ Int i ] -> bool ( Targetint. is_zero i )
80+ | Lt , [ Int i; Int j ] -> bool Targetint . (i < j)
81+ | Le , [ Int i; Int j ] -> bool Targetint . (i < = j)
82+ | Eq , [ Int i; Int j ] -> bool Targetint . (i = j)
83+ | Neq , [ Int i; Int j ] -> bool Targetint . (i <> j)
84+ | Ult , [ Int i; Int j ] -> bool (Targetint . (j < zero ) || Targetint . (i < j))
8585 | Extern name , l -> (
8686 let name = Primitive. resolve name in
8787 match name, l with
8888 (* int *)
8989 | "%int_add" , _ -> int_binop l Int. add
9090 | "%int_sub" , _ -> int_binop l Int. sub
9191 | "%direct_int_mul" , _ -> int_binop l Int. mul
92- | "%direct_int_div" , [ _; Int 0l ] -> None
92+ | "%direct_int_div" , [ _; Int maybe_zero ] when Targetint. is_zero maybe_zero -> None
9393 | "%direct_int_div" , _ -> int_binop l Int. div
9494 | "%direct_int_mod" , _ -> int_binop l Int. rem
9595 | "%int_and" , _ -> int_binop l Int. logand
@@ -111,9 +111,7 @@ let eval_prim x =
111111 | "caml_mul_float" , _ -> float_binop l ( *. )
112112 | "caml_div_float" , _ -> float_binop l ( /. )
113113 | "caml_fmod_float" , _ -> float_binop l mod_float
114- | "caml_int_of_float" , [ Float f ] -> Some (Int (Int32. of_float f))
115- | "to_int" , [ Float f ] -> Some (Int (Int32. of_float f))
116- | "to_int" , [ Int i ] -> Some (Int i)
114+ | "caml_int_of_float" , [ Float f ] -> Some (Int (Targetint. of_float f))
117115 (* Math *)
118116 | "caml_neg_float" , _ -> float_unop l ( ~-. )
119117 | "caml_abs_float" , _ -> float_unop l abs_float
@@ -131,9 +129,9 @@ let eval_prim x =
131129 | "caml_sqrt_float" , _ -> float_unop l sqrt
132130 | "caml_tan_float" , _ -> float_unop l tan
133131 | ("caml_string_get" | "caml_string_unsafe_get" ), [ String s; Int pos ] ->
134- let pos = Int. to_int pos in
132+ let pos = Int. to_int_exn pos in
135133 if Config.Flag. safe_string () && pos > = 0 && pos < String. length s
136- then Some (Int (Int. of_int (Char. code s.[pos])))
134+ then Some (Int (Int. of_int_exn (Char. code s.[pos])))
137135 else None
138136 | "caml_string_equal" , [ String s1; String s2 ] -> bool (String. equal s1 s2)
139137 | "caml_string_notequal" , [ String s1; String s2 ] ->
@@ -142,10 +140,11 @@ let eval_prim x =
142140 match get_static_env s with
143141 | Some env -> Some (String env)
144142 | None -> None )
145- | "caml_sys_const_word_size" , [ _ ] -> Some (Int 32l )
146- | "caml_sys_const_int_size" , [ _ ] -> Some (Int 32l )
147- | "caml_sys_const_big_endian" , [ _ ] -> Some (Int 0l )
148- | "caml_sys_const_naked_pointers_checked" , [ _ ] -> Some (Int 0l )
143+ | "caml_sys_const_word_size" , [ _ ] -> Some (Int (Targetint. of_int_exn 32 ))
144+ | "caml_sys_const_int_size" , [ _ ] ->
145+ Some (Int (Targetint. of_int_exn Targetint. num_bits))
146+ | "caml_sys_const_big_endian" , [ _ ] -> Some (Int Targetint. zero)
147+ | "caml_sys_const_naked_pointers_checked" , [ _ ] -> Some (Int Targetint. zero)
149148 | _ -> None )
150149 | _ -> None
151150
@@ -154,14 +153,14 @@ let the_length_of info x =
154153 info
155154 (fun x ->
156155 match Flow.Info. def info x with
157- | Some (Constant (String s )) -> Some (Int32. of_int (String. length s))
156+ | Some (Constant (String s )) -> Some (Targetint. of_int_exn (String. length s))
158157 | Some (Prim (Extern " caml_create_string" , [ arg ]))
159158 | Some (Prim (Extern "caml_create_bytes" , [ arg ])) -> the_int info arg
160159 | None | Some _ -> None )
161160 None
162161 (fun u v ->
163162 match u, v with
164- | Some l , Some l' when Int32 . (l = l') -> Some l
163+ | Some l , Some l' when Targetint . (l = l') -> Some l
165164 | _ -> None )
166165 x
167166
@@ -225,7 +224,7 @@ let the_cont_of info x (a : cont array) =
225224 (fun x ->
226225 match Flow.Info. def info x with
227226 | Some (Prim (Extern "%direct_obj_tag" , [ b ])) -> the_tag_of info b get
228- | Some (Constant (Int j )) -> get (Int32. to_int j)
227+ | Some (Constant (Int j )) -> get (Targetint. to_int_exn j)
229228 | None | Some _ -> None )
230229 None
231230 (fun u v ->
@@ -237,7 +236,7 @@ let the_cont_of info x (a : cont array) =
237236(* If [constant_js_equal a b = Some v], then [caml_js_equals a b = v]). *)
238237let constant_js_equal a b =
239238 match a, b with
240- | Int i , Int j -> Some (Int32 . equal i j)
239+ | Int i , Int j -> Some (Targetint . equal i j)
241240 | Float a , Float b -> Some (Float. ieee_equal a b)
242241 | NativeString a , NativeString b -> Some (Native_string. equal a b)
243242 | String a , String b when Config.Flag. use_js_string () -> Some (String. equal a b)
@@ -289,7 +288,7 @@ let eval_instr info ((x, loc) as i) =
289288 | Let (x , Prim (Extern "caml_ml_string_length" , [ s ])) -> (
290289 let c =
291290 match s with
292- | Pc (String s ) -> Some (Int32. of_int (String. length s))
291+ | Pc (String s ) -> Some (Targetint. of_int_exn (String. length s))
293292 | Pv v -> the_length_of info v
294293 | _ -> None
295294 in
@@ -324,7 +323,7 @@ let eval_instr info ((x, loc) as i) =
324323 | Let (x , Prim (Extern "%direct_obj_tag" , [ y ])) -> (
325324 match the_tag_of info y (fun x -> Some x) with
326325 | Some tag ->
327- let c = Constant (Int (Int32. of_int tag)) in
326+ let c = Constant (Int (Targetint. of_int_exn tag)) in
328327 Flow.Info. update_def info x c;
329328 [ Let (x, c), loc ]
330329 | None -> [ i ])
@@ -381,11 +380,10 @@ let the_cond_of info x =
381380 info
382381 (fun x ->
383382 match Flow.Info. def info x with
384- | Some (Constant (Int 0l )) -> Zero
383+ | Some (Constant (Int x )) -> if Targetint. is_zero x then Zero else Non_zero
385384 | Some
386385 (Constant
387- ( Int _
388- | Int32 _
386+ ( Int32 _
389387 | NativeInt _
390388 | Float _
391389 | Tuple _
0 commit comments