Skip to content

Commit 05a5bfe

Browse files
authored
Merge pull request #4603 from BuckleScript/clean_up_array_primitives
clean up array primitives support, add missing bytes primitives
2 parents 7a38a3c + 40a7e8a commit 05a5bfe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+637
-3049
lines changed

jscomp/core/lam_compile_primitive.ml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -435,13 +435,6 @@ let translate loc
435435
-> Ext_list.singleton_exn args
436436
| Pintofbint Pint64
437437
-> Js_long.to_int32 args
438-
(* | Pabsfloat ->
439-
begin match args with
440-
| [e] ->
441-
E.math "abs" [e]
442-
(* GCC treat built-ins like Math in a dirfferent way*)
443-
| _ -> assert false
444-
end *)
445438
| Pnot ->
446439
E.not (Ext_list.singleton_exn args)
447440
| Poffsetint n ->
@@ -542,15 +535,15 @@ let translate loc
542535
| [e;e1] -> Js_of_lam_array.ref_array e e1 (* Todo: Constant Folding *)
543536
| _ -> assert false)
544537
| Parrayrefs ->
545-
Lam_dispatch_primitive.translate loc "caml_array_get" args
538+
E.runtime_call Js_runtime_modules.array "get" args
539+
| Parraysets ->
540+
E.runtime_call Js_runtime_modules.array "set" args
546541
| Pmakearray ->
547542
Js_of_lam_array.make_array Mutable args
548543
| Parraysetu ->
549544
(match args with (* wrong*)
550545
| [e;e0;e1] -> ensure_value_unit cxt.continuation (Js_of_lam_array.set_array e e0 e1)
551546
| _ -> assert false)
552-
| Parraysets ->
553-
Lam_dispatch_primitive.translate loc "caml_array_set" args
554547
| Pccall prim ->
555548
Lam_dispatch_primitive.translate loc prim.prim_name args
556549
(* Lam_compile_external_call.translate loc cxt prim args *)

jscomp/core/lam_dispatch_primitive.ml

Lines changed: 5 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,6 @@ let translate loc (prim_name : string)
6262
let call m =
6363
E.runtime_call m prim_name args in
6464
begin match prim_name with
65-
(* | "caml_gc_stat"
66-
| "caml_gc_quick_stat"
67-
| "caml_gc_get" *)
68-
| "caml_gc_counters"
69-
| "caml_gc_set"
70-
| "caml_gc_minor"
71-
| "caml_gc_major_slice"
72-
| "caml_gc_major"
73-
| "caml_gc_full_major"
74-
| "caml_gc_compaction"
75-
| "caml_final_register"
76-
| "caml_final_release"
77-
-> call Js_runtime_modules.gc
78-
(* | "caml_abs_float" ->
79-
E.math "abs" args *)
80-
(* | "caml_acos_float" ->
81-
E.math "acos" args *)
8265
| "caml_add_float" ->
8366
begin match args with
8467
| [e0;e1] -> E.float_add e0 e1 (** TODO float plus*)
@@ -109,110 +92,11 @@ let translate loc (prim_name : string)
10992
| [e0;e1] -> E.float_comp Cgt e0 e1
11093
| _ -> assert false
11194
end
112-
(* | "caml_tan_float" ->
113-
E.math "tan" args
114-
| "caml_tanh_float" ->
115-
E.math "tanh" args
116-
| "caml_asin_float" ->
117-
E.math "asin" args
118-
| "caml_atan2_float" ->
119-
E.math "atan2" args
120-
| "caml_atan_float" ->
121-
E.math "atan" args
122-
| "caml_ceil_float" ->
123-
E.math "ceil" args
124-
| "caml_cos_float" ->
125-
E.math "cos" args
126-
| "caml_cosh_float" ->
127-
E.math "cosh" args
128-
| "caml_exp_float" ->
129-
E.math "exp" args
130-
| "caml_sin_float" ->
131-
E.math "sin" args
132-
| "caml_sinh_float"->
133-
E.math "sinh" args
134-
| "caml_sqrt_float" ->
135-
E.math "sqrt" args
136-
137-
*)
13895
| "caml_float_of_int" ->
13996
begin match args with
14097
| [e] -> e
14198
| _ -> assert false
14299
end
143-
(* | "caml_floor_float" ->
144-
E.math "floor" args
145-
| "caml_log_float" ->
146-
E.math "log" args
147-
| "caml_log10_float" ->
148-
E.math "log10" args
149-
| "caml_log1p_float" ->
150-
E.math "log1p" args
151-
| "caml_power_float" ->
152-
E.math "pow" args *)
153-
154-
| "caml_array_get" ->
155-
call Js_runtime_modules.array
156-
| "caml_array_get_addr"
157-
| "caml_array_get_float"
158-
| "caml_array_unsafe_get"
159-
| "caml_array_unsafe_get_float" ->
160-
begin match args with
161-
| [e0;e1] -> Js_of_lam_array.ref_array e0 e1
162-
| _ -> assert false
163-
end
164-
| "caml_array_set" ->
165-
call Js_runtime_modules.array
166-
| "caml_array_set_addr"
167-
| "caml_array_set_float"
168-
| "caml_array_unsafe_set"
169-
| "caml_array_unsafe_set_addr"
170-
| "caml_array_unsafe_set_float" ->
171-
begin match args with
172-
| [e0;e1;e2] ->
173-
Js_of_lam_array.set_array e0 e1 e2
174-
| _ -> assert false
175-
end
176-
177-
| "caml_int32_add"
178-
->
179-
begin match args with
180-
| [e0;e1] -> E.int32_add e0 e1
181-
| _ -> assert false
182-
end
183-
184-
| "caml_nativeint_add"
185-
->
186-
begin match args with
187-
| [e0;e1] -> E.unchecked_int32_add e0 e1
188-
| _ -> assert false
189-
end
190-
| "caml_int32_div"
191-
->
192-
begin match args with
193-
| [e0;e1] ->
194-
E.int32_div ~checked:(!Js_config.check_div_by_zero) e0 e1
195-
| _ -> assert false
196-
end
197-
198-
| "caml_nativeint_div"
199-
-> (* nativeint behaves exactly the same as js numbers except division *)
200-
begin match args with
201-
| [e0;e1] -> E.int32_div ~checked:false e0 e1
202-
| _ -> assert false
203-
end
204-
205-
| "caml_int32_mul"
206-
->
207-
begin match args with
208-
| [e0;e1] -> E.int32_mul e0 e1
209-
| _ -> assert false
210-
end
211-
| "caml_nativeint_mul" ->
212-
begin match args with
213-
| [e0;e1] -> E.unchecked_int32_mul e0 e1
214-
| _ -> assert false
215-
end
216100
| "caml_int32_of_int"
217101
| "caml_nativeint_of_int"
218102
| "caml_nativeint_of_int32" ->
@@ -236,63 +120,10 @@ let translate loc (prim_name : string)
236120
| [e] -> e (* TODO: do more checking when [to_int32]*)
237121
| _ -> assert false
238122
end
239-
| "caml_int32_sub" ->
240-
begin match args with
241-
| [e0;e1] -> E.int32_minus e0 e1
242-
| _ -> assert false
243-
end
244-
245-
| "caml_nativeint_sub" ->
246-
begin match args with
247-
| [e0;e1] -> E.unchecked_int32_minus e0 e1
248-
| _ -> assert false
249-
end
250-
| "caml_int32_xor"
251-
| "caml_nativeint_xor" ->
252-
begin match args with
253-
| [e0; e1] -> E.int32_bxor e0 e1
254-
| _ -> assert false
255-
end
256-
257-
| "caml_int32_and"
258-
| "caml_nativeint_and" ->
259-
begin match args with
260-
| [e0;e1] -> E.int32_band e0 e1
261-
| _ -> assert false
262-
end
263-
| "caml_int32_or"
264-
| "caml_nativeint_or" ->
265-
begin match args with
266-
| [e0;e1] -> E.int32_bor e0 e1
267-
| _ -> assert false
268-
end
269-
| "caml_le_float" ->
270-
begin match args with
271-
| [e0;e1] -> E.float_comp Cle e0 e1
272-
| _ -> assert false
273-
end
274-
| "caml_lt_float" ->
275-
begin match args with
276-
| [e0;e1] -> E.float_comp Clt e0 e1
277-
| _ -> assert false
278-
end
279-
| "caml_neg_float" ->
280-
begin match args with
281-
| [e] ->
282-
(** TODO: use float.. *)
283-
E.int32_minus E.zero_int_literal e
284-
| _ -> assert false
285-
end
286-
| "caml_neq_float" ->
287-
begin match args with
288-
| [e0;e1] -> E.float_notequal e0 e1
289-
| _ -> assert false
290-
end
291-
| "caml_mul_float" ->
292-
begin match args with
293-
| [e0; e1] -> E.float_mul e0 e1
294-
| _ -> assert false
295-
end
123+
| "caml_bytes_greaterthan"
124+
| "caml_bytes_greaterequal"
125+
| "caml_bytes_lessthan"
126+
| "caml_bytes_lessequal"
296127
| "caml_bytes_compare"
297128
| "caml_bytes_equal"
298129
->
@@ -517,7 +348,7 @@ let translate loc (prim_name : string)
517348
begin match args with
518349
| [{expression_desc = Bool a} ; {expression_desc = Bool b} ]
519350
->
520-
let c = compare a b in
351+
let c = compare (a : bool) b in
521352
E.int (if c = 0 then 0l else if c > 0 then 1l else -1l)
522353
| _ ->
523354
call Js_runtime_modules.caml_primitive

jscomp/ext/js_runtime_modules.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ let caml_oo_curry = "Caml_oo_curry"
4242
let caml_primitive = "Caml_primitive"
4343
let int64 = "Caml_int64"
4444
let md5 = "Caml_md5"
45-
let gc = "Caml_gc"
4645
let int32 = "Caml_int32"
4746

4847

jscomp/main/builtin_cmi_datasets.ml

Lines changed: 1 addition & 5 deletions
Large diffs are not rendered by default.

jscomp/main/builtin_cmj_datasets.ml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
(* 32aae419ae48962a58b4bf4a6a0d9f6a *)
1+
(* 42d368f93e07dc14ada8ffc65a706b6e *)
22
let module_names : string array = Obj.magic (
3-
"Gc" (* 220 *),
43
"Js" (* 23 *),
54
"Arg" (* 289 *),
65
"Dom" (* 23 *),
@@ -68,7 +67,6 @@ let module_names : string array = Obj.magic (
6867
"Js_vector" (* 516 *),
6968
"Nativeint" (* 493 *),
7069
"Node_path" (* 23 *),
71-
"Spacetime" (* 125 *),
7270
"StdLabels" (* 23 *),
7371
"Belt_Array" (* 1149 *),
7472
"Belt_Float" (* 42 *),
@@ -135,7 +133,6 @@ let module_names : string array = Obj.magic (
135133
"CamlinternalFormatBasics" (* 81 *)
136134
)
137135
let module_data : string array = Obj.magic (
138-
(* Gc *)"\132\149\166\190\000\000\000\200\000\000\0004\000\000\000\177\000\000\000\163\160\b\000\000(\000\176#get\144\160\160A@@@\176$stat\144\160\160A@@@\176(finalise\144\160\160B@@@\176*print_stat\144\160\160A@@@\176*quick_stat\144\160\160A@@@\176,create_alarm\144\160\160A@@@\176,delete_alarm\144\160\160A@@@\176-finalise_last\144\160\160B@@@\176/allocated_bytes\144\160\160A@@@\1760finalise_release\144\160\160A@@@A",
139136
(* Js *)"\132\149\166\190\000\000\000\003\000\000\000\001\000\000\000\003\000\000\000\003\160\128A",
140137
(* Arg *)"\132\149\166\190\000\000\001\r\000\000\000C\000\000\000\232\000\000\000\212\160\b\000\0004\000\176%align\144\160\160B@@@\176%parse\144\160\160C@@@\176%usage\144\160\160B@@@\176(read_arg\144\160\160A@@@\176)read_arg0\144\160\160A@@@\176)write_arg\144\160\160B@@@\176*parse_argv\144\160\160E@@@\176*write_arg0\144\160\160B@@@\176,parse_expand\144\160\160C@@@\176,usage_string\144\160\160B@@@\176-parse_dynamic\144\160\160C@@@\1762parse_argv_dynamic\144\160\160E@@@\176=parse_and_expand_argv_dynamic\144\160\160E@@@A",
141138
(* Dom *)"\132\149\166\190\000\000\000\003\000\000\000\001\000\000\000\003\000\000\000\003\160\128A",
@@ -203,7 +200,6 @@ let module_data : string array = Obj.magic (
203200
(* Js_vector *)"\132\149\166\190\000\000\001\240\000\000\000\151\000\000\001\237\000\000\001\215\160\b\000\0008\000\176#map\144\160\160B@@@\176$copy\144\160\160A@@@\176$init\144\160\160B@@@\176$iter\144\160\160B@@@\176$mapi\144\160\160B@@@\176%empty\144\160\160A@@\144\180A\160\176\001\004\146!a@@\174\151\176\181&splice\160\160AA\160\160A@@\197&splice@@@\160\144\004\015\160\146\160@@@\176\1923others/js_vector.mlt\001\bY\001\b[\192\004\002t\001\bY\001\b\127@\146A\176%iteri\144\160\160B@@@\176&append\144\160\160B@@\144\180B\160\176\001\004\204!x@\160\176\001\004\205!a@@\151\176\181&concat\160\160AA\160\004\002@\197&concat@@@\160\144\004\r\160\151\176e\160\144\004\021@\176\192\004'\001\000\140\001\015S\001\015h\192\004(\001\000\140\001\015S\001\015m@@\176\192\004*\001\000\140\001\015S\001\015U\004\003@\176&toList\144\160\160A@@@\176(foldLeft\144\160\160C@@@\176(memByRef\144\160\160B@@@\176(pushBack\144\160\160B@@\144\180B\160\176\001\004\148!x@\160\176\001\004\149\"xs@@\174\151\176\181$push\160\0042\160\0043@\197$push@@@\160\144\004\r\160\144\004\018@\176\192\004Uw\001\b\159\001\b\161\192\004Vw\001\b\159\001\b\180@\004T\176)foldRight\144\160\160C@@@\176-filterInPlace\144\160\160B@@@A",
204201
(* Nativeint *)"\132\149\166\190\000\000\001\217\000\000\000\131\000\000\001\162\000\000\001\145\160\b\000\000 \000\176#abs\144\160\160A@@@\176$pred\144\160\160A@@\144\180A\160\176\001\004\002!n@@\151\176\b\000\000\004\018@\160\144\004\007\160\146\151\018_n\000\001\000\000\000\001@\176\1927stdlib-406/nativeint.mlm\001\t\227\001\t\240\192\004\002m\001\t\227\001\t\248@\176$succ\144\160\160A@@\144\180A\160\176\001\004\000!n@@\151\176\b\000\000\004\017@\160\144\004\007\160\146\151\018_n\000\001\000\000\000\001@\176\192\004\023l\001\t\205\001\t\218\192\004\024l\001\t\205\001\t\226@\176%equal\144\160\160B@@@\176&lognot\144\160\160A@@\144\180A\160\176\001\004\t!n@@\151\176\b\000\000\004\024@\160\144\004\007\160\146\151\018_n\000\001\255\255\255\255@\176\192\0042x\001\011\005\001\011\020\192\0043x\001\011\005\001\011\"@\176'compare\144\160\160B@@\144\180B\160\176\001\004\018!x@\160\176\001\004\019!y@@\151\176\1486caml_nativeint_compare\160\144\004\011\160\144\004\n@\176\192\004J\000F\001\012i\001\012\133\192\004K\000F\001\012i\001\012\155@\176)to_string\144\160\160A@@\144\180A\160\176\001\004\012!n@@\151\176\1485caml_nativeint_format\160\146\146\"%d\160\144\004\012@\176\192\004a{\001\011n\001\011\128\192\004b{\001\011n\001\011\141@\176-of_string_opt\144\160\160A@@@A",
205202
(* Node_path *)"\132\149\166\190\000\000\000\003\000\000\000\001\000\000\000\003\000\000\000\003\160\128A",
206-
(* Spacetime *)"\132\149\166\190\000\000\000i\000\000\000\028\000\000\000\\\000\000\000U\160\192\176&Series\145\176\160\160A@@\160\160C@@\160\160B@@@\176'enabled\144@\144\146C\176(Snapshot\145\144\160\160B@@@\176\t\"save_event_for_automatic_snapshots\144\160\160A@@@A",
207203
(* StdLabels *)"\132\149\166\190\000\000\000\003\000\000\000\001\000\000\000\003\000\000\000\003\160\128A",
208204
(* Belt_Array *)"\132\149\166\190\000\000\004i\000\000\001L\000\000\004K\000\000\004\000\160\b\000\001\b\000\176\"eq\144\160\160C@@@\176#cmp\144\160\160C@@@\176#eqU\144\160\160C@@@\176#get\144\160\160B@@@\176#map\144\160\160B@@@\176#set\144\160\160C@@@\176#zip\144\160\160B@@@\176$blit\144\160\160E@@@\176$cmpU\144\160\160C@@@\176$fill\144\160\160D@@@\176$keep\144\160\160B@@@\176$make\144\160\160B@@@\176$mapU\144\160\160B@@@\176$some\144\160\160B@@@\176%every\144\160\160B@@@\176%getBy\144\160\160B@@@\176%keepU\144\160\160B@@@\176%range\144\160\160B@@@\176%slice\144\160\160C@@@\176%some2\144\160\160C@@@\176%someU\144\160\160B@@@\176%unzip\144\160\160A@@@\176%zipBy\144\160\160C@@@\176&concat\144\160\160B@@@\176&every2\144\160\160C@@@\176&everyU\144\160\160B@@@\176&getByU\144\160\160B@@@\176&getExn\144\160\160B@@@\176&makeBy\144\160\160B@@@\176&reduce\144\160\160C@@@\176&setExn\144\160\160C@@@\176&some2U\144\160\160C@@@\176&zipByU\144\160\160C@@@\176'every2U\144\160\160C@@@\176'forEach\144\160\160B@@@\176'keepMap\144\160\160B@@@\176'makeByU\144\160\160B@@@\176'rangeBy\144\160\160C@@@\176'reduceU\144\160\160C@@@\176'reverse\144\160\160A@@@\176'shuffle\144\160\160A@@@\176(forEachU\144\160\160B@@@\176(keepMapU\144\160\160B@@@\176)partition\144\160\160B@@@\176*blitUnsafe\144\160\160E@@@\176*concatMany\144\160\160A@@@\176*getIndexBy\144\160\160B@@@\176*partitionU\144\160\160B@@@\176*sliceToEnd\144\160\160B@@@\176+getIndexByU\144\160\160B@@@\176,mapWithIndex\144\160\160B@@@\176-keepWithIndex\144\160\160B@@@\176-mapWithIndexU\144\160\160B@@@\176-reduceReverse\144\160\160C@@@\176.keepWithIndexU\144\160\160B@@@\176.reduceReverse2\144\160\160D@@@\176.reduceReverseU\144\160\160C@@@\176.reverseInPlace\144\160\160A@@@\176.shuffleInPlace\144\160\160A@@@\176/reduceReverse2U\144\160\160D@@@\176/reduceWithIndex\144\160\160C@@@\1760forEachWithIndex\144\160\160B@@@\1760makeByAndShuffle\144\160\160B@@@\1760reduceWithIndexU\144\160\160C@@@\1761forEachWithIndexU\144\160\160B@@@\1761makeByAndShuffleU\144\160\160B@@@A",
209205
(* Belt_Float *)"\132\149\166\190\000\000\000\022\000\000\000\007\000\000\000\021\000\000\000\020\160\144\176*fromString\144\160\160A@@@A",

jscomp/runtime/caml_array.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ let caml_array_concat (l : 'a array list) : 'a array =
6565
fill result 0 l ;
6666
result
6767

68-
let caml_array_set xs index newval =
68+
let set xs index newval =
6969
if index <0 || index >= Caml_array_extern.length xs
7070
then raise (Invalid_argument "index out of bounds")
7171
else xs.!( index)<- newval
7272

73-
let caml_array_get xs index =
73+
let get xs index =
7474
if index <0 || index >= Caml_array_extern.length xs then
7575
raise (Invalid_argument "index out of bounds")
7676
else xs.!( index)

jscomp/runtime/caml_array.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ val caml_make_float_vect : int -> float array
3434

3535
val caml_array_blit : 'a array -> int -> 'a array -> int -> int -> unit
3636

37-
val caml_array_get: 'a array -> int -> 'a
37+
val get: 'a array -> int -> 'a
3838

39-
val caml_array_set: 'a array -> int -> 'a -> unit
39+
val set: 'a array -> int -> 'a -> unit

jscomp/runtime/caml_bytes.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,14 @@ let caml_bytes_equal (s1 : bytes) (s2 : bytes) : bool =
193193
len1 = len2 &&
194194
caml_bytes_equal_aux s1 s2 0 len1
195195

196+
let caml_bytes_greaterthan (s1 : bytes) s2 =
197+
caml_bytes_compare s1 s2 > 0
198+
199+
let caml_bytes_greaterequal (s1 : bytes) s2 =
200+
caml_bytes_compare s1 s2 >= 0
201+
202+
let caml_bytes_lessthan (s1 : bytes) s2 =
203+
caml_bytes_compare s1 s2 < 0
204+
205+
let caml_bytes_lessequal (s1 : bytes) s2 =
206+
caml_bytes_compare s1 s2 <= 0

jscomp/runtime/caml_bytes.mli

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,23 @@ val caml_blit_string :
4141
int ->
4242
int ->
4343
unit
44+
4445
val bytes_of_string : string -> bytes
45-
val caml_bytes_compare: bytes -> bytes -> int
46-
val caml_bytes_equal : bytes -> bytes -> bool
46+
47+
val caml_bytes_compare:
48+
bytes -> bytes -> int
49+
50+
val caml_bytes_greaterthan:
51+
bytes -> bytes -> bool
52+
53+
val caml_bytes_greaterequal:
54+
bytes -> bytes -> bool
55+
56+
val caml_bytes_lessthan:
57+
bytes -> bytes -> bool
58+
59+
val caml_bytes_lessequal:
60+
bytes -> bytes -> bool
61+
62+
val caml_bytes_equal :
63+
bytes -> bytes -> bool

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

0 commit comments

Comments
 (0)