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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 0 additions & 33 deletions jscomp/frontend/ast_uncurry_gen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -66,36 +66,3 @@ let to_method_callback loc (self : Bs_ast_mapper.mapper) label
}
[Typ.any ~loc ()]) );
] )

let to_uncurry_fn (e : Parsetree.expression) (self : Bs_ast_mapper.mapper)
(label : Asttypes.arg_label) pat body async : Parsetree.expression =
let loc = e.pexp_loc in
Bs_syntaxerr.optional_err loc label;
let rec aux acc (body : Parsetree.expression) =
match Ast_attributes.process_attributes_rev body.pexp_attributes with
| Nothing, _ -> (
match body.pexp_desc with
| Pexp_fun (arg_label, _, arg, body) ->
Bs_syntaxerr.optional_err loc arg_label;
aux ((arg_label, self.pat self arg) :: acc) body
| _ -> (self.expr self body, acc))
| _, _ -> (self.expr self body, acc)
in
let first_arg = self.pat self pat in

let result, rev_extra_args = aux [(label, first_arg)] body in
let result = Ast_async.add_promise_type ~async result in
let body =
Ext_list.fold_left rev_extra_args result (fun e (label, p) ->
Ast_helper.Exp.fun_ ~loc label None p e)
in
let body = Ast_async.add_async_attribute ~async body in

let arity = List.length rev_extra_args in
Bs_syntaxerr.err_large_arity loc arity;
let fun_exp = Ast_uncurried.uncurried_fun ~loc ~arity body in
{
e with
pexp_desc = fun_exp.pexp_desc;
pexp_attributes = fun_exp.pexp_attributes @ e.pexp_attributes;
}
17 changes: 0 additions & 17 deletions jscomp/frontend/ast_uncurry_gen.mli
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)

val to_uncurry_fn :
Parsetree.expression ->
Bs_ast_mapper.mapper ->
Asttypes.arg_label ->
Parsetree.pattern ->
Parsetree.expression ->
bool ->
(* async *)
Parsetree.expression
(**
[function] can only take one argument, that is the reason we did not adopt it
syntax:
{[ fun [@bs] pat pat1-> body ]}
[to_uncurry_fn (fun pat -> (fun pat1 -> ... body))]

*)

val to_method_callback :
Location.t ->
Bs_ast_mapper.mapper ->
Expand Down
6 changes: 0 additions & 6 deletions jscomp/frontend/bs_syntaxerr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,10 @@ type error =
| Misplaced_label_syntax
| Optional_in_uncurried_bs_attribute
| Bs_this_simple_pattern
| Bs_uncurried_arity_too_large

let pp_error fmt err =
Format.pp_print_string fmt
(match err with
| Bs_uncurried_arity_too_large ->
"Uncurried function supports only up to arity 22"
| Misplaced_label_syntax -> "Label syntax is not support in this position"
(*
let fn x = ((##) x ~hi) ~lo:1 ~hi:2
Expand Down Expand Up @@ -114,6 +111,3 @@ let optional_err loc (lbl : Asttypes.arg_label) =

let err_if_label loc (lbl : Asttypes.arg_label) =
if lbl <> Nolabel then raise (Error (loc, Misplaced_label_syntax))

let err_large_arity loc arity =
if arity > 22 then raise (Error (loc, Bs_uncurried_arity_too_large))
3 changes: 0 additions & 3 deletions jscomp/frontend/bs_syntaxerr.mli
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,9 @@ type error =
| Misplaced_label_syntax
| Optional_in_uncurried_bs_attribute
| Bs_this_simple_pattern
| Bs_uncurried_arity_too_large

val err : Location.t -> error -> 'a

val optional_err : Location.t -> Asttypes.arg_label -> unit

val err_if_label : Location.t -> Asttypes.arg_label -> unit

val err_large_arity : Location.t -> int -> unit