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
18 changes: 3 additions & 15 deletions compiler/core/j.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@

type mutable_flag = Js_op.mutable_flag
type binop = Js_op.binop
type int_op = Js_op.int_op
type kind = Js_op.kind
type property = Js_op.property
type number = Js_op.number
type ident_info = Js_op.ident_info
Expand Down Expand Up @@ -74,7 +72,6 @@ and exception_ident = ident
and for_ident = ident
and for_direction = Js_op.direction_flag
and property_map = (property_name * expression) list
and length_object = Js_op.length_object
and delim = External_arg_spec.delim = DNone | DStarJ | DNoQuotes | DBackQuotes

and record_rest_field = {
Expand All @@ -83,7 +80,7 @@ and record_rest_field = {
}

and expression_desc =
| Length of expression * length_object
| Length of expression
| Is_null_or_undefined of expression (** where we use a trick [== null ] *)
| String_append of expression * expression
| Bool of bool (* js true/false*)
Expand All @@ -98,9 +95,6 @@ and expression_desc =
| Seq of expression * expression
| Cond of expression * expression * expression
| Bin of binop * expression * expression
(* [int_op] will guarantee return [int32] bits
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators *)
(* | Int32_bin of int_op * expression * expression *)
| FlatCall of expression * expression
(* f.apply(null,args) -- Fully applied guaranteed
TODO: once we know args's shape --
Expand Down Expand Up @@ -133,7 +127,7 @@ and expression_desc =
All exported declarations have to be OCaml identifiers
2. Javascript dot (need to be preserved/or using quote)
*)
| New of expression * expression list option (* TODO: option remove *)
| New of expression * expression list
| Var of vident
| Fun of {
is_method: bool;
Expand All @@ -151,15 +145,13 @@ and expression_desc =
| Raw_js_code of Js_raw_info.t
(* literally raw JS code
*)
| Array of expression list * mutable_flag
| Array of expression list
| Optional_block of expression * bool
(* [true] means [identity] *)
| Caml_block of expression list * mutable_flag * expression * tag_info
(* The third argument is [tag] , forth is [tag_info] *)
(* | Caml_uninitialized_obj of expression * expression *)
(* [tag] and [size] tailed for [Obj.new_block] *)
| Caml_block_tag of expression * string (* e.tag *)
(* | Caml_block_set_length of expression * expression *)
(* It will just fetch tag, to make it safe, when creating it,
we need apply "|0", we don't do it in the
last step since "|0" can potentially be optimized
Expand Down Expand Up @@ -334,17 +326,13 @@ and deps_program = {
int_clause;
string_clause;
for_direction;
(* exception_ident; *)
for_direction;
expression_desc;
statement_desc;
for_ident_expression;
label;
finish_ident_expression;
property_map;
length_object;
record_rest_field;
(* for_ident; *)
required_modules;
case_clause;
|];
Expand Down
6 changes: 3 additions & 3 deletions compiler/core/js_analyzer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ let rec no_side_effect_expression_desc (x : J.expression_desc) =
no_side_effect a && no_side_effect b
| Is_null_or_undefined b -> no_side_effect b
| Str _ -> true
| Array (xs, _mutable_flag) | Caml_block (xs, _mutable_flag, _, _) ->
| Array xs | Caml_block (xs, _, _, _) ->
(* create [immutable] block,
does not really mean that this opreation itself is [pure].

Expand All @@ -119,7 +119,7 @@ let rec no_side_effect_expression_desc (x : J.expression_desc) =
| None -> true)
&& Ext_list.for_all_snd kvs no_side_effect
| String_append (a, b) | Seq (a, b) -> no_side_effect a && no_side_effect b
| Length (e, _) | Caml_block_tag (e, _) | Typeof e -> no_side_effect e
| Length e | Caml_block_tag (e, _) | Typeof e -> no_side_effect e
| Bin (op, a, b) -> op <> Eq && no_side_effect a && no_side_effect b
| Tagged_template (call_expr, strings, values) ->
no_side_effect call_expr
Expand Down Expand Up @@ -311,7 +311,7 @@ let rev_toplevel_flatten block =
| Array_index (a,b) -> is_constant a && is_constant b
| Str (b,_) -> b
| Number _ -> true (* Can be refined later *)
| Array (xs,_mutable_flag) -> Ext_list.for_all xs is_constant
| Array xs -> Ext_list.for_all xs is_constant
| Caml_block(xs, Immutable, tag, _)
-> Ext_list.for_all xs is_constant && is_constant tag
| Bin (_op, a, b) ->
Expand Down
29 changes: 0 additions & 29 deletions compiler/core/js_arr.ml

This file was deleted.

27 changes: 0 additions & 27 deletions compiler/core/js_arr.mli

This file was deleted.

27 changes: 11 additions & 16 deletions compiler/core/js_dump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ let raw_snippet_exp_simple_enough (s : string) =
*)
let rec exp_need_paren ?(arrow = false) (e : J.expression) =
match e.expression_desc with
(* | Caml_uninitialized_obj _ *)
| Call ({expression_desc = Raw_js_code _}, _, _) -> true
| Raw_js_code {code_info = Exp _}
| Fun _
Expand Down Expand Up @@ -754,8 +753,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
P.paren_group f 0 (fun _ -> arguments cxt f (e :: el)))
else (
Curry_gen.pp_app_any f;
P.paren_group f 0 (fun _ ->
arguments cxt f [e; E.array Mutable el]))))
P.paren_group f 0 (fun _ -> arguments cxt f [e; E.array el]))))
| FlatCall (e, el) ->
P.group f 0 (fun _ ->
let cxt = expression ~level:15 cxt f e in
Expand Down Expand Up @@ -939,7 +937,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
P.string f "+";
P.space f;
expression ~level:rght cxt f e2)
| Array (el, _) -> (
| Array el -> (
(* TODO: simplify for singleton list *)
match el with
| [] | [_] -> P.bracket_group f 1 (fun _ -> array_element_list cxt f el)
Expand All @@ -955,11 +953,11 @@ and expression_desc cxt ~(level : int) f x : cxt =
Ext_list.map_combine fields el (fun x ->
Js_op.Lit (Ext_ident.convert x)) ))
(*name convention of Record is slight different from modules*)
| Caml_block (el, mutable_flag, _, Blk_record {fields}) ->
| Caml_block (el, _, _, Blk_record {fields}) ->
if
Array.length fields <> 0
&& Ext_array.for_alli fields (fun i (v, _) -> string_of_int i = v)
then expression_desc cxt ~level f (Array (el, mutable_flag))
then expression_desc cxt ~level f (Array el)
else
let fields =
Ext_list.array_list_filter_map fields el (fun (f, opt) x ->
Expand Down Expand Up @@ -1050,8 +1048,8 @@ and expression_desc cxt ~(level : int) f x : cxt =
| Caml_block (_, _, _, (Blk_module_export _ | Blk_some | Blk_some_not_nested))
->
assert false
| Caml_block (el, mutable_flag, _tag, Blk_tuple) ->
expression_desc cxt ~level f (Array (el, mutable_flag))
| Caml_block (el, _, _tag, Blk_tuple) ->
expression_desc cxt ~level f (Array el)
| Caml_block_tag (e, tag) ->
P.group f 1 (fun _ ->
let cxt = expression ~level:15 cxt f e in
Expand All @@ -1072,23 +1070,20 @@ and expression_desc cxt ~(level : int) f x : cxt =
refer and export
*)
cxt)
| Length (e, _) ->
| Length e ->
(*Todo: check parens *)
P.cond_paren_group f (level > 15) (fun _ ->
let cxt = expression ~level:15 cxt f e in
P.string f L.dot;
P.string f L.length;
cxt)
| New (e, el) ->
| New (e, args) ->
P.cond_paren_group f (level > 15) (fun _ ->
P.group f 0 (fun _ ->
P.string f L.new_;
P.space f;
let cxt = expression ~level:16 cxt f e in
P.paren_group f 0 (fun _ ->
match el with
| Some el -> arguments cxt f el
| None -> cxt)))
P.paren_group f 0 (fun _ -> arguments cxt f args)))
| Cond (e, e1, e2) ->
let action () =
let cxt = expression ~level:3 cxt f e in
Expand Down Expand Up @@ -1200,8 +1195,8 @@ and print_jsx cxt ?(spread_props : J.expression option)
if n = "children" then
if fn_name = "jsxs" then
match e.J.expression_desc with
| J.Array (xs, _)
| J.Optional_block ({expression_desc = J.Array (xs, _)}, _) ->
| J.Array xs | J.Optional_block ({expression_desc = J.Array xs}, _)
->
Some xs
| _ -> Some [e]
else Some [e]
Expand Down
Loading
Loading