Skip to content

Commit 780f0a0

Browse files
authored
Merge pull request #4908 from rescript-lang/js_ir
no higher order types in js ir for easier code generation
2 parents 9a52f02 + eece9db commit 780f0a0

File tree

11 files changed

+1538
-1594
lines changed

11 files changed

+1538
-1594
lines changed

jscomp/core/j.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ and statement_desc =
305305
{[ goto : label option ; ]}
306306
*)
307307

308-
| Int_switch of expression * int case_clause list * block option
309-
| String_switch of expression * string case_clause list * block option
308+
| Int_switch of expression * int_clause list * block option
309+
| String_switch of expression * string_clause list * block option
310310
| Throw of expression
311311
| Try of block * (exception_ident * block) option * block option
312312
| Debugger
@@ -329,9 +329,9 @@ and variable_declaration = {
329329
property : property;
330330
ident_info : ident_info;
331331
}
332-
333-
and 'a case_clause = {
334-
switch_case : 'a ;
332+
and string_clause = string * case_clause
333+
and int_clause = int * case_clause
334+
and case_clause = {
335335
switch_body : block ;
336336
should_break : bool ; (* true means break *)
337337
comment : string option ;

jscomp/core/js_dump.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -488,9 +488,9 @@ and pp_function ~is_method
488488
since it can be either [int] or [string]
489489
*)
490490
and pp_one_case_clause : 'a .
491-
_ -> P.t -> (P.t -> 'a -> unit) -> 'a J.case_clause -> _
491+
_ -> P.t -> (P.t -> 'a -> unit) -> ('a * J.case_clause) -> _
492492
= fun cxt f pp_cond
493-
({switch_case; switch_body ; should_break; comment; } : _ J.case_clause) ->
493+
(switch_case, ({switch_body ; should_break; comment; } : J.case_clause)) ->
494494
let cxt =
495495
P.group f 1 (fun _ ->
496496
P.group f 1 (fun _ ->
@@ -520,7 +520,7 @@ and pp_one_case_clause : 'a .
520520
cxt
521521

522522
and loop_case_clauses : 'a . cxt ->
523-
P.t -> (P.t -> 'a -> unit) -> 'a J.case_clause list -> cxt
523+
P.t -> (P.t -> 'a -> unit) -> ('a * J.case_clause) list -> cxt
524524
= fun cxt f pp_cond cases ->
525525
Ext_list.fold_left cases cxt (fun acc x -> pp_one_case_clause acc f pp_cond x)
526526

jscomp/core/js_fold.ml

Lines changed: 165 additions & 169 deletions
Large diffs are not rendered by default.

jscomp/core/js_map.ml

Lines changed: 194 additions & 204 deletions
Large diffs are not rendered by default.

jscomp/core/js_of_lam_variant.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ let eval (arg : J.expression) (dispatches : (string * string) list ) : E.t =
4343
E.of_block
4444
[(S.string_switch arg
4545
(Ext_list.map dispatches (fun (i,r) ->
46-
{J.switch_case = i ;
46+
i, J.{
4747
switch_body = [S.return_stmt (E.str r)];
4848
should_break = false; (* FIXME: if true, still print break*)
4949
comment = None;
@@ -71,7 +71,7 @@ let eval_as_event (arg : J.expression) (dispatches : (string * string) list opti
7171

7272
(S.string_switch (E.poly_var_tag_access arg)
7373
(Ext_list.map dispatches (fun (i,r) ->
74-
{J.switch_case = i ;
74+
i, J.{
7575
switch_body = [S.return_stmt (E.str r)];
7676
should_break = false; (* FIXME: if true, still print break*)
7777
comment = None;
@@ -103,7 +103,7 @@ let eval_as_int (arg : J.expression) (dispatches : (string * int) list ) : E.t
103103
E.of_block
104104
[(S.string_switch arg
105105
(Ext_list.map dispatches (fun (i,r) ->
106-
{J.switch_case = i ;
106+
i, J.{
107107
switch_body = [S.return_stmt (E.int (Int32.of_int r))];
108108
should_break = false; (* FIXME: if true, still print break*)
109109
comment = None;

jscomp/core/js_stmt_make.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ let int_switch
9898
?(declaration : (J.property * Ident.t) option )
9999
?(default : J.block option)
100100
(e : J.expression)
101-
(clauses : int J.case_clause list): t =
101+
(clauses : (int * J.case_clause) list): t =
102102
match e.expression_desc with
103103
| Number (Int {i; _}) ->
104104
let continuation =
105105
match Ext_list.find_opt clauses
106-
(fun x ->
107-
if x.switch_case = Int32.to_int i then
106+
(fun (switch_case,x) ->
107+
if switch_case = Int32.to_int i then
108108
Some x.switch_body else None )
109109
with
110110
| Some case -> case
@@ -137,12 +137,12 @@ let string_switch
137137
?(declaration : (J.property * Ident.t) option)
138138
?(default : J.block option)
139139
(e : J.expression)
140-
(clauses : string J.case_clause list): t=
140+
(clauses : (string * J.case_clause) list): t=
141141
match e.expression_desc with
142142
| Str (_,s) ->
143143
let continuation =
144-
match Ext_list.find_opt clauses (fun x ->
145-
if x.switch_case = s then
144+
match Ext_list.find_opt clauses (fun (switch_case, x) ->
145+
if switch_case = s then
146146
Some x.switch_body
147147
else None
148148
) with

jscomp/core/js_stmt_make.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,15 @@ val int_switch :
8484
?declaration:Lam_compat.let_kind * Ident.t ->
8585
?default:J.block ->
8686
J.expression ->
87-
int J.case_clause list ->
87+
(int * J.case_clause) list ->
8888
t
8989

9090
val string_switch :
9191
?comment:string ->
9292
?declaration:Lam_compat.let_kind * Ident.t ->
9393
?default:J.block ->
9494
J.expression ->
95-
string J.case_clause list ->
95+
(string * J.case_clause) list ->
9696
t
9797

9898
(** Just declaration without initialization *)

jscomp/core/lam_compile.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ and compile_general_cases
490490
Lam_compile_context.t ->
491491
(?default:J.block ->
492492
?declaration:Lam_compat.let_kind * Ident.t ->
493-
_ -> 'a J.case_clause list -> J.statement) ->
493+
_ -> ('a * J.case_clause) list -> J.statement) ->
494494
_ ->
495495
('a * Lam.t) list -> default_case -> J.block
496496
= fun
@@ -501,7 +501,7 @@ and compile_general_cases
501501
(switch :
502502
?default:J.block ->
503503
?declaration:Lam_compat.let_kind * Ident.t ->
504-
_ -> _ J.case_clause list -> J.statement
504+
_ -> (_ * J.case_clause) list -> J.statement
505505
)
506506
(switch_exp : J.expression)
507507
(cases : (_ * Lam.t) list)
@@ -571,13 +571,13 @@ and compile_general_cases
571571
should_break
572572
else
573573
should_break && Lam_exit_code.has_exit lam in
574-
{J.switch_case ;
574+
switch_case , J.{
575575
switch_body;
576576
should_break;
577577
comment = make_comment switch_case;
578578
}
579579
else
580-
{ switch_case; switch_body = []; should_break = false; comment = make_comment switch_case; }
580+
switch_case, {switch_body = []; should_break = false; comment = make_comment switch_case; }
581581
)
582582

583583
(* TODO: we should also group default *)

0 commit comments

Comments
 (0)