Skip to content

[refactoring] clean up arity which does not depend on type info anymore #431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 1, 2016
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
4 changes: 2 additions & 2 deletions jscomp/js_dump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ and
pp_string f (* ~utf:(kind = `Utf8) *) ~quote s; cxt
| Raw_js_code (s,info) ->
begin match info with
| Exp _ ->
| Exp ->
P.string f "(";
P.string f s ;
P.string f ")";
Expand Down Expand Up @@ -1147,7 +1147,7 @@ and statement_desc top cxt f (s : J.statement_desc) : Ext_pp_scope.t =
match e.expression_desc with
| Call ({expression_desc = Fun _; },_,_) -> true
| Caml_uninitialized_obj _
| Raw_js_code (_, Exp _)
| Raw_js_code (_, Exp)
| Fun _ | Object _ -> true
| Raw_js_code (_,Stmt)
| Caml_block_set_tag _
Expand Down
2 changes: 1 addition & 1 deletion jscomp/js_op.ml
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ type length_object =
| Caml_block

type code_info =
| Exp of int option
| Exp (* of int option *)
| Stmt
(** TODO: define constant - for better constant folding *)
(* type constant = *)
Expand Down
18 changes: 9 additions & 9 deletions jscomp/lam_compile_external_call.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

module E = Js_exp_make

open Parsetree_util


type external_module_name =
| Single of string
Expand Down Expand Up @@ -141,7 +141,7 @@ let handle_attributes ({prim_attributes ; prim_name} as _prim : prim ) : Locati
]}
*)
->
begin match is_single_string pay_load with
begin match Ast_payload.is_single_string pay_load with
| Some name ->
js_val := `Value name
| None ->
Expand All @@ -152,7 +152,7 @@ let handle_attributes ({prim_attributes ; prim_name} as _prim : prim ) : Locati
(* {[ [@@bs.val_of_module]]}
*)
->
begin match is_single_string pay_load with
begin match Ast_payload.is_single_string pay_load with
| Some name ->
js_val_of_module := `Value(Bind (name, prim_name))
| None ->
Expand All @@ -164,19 +164,19 @@ let handle_attributes ({prim_attributes ; prim_name} as _prim : prim ) : Locati

|"bs.send"
->
begin match is_single_string pay_load with
begin match Ast_payload.is_single_string pay_load with
| Some name -> js_send := `Value name
| None -> js_send := `Value _prim.prim_name
end
| "bs.set"
->
begin match is_single_string pay_load with
begin match Ast_payload.is_single_string pay_load with
| Some name -> js_set := `Value name
| None -> js_set := `Value _prim.prim_name
end
| "bs.get"
->
begin match is_single_string pay_load with
begin match Ast_payload.is_single_string pay_load with
| Some name -> js_get := `Value name
| None -> js_get := `Value _prim.prim_name
end
Expand All @@ -186,20 +186,20 @@ let handle_attributes ({prim_attributes ; prim_name} as _prim : prim ) : Locati
[@@bs.call "xx"] [@@bs.call]
*)
->
begin match is_single_string pay_load with
begin match Ast_payload.is_single_string pay_load with
| Some name -> call_name := Some (x.loc, name)
| None -> call_name := Some(x.loc, _prim.prim_name)
end
| "bs.module" ->
begin match is_string_or_strings pay_load with
begin match Ast_payload.is_string_or_strings pay_load with
| `Single name -> external_module_name:= Some (Single name)
| `Some [a;b] -> external_module_name := Some (Bind (a,b))
| `Some _ -> ()
| `None -> () (* should emit a warning instead *)
end

| "bs.new" ->
begin match is_single_string pay_load with
begin match Ast_payload.is_single_string pay_load with
| Some x -> js_new := Some x
| None -> js_new := Some _prim.prim_name
end
Expand Down
2 changes: 1 addition & 1 deletion jscomp/lam_dispatch_primitive.ml
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ let query (prim : Lam_compile_env.primitive_description)
->
begin match args with
| [ { expression_desc = Str (_,s )}] ->
E.raw_js_code (Exp (Parsetree_util.has_arity prim.prim_attributes)) s
E.raw_js_code Exp s
| _ ->
Ext_log.err __LOC__
"JS.unsafe_js_expr is applied to an non literal string in %s"
Expand Down
20 changes: 10 additions & 10 deletions jscomp/lam_stats_util.ml
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,16 @@ let rec get_arity

end
| Llet(_,_,_, l ) -> get_arity meta l
| Lprim (Pccall {prim_name = "js_pure_expr"; prim_attributes},
[Lconst (Const_base (Const_string (_str,_)))])
->
(* Ext_log.dwarn __LOC__ "called %s %d" str (List.length prim_attributes ); *)
begin match Parsetree_util.has_arity prim_attributes with
| Some arity ->
(* Ext_log.dwarn __LOC__ "arity %d" arity; *)
Determin(false, [arity, None], false)
| None -> NA
end
(* | Lprim (Pccall {prim_name = "js_pure_expr"; prim_attributes}, *)
(* [Lconst (Const_base (Const_string (_str,_)))]) *)
(* -> *)
(* (\* Ext_log.dwarn __LOC__ "called %s %d" str (List.length prim_attributes ); *\) *)
(* begin match Parsetree_util.has_arity prim_attributes with *)
(* | Some arity -> *)
(* (\* Ext_log.dwarn __LOC__ "arity %d" arity; *\) *)
(* Determin(false, [arity, None], false) *)
(* | None -> NA *)
(* end *)
| Lprim (Pfield (n,_), [Lprim(Pgetglobal id,[])]) ->
Lam_compile_env.find_and_add_if_not_exist (id, n) meta.env
~not_found:(fun _ -> assert false)
Expand Down
75 changes: 75 additions & 0 deletions jscomp/syntax/ast_comb.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In addition to the permissions granted to you by the LGPL, you may combine
* or link a "work that uses the Library" with a publicly distributed version
* of this file to produce a combined library or application, then distribute
* that combined work under the terms of your choosing, with no requirement
* to comply with the obligations normally placed on you by section 4 of the
* LGPL version 3 (or the corresponding section of a later version of the LGPL
* should you choose to use a later version).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)

let create_local_external loc
?(pval_attributes=[])
~pval_prim
~pval_type
?(local_module_name = "J")
?(local_fun_name = "unsafe_expr")
args
: Parsetree.expression_desc =
Pexp_letmodule
({txt = local_module_name; loc},
{pmod_desc =
Pmod_structure
[{pstr_desc =
Pstr_primitive
{pval_name = {txt = local_fun_name; loc};
pval_type ;
pval_loc = loc;
pval_prim = [pval_prim];
pval_attributes };
pstr_loc = loc;
}];
pmod_loc = loc;
pmod_attributes = []},
{
pexp_desc =
Pexp_apply
(({pexp_desc = Pexp_ident {txt = Ldot (Lident local_module_name, local_fun_name);
loc};
pexp_attributes = [] ;
pexp_loc = loc} : Parsetree.expression),
args);
pexp_attributes = [];
pexp_loc = loc
})

open Ast_helper

let exp_apply_no_label ?loc ?attrs a b =
Exp.apply ?loc ?attrs a (List.map (fun x -> "", x) b)

let fun_no_label ?loc ?attrs pat body =
Exp.fun_ ?loc ?attrs "" None pat body

let arrow_no_label ?loc ?attrs b c =
Typ.arrow ?loc ?attrs "" b c

let discard_exp_as_unit loc e =
exp_apply_no_label ~loc
(Exp.ident ~loc {txt = Ast_literal.Lid.ignore_id; loc})
[Exp.constraint_ ~loc e
(Ast_literal.type_unit ~loc ())]
55 changes: 55 additions & 0 deletions jscomp/syntax/ast_comb.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In addition to the permissions granted to you by the LGPL, you may combine
* or link a "work that uses the Library" with a publicly distributed version
* of this file to produce a combined library or application, then distribute
* that combined work under the terms of your choosing, with no requirement
* to comply with the obligations normally placed on you by section 4 of the
* LGPL version 3 (or the corresponding section of a later version of the LGPL
* should you choose to use a later version).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)

val create_local_external : Location.t ->
?pval_attributes:Parsetree.attributes ->
pval_prim:string ->
pval_type:Parsetree.core_type ->
?local_module_name:string ->
?local_fun_name:string ->
(Asttypes.label * Parsetree.expression) list -> Parsetree.expression_desc

val exp_apply_no_label :
?loc:Location.t ->
?attrs:Parsetree.attributes ->
Parsetree.expression -> Parsetree.expression list -> Parsetree.expression

val fun_no_label :
?loc:Location.t ->
?attrs:Parsetree.attributes ->
Parsetree.pattern -> Parsetree.expression -> Parsetree.expression

val arrow_no_label :
?loc:Location.t ->
?attrs:Parsetree.attributes ->
Parsetree.core_type -> Parsetree.core_type -> Parsetree.core_type

(* note we first declare its type is [unit],
then [ignore] it, [ignore] is necessary since
the js value maybe not be of type [unit] and
we can use [unit] value (though very little chance)
sometimes
*)
val discard_exp_as_unit :
Location.t -> Parsetree.expression -> Parsetree.expression
26 changes: 26 additions & 0 deletions jscomp/syntax/ast_lift.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In addition to the permissions granted to you by the LGPL, you may combine
* or link a "work that uses the Library" with a publicly distributed version
* of this file to produce a combined library or application, then distribute
* that combined work under the terms of your choosing, with no requirement
* to comply with the obligations normally placed on you by section 4 of the
* LGPL version 3 (or the corresponding section of a later version of the LGPL
* should you choose to use a later version).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)

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

val int :
?loc:Location.t ->
?attrs:Parsetree.attributes -> int -> Parsetree.expression
Loading