Skip to content

Commit 83ba99f

Browse files
committed
clean up js_output
1 parent 4cbd995 commit 83ba99f

37 files changed

+386
-376
lines changed

jscomp/core/js_output.ml

+24-21
Original file line numberDiff line numberDiff line change
@@ -41,53 +41,56 @@ type t = {
4141
block : J.block ;
4242
value : J.expression option;
4343
finished : finished ;
44-
(** When [finished] is true the block is already terminated, value does not make sense
45-
default is false, false is an conservative approach
46-
*)
44+
4745
}
4846

49-
type cont = Lam_compile_context.cont
47+
type continuation = Lam_compile_context.continuation
5048

51-
let make ?value ?(finished=False) block = {block ; value ; finished }
49+
let make ?value ?(finished=False) block =
50+
{ block ; value ; finished }
5251

53-
let of_stmt ?value ?(finished = False) stmt = {block = [stmt] ; value ; finished }
52+
let of_stmt ?value ?(finished = False) stmt =
53+
{ block = [stmt] ; value ; finished }
5454

5555
let of_block ?value ?(finished = False) block =
56-
{block ; value ; finished }
56+
{ block ; value ; finished }
5757

58-
let dummy = {value = None; block = []; finished = Dummy }
58+
let dummy =
59+
{value = None; block = []; finished = Dummy }
5960

60-
let handle_name_tail
61-
(name : cont)
61+
let output_of_expression
62+
(continuation : continuation)
6263
(should_return : Lam_compile_context.return_type)
63-
lam (exp : J.expression) : t =
64-
begin match name, should_return with
64+
(lam : Lam.t) (exp : J.expression) : t =
65+
begin match continuation, should_return with
6566
| EffectCall, ReturnFalse ->
6667
if Lam_analysis.no_side_effects lam
6768
then dummy
6869
else {block = []; value = Some exp ; finished = False}
69-
| EffectCall, ReturnTrue _ ->
70-
make [S.return_stmt exp] ~finished:True
7170
| Declare (kind, n), ReturnFalse ->
7271
make [ S.define_variable ~kind n exp]
7372
| Assign n ,ReturnFalse ->
7473
make [S.assign n exp ]
74+
| EffectCall, ReturnTrue _ ->
75+
make [S.return_stmt exp] ~finished:True
7576
| (Declare _ | Assign _ ), ReturnTrue _ ->
7677
make [S.unknown_lambda lam] ~finished:True
77-
| NeedValue, _ -> {block = []; value = Some exp; finished = False }
78+
| NeedValue, _ ->
79+
{block = []; value = Some exp; finished = False }
7880
end
7981

80-
let handle_block_return
81-
(st : cont)
82+
let output_of_block_and_expression
83+
(continuation : continuation)
8284
(should_return : Lam_compile_context.return_type)
8385
(lam : Lam.t) (block : J.block) exp : t =
84-
match st, should_return with
86+
match continuation, should_return with
87+
| EffectCall, ReturnFalse -> make block ~value:exp
8588
| Declare (kind,n), ReturnFalse ->
8689
make (block @ [ S.define_variable ~kind n exp])
87-
| Assign n, ReturnFalse -> make (block @ [S.assign n exp])
88-
| (Declare _ | Assign _), ReturnTrue _ -> make [S.unknown_lambda lam] ~finished:True
89-
| EffectCall, ReturnFalse -> make block ~value:exp
90+
| Assign n, ReturnFalse -> make (block @ [S.assign n exp])
9091
| EffectCall, ReturnTrue _ -> make (block @ [S.return_stmt exp]) ~finished:True
92+
| (Declare _ | Assign _), ReturnTrue _ ->
93+
make [S.unknown_lambda lam] ~finished:True
9194
| NeedValue, _ -> make block ~value:exp
9295

9396
let statement_of_opt_expr (x : J.expression option) : J.statement =

jscomp/core/js_output.mli

+46-19
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
containing that step
3636
*)
3737

38-
type cont = Lam_compile_context.cont
3938

4039
type finished =
4140
| True
@@ -47,16 +46,36 @@ type t = {
4746
value : J.expression option;
4847
finished : finished
4948
}
50-
51-
val make : ?value: J.expression -> ?finished:finished -> J.block -> t
52-
53-
val of_stmt : ?value: J.expression -> ?finished:finished -> J.statement -> t
54-
55-
val of_block : ?value:J.expression -> ?finished:finished -> J.block -> t
56-
57-
val to_block : t -> J.block
58-
59-
val to_break_block : t -> J.block * bool
49+
(** When [finished] is true the block is already terminated,
50+
value does not make sense
51+
[finished] default to false, which is conservative
52+
*)
53+
54+
val make :
55+
?value: J.expression ->
56+
?finished:finished ->
57+
J.block ->
58+
t
59+
60+
val of_stmt :
61+
?value: J.expression ->
62+
?finished:finished ->
63+
J.statement ->
64+
t
65+
66+
val of_block :
67+
?value:J.expression ->
68+
?finished:finished ->
69+
J.block ->
70+
t
71+
72+
val to_block :
73+
t ->
74+
J.block
75+
76+
val to_break_block :
77+
t ->
78+
J.block * bool
6079

6180
module Ops : sig
6281
val (++) : t -> t -> t
@@ -65,17 +84,25 @@ end
6584
val dummy : t
6685

6786

68-
val handle_name_tail :
69-
Lam_compile_context.cont ->
87+
val output_of_expression :
88+
Lam_compile_context.continuation ->
7089
Lam_compile_context.return_type ->
71-
Lam.t -> J.expression -> t
90+
Lam.t -> (* original lambda *)
91+
J.expression -> (* compiled expression *)
92+
t
7293

73-
val handle_block_return :
74-
Lam_compile_context.cont ->
94+
val output_of_block_and_expression :
95+
Lam_compile_context.continuation ->
7596
Lam_compile_context.return_type ->
7697
Lam.t ->
77-
J.block -> J.expression -> t
98+
J.block ->
99+
J.expression ->
100+
t
78101

79-
val concat : t list -> t
102+
val concat :
103+
t list ->
104+
t
80105

81-
val to_string : t -> string
106+
val to_string :
107+
t ->
108+
string

0 commit comments

Comments
 (0)