Skip to content

Commit cbeaced

Browse files
committed
clean up
1 parent ced601f commit cbeaced

File tree

3 files changed

+36
-50
lines changed

3 files changed

+36
-50
lines changed

jscomp/core/js_output.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ val output_of_expression :
9494
J.expression -> (* compiled expression *)
9595
t
9696

97+
(** - needed for instrument [return] statement properly
98+
*)
9799
val output_of_block_and_expression :
98100
Lam_compile_context.continuation ->
99101
Lam_compile_context.return_type ->

jscomp/core/lam_compile.ml

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,22 +1300,22 @@ and
13001300
begin
13011301
match Lam_compile_context.find_exn i cxt with
13021302
| {exit_id; args ; order_id} ->
1303-
let args_code =
1304-
(Js_output.concat @@ Ext_list.map2 (
1305-
fun (x : Lam.t) (arg : Ident.t) ->
1306-
match x with
1307-
| Lvar id ->
1303+
Ext_list.fold_right2
1304+
(fun (x : Lam.t) (arg: Ident.t) acc ->
1305+
let new_output =
1306+
match x with
1307+
| Lvar id ->
13081308
Js_output.make [S.assign arg (E.var id)]
13091309

1310-
| _ -> (* TODO: should be Assign -- Assign is an optimization *)
1311-
compile_lambda {cxt with st = Assign arg ; should_return = ReturnFalse} x
1312-
) largs (args : Ident.t list))
1313-
in
1314-
Js_output.append_output args_code (* Declared in [Lstaticraise ]*)
1315-
(Js_output.make [S.assign exit_id (E.small_int order_id)]
1316-
~value:E.undefined)
1310+
| _ -> (* TODO: should be Assign -- Assign is an optimization *)
1311+
compile_lambda {cxt with st = Assign arg ; should_return = ReturnFalse} x
1312+
in Js_output.append_output new_output acc
1313+
)
1314+
largs args
1315+
(Js_output.make [S.assign exit_id (E.small_int order_id)]
1316+
~value:E.undefined)
13171317
| exception Not_found ->
1318-
Js_output.make [S.unknown_lambda ~comment:"error" lam]
1318+
assert false
13191319
(* staticraise is always enclosed by catch *)
13201320
end
13211321
(* Invariant: code can not be reused
@@ -1328,11 +1328,6 @@ and
13281328
if not we should use ``javascript break`` or ``continue``
13291329
*)
13301330
| Lstaticcatch _ ->
1331-
let code_table, body = flatten_caches lam in
1332-
1333-
1334-
let bindings = Ext_list.flat_map (fun (_,_,bindings) -> bindings) code_table in
1335-
13361331
(* compile_list name l false (\*\) *)
13371332
(* if exit_code_id == code
13381333
handler -- ids are not useful, since
@@ -1358,16 +1353,14 @@ and
13581353
]}
13591354
*)
13601355
(* TODO: handle NeedValue *)
1361-
let exit_id = Ext_ident.create_tmp ~name:"exit" () in
1356+
let code_table, body = flatten_caches lam in
1357+
let bindings = Ext_list.flat_map (fun (_,_,bindings) -> bindings) code_table in
1358+
let exit_id = Ext_ident.create_tmp ~name:"exit" () in
13621359
let exit_expr = E.var exit_id in
13631360
let jmp_table, handlers =
13641361
Lam_compile_context.add_jmps exit_id code_table jmp_table in
13651362

13661363
(* Declaration First, body and handler have the same value *)
1367-
(* There is a bug in google closure compiler:
1368-
https://github.com/google/closure-compiler/issues/1234#issuecomment-151976340
1369-
TODO: wait for a bug fix
1370-
*)
13711364
let declares =
13721365
S.define_variable ~kind:Variable exit_id
13731366
E.zero_int_literal ::

lib/whole_compiler.ml

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -87955,6 +87955,8 @@ val output_of_expression :
8795587955
J.expression -> (* compiled expression *)
8795687956
t
8795787957

87958+
(** - needed for instrument [return] statement properly
87959+
*)
8795887960
val output_of_block_and_expression :
8795987961
Lam_compile_context.continuation ->
8796087962
Lam_compile_context.return_type ->
@@ -87963,10 +87965,6 @@ val output_of_block_and_expression :
8796387965
J.expression ->
8796487966
t
8796587967

87966-
val concat :
87967-
t list ->
87968-
t
87969-
8797087968
val to_string :
8797187969
t ->
8797287970
string
@@ -98670,22 +98668,22 @@ and
9867098668
begin
9867198669
match Lam_compile_context.find_exn i cxt with
9867298670
| {exit_id; args ; order_id} ->
98673-
let args_code =
98674-
(Js_output.concat @@ Ext_list.map2 (
98675-
fun (x : Lam.t) (arg : Ident.t) ->
98676-
match x with
98677-
| Lvar id ->
98671+
Ext_list.fold_right2
98672+
(fun (x : Lam.t) (arg: Ident.t) acc ->
98673+
let new_output =
98674+
match x with
98675+
| Lvar id ->
9867898676
Js_output.make [S.assign arg (E.var id)]
9867998677

98680-
| _ -> (* TODO: should be Assign -- Assign is an optimization *)
98681-
compile_lambda {cxt with st = Assign arg ; should_return = ReturnFalse} x
98682-
) largs (args : Ident.t list))
98683-
in
98684-
Js_output.append_output args_code (* Declared in [Lstaticraise ]*)
98685-
(Js_output.make [S.assign exit_id (E.small_int order_id)]
98686-
~value:E.undefined)
98678+
| _ -> (* TODO: should be Assign -- Assign is an optimization *)
98679+
compile_lambda {cxt with st = Assign arg ; should_return = ReturnFalse} x
98680+
in Js_output.append_output new_output acc
98681+
)
98682+
largs args
98683+
(Js_output.make [S.assign exit_id (E.small_int order_id)]
98684+
~value:E.undefined)
9868798685
| exception Not_found ->
98688-
Js_output.make [S.unknown_lambda ~comment:"error" lam]
98686+
assert false
9868998687
(* staticraise is always enclosed by catch *)
9869098688
end
9869198689
(* Invariant: code can not be reused
@@ -98698,11 +98696,6 @@ and
9869898696
if not we should use ``javascript break`` or ``continue``
9869998697
*)
9870098698
| Lstaticcatch _ ->
98701-
let code_table, body = flatten_caches lam in
98702-
98703-
98704-
let bindings = Ext_list.flat_map (fun (_,_,bindings) -> bindings) code_table in
98705-
9870698699
(* compile_list name l false (\*\) *)
9870798700
(* if exit_code_id == code
9870898701
handler -- ids are not useful, since
@@ -98728,16 +98721,14 @@ and
9872898721
]}
9872998722
*)
9873098723
(* TODO: handle NeedValue *)
98731-
let exit_id = Ext_ident.create_tmp ~name:"exit" () in
98724+
let code_table, body = flatten_caches lam in
98725+
let bindings = Ext_list.flat_map (fun (_,_,bindings) -> bindings) code_table in
98726+
let exit_id = Ext_ident.create_tmp ~name:"exit" () in
9873298727
let exit_expr = E.var exit_id in
9873398728
let jmp_table, handlers =
9873498729
Lam_compile_context.add_jmps exit_id code_table jmp_table in
9873598730

9873698731
(* Declaration First, body and handler have the same value *)
98737-
(* There is a bug in google closure compiler:
98738-
https://github.com/google/closure-compiler/issues/1234#issuecomment-151976340
98739-
TODO: wait for a bug fix
98740-
*)
9874198732
let declares =
9874298733
S.define_variable ~kind:Variable exit_id
9874398734
E.zero_int_literal ::

0 commit comments

Comments
 (0)