Skip to content

Commit 9e1714c

Browse files
committed
Merge pull request #431 from bloomberg/ppx_global_config
[refactoring] clean up arity which does not depend on type info anymore
2 parents 5aa9826 + 9e704c5 commit 9e1714c

15 files changed

+482
-345
lines changed

jscomp/js_dump.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ and
643643
pp_string f (* ~utf:(kind = `Utf8) *) ~quote s; cxt
644644
| Raw_js_code (s,info) ->
645645
begin match info with
646-
| Exp _ ->
646+
| Exp ->
647647
P.string f "(";
648648
P.string f s ;
649649
P.string f ")";
@@ -1147,7 +1147,7 @@ and statement_desc top cxt f (s : J.statement_desc) : Ext_pp_scope.t =
11471147
match e.expression_desc with
11481148
| Call ({expression_desc = Fun _; },_,_) -> true
11491149
| Caml_uninitialized_obj _
1150-
| Raw_js_code (_, Exp _)
1150+
| Raw_js_code (_, Exp)
11511151
| Fun _ | Object _ -> true
11521152
| Raw_js_code (_,Stmt)
11531153
| Caml_block_set_tag _

jscomp/js_op.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ type length_object =
247247
| Caml_block
248248

249249
type code_info =
250-
| Exp of int option
250+
| Exp (* of int option *)
251251
| Stmt
252252
(** TODO: define constant - for better constant folding *)
253253
(* type constant = *)

jscomp/lam_compile_external_call.ml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
module E = Js_exp_make
3333

34-
open Parsetree_util
34+
3535

3636
type external_module_name =
3737
| Single of string
@@ -141,7 +141,7 @@ let handle_attributes ({prim_attributes ; prim_name} as _prim : prim ) : Locati
141141
]}
142142
*)
143143
->
144-
begin match is_single_string pay_load with
144+
begin match Ast_payload.is_single_string pay_load with
145145
| Some name ->
146146
js_val := `Value name
147147
| None ->
@@ -152,7 +152,7 @@ let handle_attributes ({prim_attributes ; prim_name} as _prim : prim ) : Locati
152152
(* {[ [@@bs.val_of_module]]}
153153
*)
154154
->
155-
begin match is_single_string pay_load with
155+
begin match Ast_payload.is_single_string pay_load with
156156
| Some name ->
157157
js_val_of_module := `Value(Bind (name, prim_name))
158158
| None ->
@@ -164,19 +164,19 @@ let handle_attributes ({prim_attributes ; prim_name} as _prim : prim ) : Locati
164164

165165
|"bs.send"
166166
->
167-
begin match is_single_string pay_load with
167+
begin match Ast_payload.is_single_string pay_load with
168168
| Some name -> js_send := `Value name
169169
| None -> js_send := `Value _prim.prim_name
170170
end
171171
| "bs.set"
172172
->
173-
begin match is_single_string pay_load with
173+
begin match Ast_payload.is_single_string pay_load with
174174
| Some name -> js_set := `Value name
175175
| None -> js_set := `Value _prim.prim_name
176176
end
177177
| "bs.get"
178178
->
179-
begin match is_single_string pay_load with
179+
begin match Ast_payload.is_single_string pay_load with
180180
| Some name -> js_get := `Value name
181181
| None -> js_get := `Value _prim.prim_name
182182
end
@@ -186,20 +186,20 @@ let handle_attributes ({prim_attributes ; prim_name} as _prim : prim ) : Locati
186186
[@@bs.call "xx"] [@@bs.call]
187187
*)
188188
->
189-
begin match is_single_string pay_load with
189+
begin match Ast_payload.is_single_string pay_load with
190190
| Some name -> call_name := Some (x.loc, name)
191191
| None -> call_name := Some(x.loc, _prim.prim_name)
192192
end
193193
| "bs.module" ->
194-
begin match is_string_or_strings pay_load with
194+
begin match Ast_payload.is_string_or_strings pay_load with
195195
| `Single name -> external_module_name:= Some (Single name)
196196
| `Some [a;b] -> external_module_name := Some (Bind (a,b))
197197
| `Some _ -> ()
198198
| `None -> () (* should emit a warning instead *)
199199
end
200200

201201
| "bs.new" ->
202-
begin match is_single_string pay_load with
202+
begin match Ast_payload.is_single_string pay_load with
203203
| Some x -> js_new := Some x
204204
| None -> js_new := Some _prim.prim_name
205205
end

jscomp/lam_dispatch_primitive.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ let query (prim : Lam_compile_env.primitive_description)
940940
->
941941
begin match args with
942942
| [ { expression_desc = Str (_,s )}] ->
943-
E.raw_js_code (Exp (Parsetree_util.has_arity prim.prim_attributes)) s
943+
E.raw_js_code Exp s
944944
| _ ->
945945
Ext_log.err __LOC__
946946
"JS.unsafe_js_expr is applied to an non literal string in %s"

jscomp/lam_stats_util.ml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,16 @@ let rec get_arity
9292

9393
end
9494
| Llet(_,_,_, l ) -> get_arity meta l
95-
| Lprim (Pccall {prim_name = "js_pure_expr"; prim_attributes},
96-
[Lconst (Const_base (Const_string (_str,_)))])
97-
->
98-
(* Ext_log.dwarn __LOC__ "called %s %d" str (List.length prim_attributes ); *)
99-
begin match Parsetree_util.has_arity prim_attributes with
100-
| Some arity ->
101-
(* Ext_log.dwarn __LOC__ "arity %d" arity; *)
102-
Determin(false, [arity, None], false)
103-
| None -> NA
104-
end
95+
(* | Lprim (Pccall {prim_name = "js_pure_expr"; prim_attributes}, *)
96+
(* [Lconst (Const_base (Const_string (_str,_)))]) *)
97+
(* -> *)
98+
(* (\* Ext_log.dwarn __LOC__ "called %s %d" str (List.length prim_attributes ); *\) *)
99+
(* begin match Parsetree_util.has_arity prim_attributes with *)
100+
(* | Some arity -> *)
101+
(* (\* Ext_log.dwarn __LOC__ "arity %d" arity; *\) *)
102+
(* Determin(false, [arity, None], false) *)
103+
(* | None -> NA *)
104+
(* end *)
105105
| Lprim (Pfield (n,_), [Lprim(Pgetglobal id,[])]) ->
106106
Lam_compile_env.find_and_add_if_not_exist (id, n) meta.env
107107
~not_found:(fun _ -> assert false)

jscomp/syntax/ast_comb.ml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
2+
*
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU Lesser General Public License as published by
5+
* the Free Software Foundation, either version 3 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* In addition to the permissions granted to you by the LGPL, you may combine
9+
* or link a "work that uses the Library" with a publicly distributed version
10+
* of this file to produce a combined library or application, then distribute
11+
* that combined work under the terms of your choosing, with no requirement
12+
* to comply with the obligations normally placed on you by section 4 of the
13+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
14+
* should you choose to use a later version).
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Lesser General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Lesser General Public License
22+
* along with this program; if not, write to the Free Software
23+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
24+
25+
let create_local_external loc
26+
?(pval_attributes=[])
27+
~pval_prim
28+
~pval_type
29+
?(local_module_name = "J")
30+
?(local_fun_name = "unsafe_expr")
31+
args
32+
: Parsetree.expression_desc =
33+
Pexp_letmodule
34+
({txt = local_module_name; loc},
35+
{pmod_desc =
36+
Pmod_structure
37+
[{pstr_desc =
38+
Pstr_primitive
39+
{pval_name = {txt = local_fun_name; loc};
40+
pval_type ;
41+
pval_loc = loc;
42+
pval_prim = [pval_prim];
43+
pval_attributes };
44+
pstr_loc = loc;
45+
}];
46+
pmod_loc = loc;
47+
pmod_attributes = []},
48+
{
49+
pexp_desc =
50+
Pexp_apply
51+
(({pexp_desc = Pexp_ident {txt = Ldot (Lident local_module_name, local_fun_name);
52+
loc};
53+
pexp_attributes = [] ;
54+
pexp_loc = loc} : Parsetree.expression),
55+
args);
56+
pexp_attributes = [];
57+
pexp_loc = loc
58+
})
59+
60+
open Ast_helper
61+
62+
let exp_apply_no_label ?loc ?attrs a b =
63+
Exp.apply ?loc ?attrs a (List.map (fun x -> "", x) b)
64+
65+
let fun_no_label ?loc ?attrs pat body =
66+
Exp.fun_ ?loc ?attrs "" None pat body
67+
68+
let arrow_no_label ?loc ?attrs b c =
69+
Typ.arrow ?loc ?attrs "" b c
70+
71+
let discard_exp_as_unit loc e =
72+
exp_apply_no_label ~loc
73+
(Exp.ident ~loc {txt = Ast_literal.Lid.ignore_id; loc})
74+
[Exp.constraint_ ~loc e
75+
(Ast_literal.type_unit ~loc ())]

jscomp/syntax/ast_comb.mli

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
2+
*
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU Lesser General Public License as published by
5+
* the Free Software Foundation, either version 3 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* In addition to the permissions granted to you by the LGPL, you may combine
9+
* or link a "work that uses the Library" with a publicly distributed version
10+
* of this file to produce a combined library or application, then distribute
11+
* that combined work under the terms of your choosing, with no requirement
12+
* to comply with the obligations normally placed on you by section 4 of the
13+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
14+
* should you choose to use a later version).
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Lesser General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Lesser General Public License
22+
* along with this program; if not, write to the Free Software
23+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
24+
25+
val create_local_external : Location.t ->
26+
?pval_attributes:Parsetree.attributes ->
27+
pval_prim:string ->
28+
pval_type:Parsetree.core_type ->
29+
?local_module_name:string ->
30+
?local_fun_name:string ->
31+
(Asttypes.label * Parsetree.expression) list -> Parsetree.expression_desc
32+
33+
val exp_apply_no_label :
34+
?loc:Location.t ->
35+
?attrs:Parsetree.attributes ->
36+
Parsetree.expression -> Parsetree.expression list -> Parsetree.expression
37+
38+
val fun_no_label :
39+
?loc:Location.t ->
40+
?attrs:Parsetree.attributes ->
41+
Parsetree.pattern -> Parsetree.expression -> Parsetree.expression
42+
43+
val arrow_no_label :
44+
?loc:Location.t ->
45+
?attrs:Parsetree.attributes ->
46+
Parsetree.core_type -> Parsetree.core_type -> Parsetree.core_type
47+
48+
(* note we first declare its type is [unit],
49+
then [ignore] it, [ignore] is necessary since
50+
the js value maybe not be of type [unit] and
51+
we can use [unit] value (though very little chance)
52+
sometimes
53+
*)
54+
val discard_exp_as_unit :
55+
Location.t -> Parsetree.expression -> Parsetree.expression

jscomp/syntax/ast_lift.ml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
2+
*
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU Lesser General Public License as published by
5+
* the Free Software Foundation, either version 3 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* In addition to the permissions granted to you by the LGPL, you may combine
9+
* or link a "work that uses the Library" with a publicly distributed version
10+
* of this file to produce a combined library or application, then distribute
11+
* that combined work under the terms of your choosing, with no requirement
12+
* to comply with the obligations normally placed on you by section 4 of the
13+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
14+
* should you choose to use a later version).
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Lesser General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Lesser General Public License
22+
* along with this program; if not, write to the Free Software
23+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
24+
25+
let int ?loc ?attrs x =
26+
Ast_helper.Exp.constant ?loc ?attrs (Const_int x)

jscomp/syntax/ast_lift.mli

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
2+
*
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU Lesser General Public License as published by
5+
* the Free Software Foundation, either version 3 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* In addition to the permissions granted to you by the LGPL, you may combine
9+
* or link a "work that uses the Library" with a publicly distributed version
10+
* of this file to produce a combined library or application, then distribute
11+
* that combined work under the terms of your choosing, with no requirement
12+
* to comply with the obligations normally placed on you by section 4 of the
13+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
14+
* should you choose to use a later version).
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Lesser General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Lesser General Public License
22+
* along with this program; if not, write to the Free Software
23+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
24+
25+
val int :
26+
?loc:Location.t ->
27+
?attrs:Parsetree.attributes -> int -> Parsetree.expression

0 commit comments

Comments
 (0)