File tree Expand file tree Collapse file tree 5 files changed +26
-19
lines changed Expand file tree Collapse file tree 5 files changed +26
-19
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,7 @@ let rec no_side_effects (lam : Lam.t) : bool =
56
56
(* non-observable side effect *)
57
57
| " caml_sys_get_config"
58
58
| " caml_sys_get_argv" (* should be fine *)
59
+ | " caml_string_repeat"
59
60
| " caml_make_vect"
60
61
| " caml_create_bytes"
61
62
| " caml_obj_dup"
Original file line number Diff line number Diff line change @@ -380,6 +380,20 @@ let translate loc (prim_name : string)
380
380
E. string_comp Ge e0 e1
381
381
| _ -> assert false
382
382
end
383
+ | " caml_string_repeat"
384
+ ->
385
+ begin match args with
386
+ | [ n ; {expression_desc = Number (Int {i})} ] ->
387
+ let str = (String. make 1 (Char. chr (Int32. to_int i))) in
388
+ begin match n.expression_desc with
389
+ | Number (Int {i = 1l } ) -> E. str str
390
+ | _ ->
391
+ E. call (E. dot (E. str str) " repeat" ) [n]
392
+ ~info: Js_call_info. builtin_runtime_call
393
+ end
394
+ | _ ->
395
+ E. runtime_call Js_runtime_modules. string " make" args
396
+ end
383
397
| " caml_string_greaterthan"
384
398
->
385
399
begin match args with
@@ -475,7 +489,7 @@ let translate loc (prim_name : string)
475
489
| _ -> assert false
476
490
end
477
491
| " caml_create_bytes"
478
- | "caml_create_string" ->
492
+ ->
479
493
(* Bytes.create *)
480
494
(* Note that for invalid range, JS raise an Exception RangeError,
481
495
here in OCaml it's [Invalid_argument], we have to preserve this semantics.
Original file line number Diff line number Diff line change @@ -36,18 +36,8 @@ let get s i=
36
36
raise (Invalid_argument " index out of bounds" )
37
37
else Caml_string_extern. unsafe_get s i
38
38
39
- (* let caml_string_get16 s i =
40
- Caml_char.code (Caml_string_extern.unsafe_get s i) + Caml_char.code (Caml_string_extern.unsafe_get s (i+1)) lsl 8
41
-
42
- let caml_string_get32 s i =
43
- Caml_char.code (Caml_string_extern.unsafe_get s i) +
44
- Caml_char.code (Caml_string_extern.unsafe_get s (i+1)) lsl 8 +
45
- Caml_char.code (Caml_string_extern.unsafe_get s (i+2)) lsl 16 +
46
- Caml_char.code (Caml_string_extern.unsafe_get s (i+3)) lsl 24 *)
47
-
48
-
49
- (* let get s i =
50
- if i < 0 || i >= Caml_string_extern.length s then
51
- raise (Invalid_argument "index out of bounds")
52
- else Caml_string_extern.unsafe_get s i
53
- *)
39
+ let make n (ch : char ) : string =
40
+ (Caml_string_extern. of_char ch)
41
+ |. Caml_string_extern. repeat n
42
+
43
+
Original file line number Diff line number Diff line change 24
24
25
25
26
26
val get : string -> int -> char
27
+
28
+ val make : int -> char -> string
Original file line number Diff line number Diff line change @@ -36,9 +36,9 @@ module B = Bytes
36
36
37
37
let bts = B. unsafe_to_string
38
38
let bos = B. unsafe_of_string
39
- (* -FIXME: replaced by Belt.String.repeat *)
40
- let make n c =
41
- B. make n c |> bts
39
+
40
+ external make : int -> char -> string = " caml_string_repeat "
41
+
42
42
let init n f =
43
43
B. init n f |> bts
44
44
let copy s =
You can’t perform that action at this time.
0 commit comments