Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions jscomp/all.depend
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ core/js_of_lam_array.cmi : core/j.cmx
core/js_of_lam_block.cmi : core/js_op.cmx core/j.cmx
core/js_of_lam_string.cmi : core/j.cmx
core/js_of_lam_tuple.cmi : core/j.cmx
core/js_of_lam_record.cmi : core/js_exp_make.cmi core/j.cmx
core/js_of_lam_record.cmi : core/j.cmx
core/js_of_lam_float_record.cmi : core/j.cmx
core/js_arr.cmi : core/j.cmx
core/lam_compile_const.cmi : core/lam.cmi core/j.cmx \
Expand Down Expand Up @@ -645,12 +645,11 @@ core/lam_compile_external_obj.cmx : core/lam_compile_external_call.cmx \
core/lam_compile_primitive.cmx : core/lam_print.cmx \
core/lam_dispatch_primitive.cmx core/lam_compile_external_call.cmx \
core/lam_compile_context.cmx core/lam.cmx core/js_runtime_modules.cmx \
core/js_op_util.cmx core/js_of_lam_string.cmx core/js_of_lam_record.cmx \
core/js_of_lam_option.cmx core/js_of_lam_float_record.cmx \
core/js_of_lam_exception.cmx core/js_of_lam_block.cmx \
core/js_of_lam_array.cmx core/js_long.cmx core/js_exp_make.cmx \
common/js_config.cmx core/j.cmx common/bs_warnings.cmx \
core/lam_compile_primitive.cmi
core/js_op_util.cmx core/js_of_lam_string.cmx core/js_of_lam_option.cmx \
core/js_of_lam_float_record.cmx core/js_of_lam_exception.cmx \
core/js_of_lam_block.cmx core/js_of_lam_array.cmx core/js_long.cmx \
core/js_exp_make.cmx common/js_config.cmx core/j.cmx \
common/bs_warnings.cmx core/lam_compile_primitive.cmi
core/lam_compile.cmx : ext/literals.cmx core/lam_util.cmx \
common/lam_methname.cmx core/lam_exit_code.cmx \
core/lam_eta_conversion.cmx core/lam_compile_primitive.cmx \
Expand Down
2 changes: 0 additions & 2 deletions jscomp/core/j.ml
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ and expression_desc =
| Char_to_int of expression
| Is_null_or_undefined of expression
(** where we use a trick [== null ] *)
| Array_copy of expression (* shallow copy, like [x.slice] *)

| String_append of expression * expression
| Bool of bool (* js true/false*)
(* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence
Expand Down
2 changes: 0 additions & 2 deletions jscomp/core/js_analyzer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ let rec no_side_effect_expression_desc (x : J.expression_desc) =
| Bin (op, a, b) ->
op <> Eq && no_side_effect a && no_side_effect b
| Math _
| Array_copy _
| Js_not _
| Cond _

Expand Down Expand Up @@ -254,7 +253,6 @@ let rec eq_expression
| Char_of_int _
| Char_to_int _
| Is_null_or_undefined _
| Array_copy _
| String_append _
| Typeof _
| Js_not _
Expand Down
9 changes: 0 additions & 9 deletions jscomp/core/js_dump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -494,14 +494,6 @@ and
expression 1 cxt f el
)
)

| Array_copy e ->
P.group f 1 (fun _ ->
let cxt = expression 15 cxt f e in
P.string f ".slice";
P.string f "()" ;
cxt
)
| Char_to_int e ->
begin match e.expression_desc with
| String_access (a,b) ->
Expand Down Expand Up @@ -1039,7 +1031,6 @@ and statement_desc top cxt f (s : J.statement_desc) : Ext_pp_scope.t =
| Length _
| Caml_block_set_length _
| Call _
| Array_copy _
| Caml_block_tag _
| Seq _
| Dot _
Expand Down
2 changes: 0 additions & 2 deletions jscomp/core/js_exp_make.ml
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,6 @@ let char_to_int ?comment (v : t) : t =
| _ -> {comment; expression_desc = Char_to_int v }


let array_copy ?comment e : t =
{ comment ; expression_desc = Array_copy e}

let rec string_append ?comment (e : t) (el : t) : t =
match e.expression_desc , el.expression_desc with
Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/js_exp_make.mli
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ val function_length : unary_op
val char_of_int : unary_op

val char_to_int : unary_op
val array_copy : unary_op

val string_append : binary_op
(**
When in ES6 mode, we can use Symbol to guarantee its uniquess,
Expand Down
4 changes: 1 addition & 3 deletions jscomp/core/js_fold.ml
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ class virtual fold =
Qualified (_, Runtime, Some "caml_int_compare")
]}
*)
(** where we use a trick [== null ] *)
(* shallow copy, like [x.slice] *) (* js true/false*)
(** where we use a trick [== null ] *) (* js true/false*)
(* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence
[typeof] is an operator
*)
Expand Down Expand Up @@ -320,7 +319,6 @@ class virtual fold =
| Char_of_int _x -> let o = o#expression _x in o
| Char_to_int _x -> let o = o#expression _x in o
| Is_null_or_undefined _x -> let o = o#expression _x in o
| Array_copy _x -> let o = o#expression _x in o
| String_append (_x, _x_i1) ->
let o = o#expression _x in let o = o#expression _x_i1 in o
| Bool _x -> let o = o#bool _x in o
Expand Down
4 changes: 1 addition & 3 deletions jscomp/core/js_map.ml
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ class virtual map =
Qualified (_, Runtime, Some "caml_int_compare")
]}
*)
(** where we use a trick [== null ] *)
(* shallow copy, like [x.slice] *) (* js true/false*)
(** where we use a trick [== null ] *) (* js true/false*)
(* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence
[typeof] is an operator
*)
Expand Down Expand Up @@ -346,7 +345,6 @@ class virtual map =
| Char_to_int _x -> let _x = o#expression _x in Char_to_int _x
| Is_null_or_undefined _x ->
let _x = o#expression _x in Is_null_or_undefined _x
| Array_copy _x -> let _x = o#expression _x in Array_copy _x
| String_append (_x, _x_i1) ->
let _x = o#expression _x in
let _x_i1 = o#expression _x_i1 in String_append (_x, _x_i1)
Expand Down
6 changes: 0 additions & 6 deletions jscomp/core/js_of_lam_record.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,4 @@ let field field_info e i =
| Lambda.Fld_module s
-> E.index ~comment:s e i

(**
used in [Pduprecord]
this is due to we encode record as an array, it is going to change
if we have another encoding
*)
let copy = E.array_copy

1 change: 0 additions & 1 deletion jscomp/core/js_of_lam_record.mli
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,3 @@

val field : Lambda.field_dbg_info -> J.expression -> J.jsint ->J.expression

val copy : Js_exp_make.unary_op
27 changes: 9 additions & 18 deletions jscomp/core/lam_compile_primitive.ml
Original file line number Diff line number Diff line change
Expand Up @@ -675,27 +675,18 @@ let translate loc
| Pctconst ct ->
begin
match ct with
| Big_endian ->
if Sys.big_endian then E.caml_true
else E.caml_false
| Big_endian -> E.bool Sys.big_endian
| Word_size ->
E.small_int Sys.word_size
| Ostype_unix ->
if Sys.unix then E.caml_true else E.caml_false
| Ostype_win32 ->
if Sys.win32 then E.caml_true else E.caml_false
| Ostype_cygwin ->
if Sys.cygwin then E.caml_true else E.caml_false
end
(* | Psetglobal _ -> *)
(* assert false (\* already handled *\) *)
(* assert false *)
| Pduprecord ((Record_regular
| Record_float ),_size) -> (* _size is the length of all_lables*)
begin match args with
| [e] -> Js_of_lam_record.copy e
| _ -> assert false
| Ostype_unix -> E.bool Sys.unix
| Ostype_win32 -> E.bool Sys.win32
| Ostype_cygwin -> E.bool Sys.cygwin
end
| Pduprecord ((Record_regular
| Record_float ),_) ->
(* _size is the length of all_lables*)
(* TODO: In debug mode, need switch to *)
Lam_dispatch_primitive.translate loc "caml_array_dup" args
| Pbigarrayref (unsafe, dimension, kind, layout)
->
(* can be refined to
Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/lam_dispatch_primitive.ml
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ let translate loc (prim_name : string)
and discarded it immediately
This could be canceled
*)
| _ -> E.array_copy a
| _ -> call Js_runtime_modules.array
end
| _ -> assert false
end
Expand Down
10 changes: 3 additions & 7 deletions jscomp/others/belt_Array.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,9 @@ external makeUninitialized : int -> 'a Js.undefined array = "Array" [@@bs.new]
external makeUninitializedUnsafe : int -> 'a array = "Array" [@@bs.new]


let copy a =
let l = length a in
let v = makeUninitializedUnsafe l in
for i = 0 to l - 1 do
setUnsafe v i (getUnsafe a i)
done ;
v
external copy : 'a array -> (_ [@bs.as 0]) -> 'a array =
"slice" [@@bs.send]


let swapUnsafe xs i j =
let tmp = getUnsafe xs i in
Expand Down
2 changes: 1 addition & 1 deletion jscomp/others/belt_Array.mli
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ val slice: 'a array -> offset:int -> len:int -> 'a array
*)


val copy: 'a array -> 'a array
external copy : 'a array -> (_ [@bs.as 0]) -> 'a array = "slice" [@@bs.send]
(** [copy a]

@return a copy of [a], that is, a fresh array
Expand Down
4 changes: 4 additions & 0 deletions jscomp/runtime/caml_array.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ external new_uninitialized : int -> 'a array = "Array" [@@bs.new]
external append : 'a array -> 'a array -> 'a array = "concat" [@@bs.send]


external caml_array_dup : 'a array -> (_ [@bs.as 0]) -> 'a array =
"slice" [@@bs.send]


let caml_array_sub (x : 'a array) (offset : int) (len : int) =
let result = new_uninitialized len in
Expand Down Expand Up @@ -99,3 +102,4 @@ let caml_array_blit a1 i1 a2 i2 len =
for j = len - 1 downto 0 do
a2.(j+i2) <- a1.(j+i1)
done

3 changes: 2 additions & 1 deletion jscomp/runtime/caml_array.mli
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@

external new_uninitialized : int -> 'a array = "Array" [@@bs.new]
external append : 'a array -> 'a array -> 'a array = "concat" [@@bs.send]
(*external make : int -> 'a -> 'a array = "caml_make_vect"*)

val caml_array_dup : 'a array -> 'a array

val caml_array_sub : 'a array -> int -> int -> 'a array

Expand Down
Loading