Skip to content

Commit 2a5d9f2

Browse files
committed
remove redundant arith support
1 parent 748d95a commit 2a5d9f2

File tree

7 files changed

+19
-451
lines changed

7 files changed

+19
-451
lines changed

jscomp/core/lam_compile_primitive.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,15 +535,15 @@ let translate loc
535535
| [e;e1] -> Js_of_lam_array.ref_array e e1 (* Todo: Constant Folding *)
536536
| _ -> assert false)
537537
| Parrayrefs ->
538-
Lam_dispatch_primitive.translate loc "caml_array_get" args
538+
E.runtime_call Js_runtime_modules.array "caml_array_get" args
539+
| Parraysets ->
540+
E.runtime_call Js_runtime_modules.array "caml_array_set" args
539541
| Pmakearray ->
540542
Js_of_lam_array.make_array Mutable args
541543
| Parraysetu ->
542544
(match args with (* wrong*)
543545
| [e;e0;e1] -> ensure_value_unit cxt.continuation (Js_of_lam_array.set_array e e0 e1)
544546
| _ -> assert false)
545-
| Parraysets ->
546-
Lam_dispatch_primitive.translate loc "caml_array_set" args
547547
| Pccall prim ->
548548
Lam_dispatch_primitive.translate loc prim.prim_name args
549549
(* Lam_compile_external_call.translate loc cxt prim args *)

jscomp/core/lam_dispatch_primitive.ml

Lines changed: 1 addition & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -97,57 +97,6 @@ let translate loc (prim_name : string)
9797
| [e] -> e
9898
| _ -> assert false
9999
end
100-
| "caml_array_get" ->
101-
call Js_runtime_modules.array
102-
| "caml_array_set" ->
103-
call Js_runtime_modules.array
104-
| "caml_array_unsafe_set"
105-
->
106-
begin match args with
107-
| [e0;e1;e2] ->
108-
Js_of_lam_array.set_array e0 e1 e2
109-
| _ -> assert false
110-
end
111-
112-
| "caml_int32_add"
113-
->
114-
begin match args with
115-
| [e0;e1] -> E.int32_add e0 e1
116-
| _ -> assert false
117-
end
118-
119-
| "caml_nativeint_add"
120-
->
121-
begin match args with
122-
| [e0;e1] -> E.unchecked_int32_add e0 e1
123-
| _ -> assert false
124-
end
125-
| "caml_int32_div"
126-
->
127-
begin match args with
128-
| [e0;e1] ->
129-
E.int32_div ~checked:(!Js_config.check_div_by_zero) e0 e1
130-
| _ -> assert false
131-
end
132-
133-
| "caml_nativeint_div"
134-
-> (* nativeint behaves exactly the same as js numbers except division *)
135-
begin match args with
136-
| [e0;e1] -> E.int32_div ~checked:false e0 e1
137-
| _ -> assert false
138-
end
139-
140-
| "caml_int32_mul"
141-
->
142-
begin match args with
143-
| [e0;e1] -> E.int32_mul e0 e1
144-
| _ -> assert false
145-
end
146-
| "caml_nativeint_mul" ->
147-
begin match args with
148-
| [e0;e1] -> E.unchecked_int32_mul e0 e1
149-
| _ -> assert false
150-
end
151100
| "caml_int32_of_int"
152101
| "caml_nativeint_of_int"
153102
| "caml_nativeint_of_int32" ->
@@ -171,63 +120,6 @@ let translate loc (prim_name : string)
171120
| [e] -> e (* TODO: do more checking when [to_int32]*)
172121
| _ -> assert false
173122
end
174-
| "caml_int32_sub" ->
175-
begin match args with
176-
| [e0;e1] -> E.int32_minus e0 e1
177-
| _ -> assert false
178-
end
179-
180-
| "caml_nativeint_sub" ->
181-
begin match args with
182-
| [e0;e1] -> E.unchecked_int32_minus e0 e1
183-
| _ -> assert false
184-
end
185-
| "caml_int32_xor"
186-
| "caml_nativeint_xor" ->
187-
begin match args with
188-
| [e0; e1] -> E.int32_bxor e0 e1
189-
| _ -> assert false
190-
end
191-
192-
| "caml_int32_and"
193-
| "caml_nativeint_and" ->
194-
begin match args with
195-
| [e0;e1] -> E.int32_band e0 e1
196-
| _ -> assert false
197-
end
198-
| "caml_int32_or"
199-
| "caml_nativeint_or" ->
200-
begin match args with
201-
| [e0;e1] -> E.int32_bor e0 e1
202-
| _ -> assert false
203-
end
204-
| "caml_le_float" ->
205-
begin match args with
206-
| [e0;e1] -> E.float_comp Cle e0 e1
207-
| _ -> assert false
208-
end
209-
| "caml_lt_float" ->
210-
begin match args with
211-
| [e0;e1] -> E.float_comp Clt e0 e1
212-
| _ -> assert false
213-
end
214-
| "caml_neg_float" ->
215-
begin match args with
216-
| [e] ->
217-
(** TODO: use float.. *)
218-
E.int32_minus E.zero_int_literal e
219-
| _ -> assert false
220-
end
221-
| "caml_neq_float" ->
222-
begin match args with
223-
| [e0;e1] -> E.float_notequal e0 e1
224-
| _ -> assert false
225-
end
226-
| "caml_mul_float" ->
227-
begin match args with
228-
| [e0; e1] -> E.float_mul e0 e1
229-
| _ -> assert false
230-
end
231123
| "caml_bytes_compare"
232124
| "caml_bytes_equal"
233125
->
@@ -452,7 +344,7 @@ let translate loc (prim_name : string)
452344
begin match args with
453345
| [{expression_desc = Bool a} ; {expression_desc = Bool b} ]
454346
->
455-
let c = compare a b in
347+
let c = compare (a : bool) b in
456348
E.int (if c = 0 then 0l else if c > 0 then 1l else -1l)
457349
| _ ->
458350
call Js_runtime_modules.caml_primitive

jscomp/runtime/caml_hash.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ let unsafe_pop (q : 'a t) =
7878

7979

8080
external ( +~ ) : nativeint -> nativeint -> nativeint =
81-
"caml_int32_add"
81+
"%int32_add"
8282

8383

8484
open Caml_hash_primitive

jscomp/runtime/caml_hash_primitive.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ let (>>>) = Caml_nativeint_extern.shift_right_logical
2929
let (|~) = Caml_nativeint_extern.logor
3030
let (^) = Caml_nativeint_extern.logxor
3131

32-
external ( *~ ) : nativeint -> nativeint -> nativeint = "caml_int32_mul"
33-
external ( +~ ) : nativeint -> nativeint -> nativeint = "caml_int32_add"
32+
external ( *~ ) : nativeint -> nativeint -> nativeint = "%int32_mul"
33+
external ( +~ ) : nativeint -> nativeint -> nativeint = "%int32_add"
3434

3535

3636

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 4 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -110689,57 +110689,6 @@ let translate loc (prim_name : string)
110689110689
| [e] -> e
110690110690
| _ -> assert false
110691110691
end
110692-
| "caml_array_get" ->
110693-
call Js_runtime_modules.array
110694-
| "caml_array_set" ->
110695-
call Js_runtime_modules.array
110696-
| "caml_array_unsafe_set"
110697-
->
110698-
begin match args with
110699-
| [e0;e1;e2] ->
110700-
Js_of_lam_array.set_array e0 e1 e2
110701-
| _ -> assert false
110702-
end
110703-
110704-
| "caml_int32_add"
110705-
->
110706-
begin match args with
110707-
| [e0;e1] -> E.int32_add e0 e1
110708-
| _ -> assert false
110709-
end
110710-
110711-
| "caml_nativeint_add"
110712-
->
110713-
begin match args with
110714-
| [e0;e1] -> E.unchecked_int32_add e0 e1
110715-
| _ -> assert false
110716-
end
110717-
| "caml_int32_div"
110718-
->
110719-
begin match args with
110720-
| [e0;e1] ->
110721-
E.int32_div ~checked:(!Js_config.check_div_by_zero) e0 e1
110722-
| _ -> assert false
110723-
end
110724-
110725-
| "caml_nativeint_div"
110726-
-> (* nativeint behaves exactly the same as js numbers except division *)
110727-
begin match args with
110728-
| [e0;e1] -> E.int32_div ~checked:false e0 e1
110729-
| _ -> assert false
110730-
end
110731-
110732-
| "caml_int32_mul"
110733-
->
110734-
begin match args with
110735-
| [e0;e1] -> E.int32_mul e0 e1
110736-
| _ -> assert false
110737-
end
110738-
| "caml_nativeint_mul" ->
110739-
begin match args with
110740-
| [e0;e1] -> E.unchecked_int32_mul e0 e1
110741-
| _ -> assert false
110742-
end
110743110692
| "caml_int32_of_int"
110744110693
| "caml_nativeint_of_int"
110745110694
| "caml_nativeint_of_int32" ->
@@ -110763,63 +110712,6 @@ let translate loc (prim_name : string)
110763110712
| [e] -> e (* TODO: do more checking when [to_int32]*)
110764110713
| _ -> assert false
110765110714
end
110766-
| "caml_int32_sub" ->
110767-
begin match args with
110768-
| [e0;e1] -> E.int32_minus e0 e1
110769-
| _ -> assert false
110770-
end
110771-
110772-
| "caml_nativeint_sub" ->
110773-
begin match args with
110774-
| [e0;e1] -> E.unchecked_int32_minus e0 e1
110775-
| _ -> assert false
110776-
end
110777-
| "caml_int32_xor"
110778-
| "caml_nativeint_xor" ->
110779-
begin match args with
110780-
| [e0; e1] -> E.int32_bxor e0 e1
110781-
| _ -> assert false
110782-
end
110783-
110784-
| "caml_int32_and"
110785-
| "caml_nativeint_and" ->
110786-
begin match args with
110787-
| [e0;e1] -> E.int32_band e0 e1
110788-
| _ -> assert false
110789-
end
110790-
| "caml_int32_or"
110791-
| "caml_nativeint_or" ->
110792-
begin match args with
110793-
| [e0;e1] -> E.int32_bor e0 e1
110794-
| _ -> assert false
110795-
end
110796-
| "caml_le_float" ->
110797-
begin match args with
110798-
| [e0;e1] -> E.float_comp Cle e0 e1
110799-
| _ -> assert false
110800-
end
110801-
| "caml_lt_float" ->
110802-
begin match args with
110803-
| [e0;e1] -> E.float_comp Clt e0 e1
110804-
| _ -> assert false
110805-
end
110806-
| "caml_neg_float" ->
110807-
begin match args with
110808-
| [e] ->
110809-
(** TODO: use float.. *)
110810-
E.int32_minus E.zero_int_literal e
110811-
| _ -> assert false
110812-
end
110813-
| "caml_neq_float" ->
110814-
begin match args with
110815-
| [e0;e1] -> E.float_notequal e0 e1
110816-
| _ -> assert false
110817-
end
110818-
| "caml_mul_float" ->
110819-
begin match args with
110820-
| [e0; e1] -> E.float_mul e0 e1
110821-
| _ -> assert false
110822-
end
110823110715
| "caml_bytes_compare"
110824110716
| "caml_bytes_equal"
110825110717
->
@@ -111044,7 +110936,7 @@ let translate loc (prim_name : string)
111044110936
begin match args with
111045110937
| [{expression_desc = Bool a} ; {expression_desc = Bool b} ]
111046110938
->
111047-
let c = compare a b in
110939+
let c = compare (a : bool) b in
111048110940
E.int (if c = 0 then 0l else if c > 0 then 1l else -1l)
111049110941
| _ ->
111050110942
call Js_runtime_modules.caml_primitive
@@ -111876,15 +111768,15 @@ let translate loc
111876111768
| [e;e1] -> Js_of_lam_array.ref_array e e1 (* Todo: Constant Folding *)
111877111769
| _ -> assert false)
111878111770
| Parrayrefs ->
111879-
Lam_dispatch_primitive.translate loc "caml_array_get" args
111771+
E.runtime_call Js_runtime_modules.array "caml_array_get" args
111772+
| Parraysets ->
111773+
E.runtime_call Js_runtime_modules.array "caml_array_set" args
111880111774
| Pmakearray ->
111881111775
Js_of_lam_array.make_array Mutable args
111882111776
| Parraysetu ->
111883111777
(match args with (* wrong*)
111884111778
| [e;e0;e1] -> ensure_value_unit cxt.continuation (Js_of_lam_array.set_array e e0 e1)
111885111779
| _ -> assert false)
111886-
| Parraysets ->
111887-
Lam_dispatch_primitive.translate loc "caml_array_set" args
111888111780
| Pccall prim ->
111889111781
Lam_dispatch_primitive.translate loc prim.prim_name args
111890111782
(* Lam_compile_external_call.translate loc cxt prim args *)

0 commit comments

Comments
 (0)