Skip to content

Commit d905163

Browse files
committed
Clean up addressing style comments.
1 parent b0a0f7f commit d905163

File tree

6 files changed

+63
-81
lines changed

6 files changed

+63
-81
lines changed

jscomp/core/lam.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,13 +733,13 @@ let if_ (a : t) (b : t) (c : t) : t =
733733
begin match c with
734734
| Lswitch ( Lvar yy as switch_arg,
735735
({sw_blocks = []; sw_numblocks = true; sw_consts ;
736-
sw_numconsts; sw_failaction = None; sw_names; } as body)
736+
sw_numconsts; sw_failaction = None} as body)
737737
)
738738
when Ident.same xx yy
739739
&& complete_range sw_consts ~start:0 ~finish:range
740740
->
741741
Lswitch(switch_arg,
742-
{ body with sw_failaction = Some b; sw_numconsts = false; sw_names; })
742+
{ body with sw_failaction = Some b; sw_numconsts = false; })
743743
| _ -> Lifthenelse(a,b,c)
744744
end
745745
| _ -> Lifthenelse (a,b,c))

jscomp/core/lam_analysis.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ let rec no_side_effects (lam : Lam.t) : bool =
217217
-> false
218218
)
219219
| Llet (_,_, arg,body) -> no_side_effects arg && no_side_effects body
220-
| Lswitch _ -> false
220+
| Lswitch (_,_) -> false
221221
| Lstringswitch (_,_,_) -> false
222222
| Lstaticraise _ -> false
223223
| Lstaticcatch _ -> false

jscomp/core/lam_compile.ml

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -515,20 +515,10 @@ and compile_general_cases
515515
[switch ?default ?declaration switch_exp body]
516516
)
517517

518-
and compile_cases ~is_tag cxt switch_exp table default sw_names =
518+
and compile_cases cxt switch_exp table default get_name =
519519
compile_general_cases
520-
(fun i ->
521-
match sw_names with
522-
| None -> None
523-
| Some {Lam.blocks; consts} ->
524-
Some (if is_tag then blocks.(i) else consts.(i)))
525-
(fun i ->
526-
let comment =
527-
match sw_names with
528-
| None -> None
529-
| Some {Lam.blocks; consts} ->
530-
Some (if is_tag then blocks.(i) else consts.(i)) in
531-
{(E.small_int i) with comment})
520+
get_name
521+
(fun i -> {(E.small_int i) with comment = get_name i})
532522
E.int_equal
533523
cxt
534524
(fun ?default ?declaration e clauses ->
@@ -564,6 +554,11 @@ and compile_switch switch_arg sw (lambda_cxt : Lam_compile_context.t) =
564554
if sw_numblocks
565555
then Complete
566556
else Default x in
557+
let get_name is_const i =
558+
match sw_names with
559+
| None -> None
560+
| Some {blocks; consts} ->
561+
Some (if is_const then consts.(i) else blocks.(i)) in
567562
let compile_whole (cxt : Lam_compile_context.t ) =
568563
match compile_lambda
569564
{cxt with continuation = NeedValue Not_tail}
@@ -573,20 +568,20 @@ and compile_switch switch_arg sw (lambda_cxt : Lam_compile_context.t) =
573568
| { block; value = Some e } ->
574569
block @
575570
(if sw_numconsts && sw_consts = [] then
576-
compile_cases ~is_tag:true cxt (E.tag e) sw_blocks sw_blocks_default sw_names
571+
compile_cases cxt (E.tag e) sw_blocks sw_blocks_default (get_name false)
577572
else if sw_numblocks && sw_blocks = [] then
578-
compile_cases ~is_tag:false cxt e sw_consts sw_num_default sw_names
573+
compile_cases cxt e sw_consts sw_num_default (get_name true)
579574
else
580575
(* [e] will be used twice *)
581576
let dispatch e =
582577
S.if_
583578
(E.is_type_number e )
584-
(compile_cases ~is_tag:false cxt e sw_consts sw_num_default sw_names
579+
(compile_cases cxt e sw_consts sw_num_default (get_name true)
585580
)
586581
(* default still needed, could simplified*)
587582
~else_:
588-
(compile_cases ~is_tag:true cxt (E.tag e ) sw_blocks
589-
sw_blocks_default sw_names) in
583+
(compile_cases cxt (E.tag e ) sw_blocks
584+
sw_blocks_default (get_name false)) in
590585
match e.expression_desc with
591586
| J.Var _ -> [ dispatch e]
592587
| _ ->
@@ -768,15 +763,15 @@ and compile_staticcatch (lam : Lam.t) (lambda_cxt : Lam_compile_context.t)=
768763
Js_output.append_output
769764
(Js_output.make (S.declare_variable ~kind:Variable v :: declares) )
770765
(Js_output.append_output lbody (Js_output.make (
771-
compile_cases ~is_tag:false new_cxt exit_expr handlers NonComplete None) ~value:(E.var v )))
766+
compile_cases new_cxt exit_expr handlers NonComplete (fun _ -> None)) ~value:(E.var v )))
772767
| Declare (kind, id)
773768
(* declare first this we will do branching*) ->
774769
let declares = S.declare_variable ~kind id :: declares in
775770
let new_cxt = {lambda_cxt with jmp_table = jmp_table; continuation = Assign id } in
776771
let lbody = compile_lambda new_cxt body in
777772
Js_output.append_output (Js_output.make declares)
778773
(Js_output.append_output lbody
779-
(Js_output.make (compile_cases ~is_tag:false new_cxt exit_expr handlers NonComplete None)))
774+
(Js_output.make (compile_cases new_cxt exit_expr handlers NonComplete (fun _ -> None))))
780775
(* place holder -- tell the compiler that
781776
we don't know if it's complete
782777
*)
@@ -785,13 +780,13 @@ and compile_staticcatch (lam : Lam.t) (lambda_cxt : Lam_compile_context.t)=
785780
let lbody = compile_lambda new_cxt body in
786781
Js_output.append_output (Js_output.make declares)
787782
(Js_output.append_output lbody
788-
(Js_output.make (compile_cases ~is_tag:false new_cxt exit_expr handlers NonComplete None)))
783+
(Js_output.make (compile_cases new_cxt exit_expr handlers NonComplete (fun _ -> None))))
789784
| Assign _ ->
790785
let new_cxt = {lambda_cxt with jmp_table = jmp_table } in
791786
let lbody = compile_lambda new_cxt body in
792787
Js_output.append_output (Js_output.make declares)
793788
(Js_output.append_output lbody
794-
(Js_output.make (compile_cases ~is_tag:false new_cxt exit_expr handlers NonComplete None)))
789+
(Js_output.make (compile_cases new_cxt exit_expr handlers NonComplete (fun _ -> None))))
795790

796791
and compile_sequand
797792
(l : Lam.t) (r : Lam.t) (lambda_cxt : Lam_compile_context.t) =

jscomp/core/lam_convert.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,7 @@ let convert (exports : Ident_set.t) (lam : Lambda.lambda) : Lam.t * Lam_module_i
625625
#else
626626
(e,s)
627627
#end
628-
->
629-
convert_switch e s
628+
-> convert_switch e s
630629
| Lstringswitch (e, cases, default, _ ) ->
631630
Lam.stringswitch
632631
(convert_aux e)

lib/4.02.3/unstable/js_compiler.ml

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -75000,13 +75000,13 @@ let if_ (a : t) (b : t) (c : t) : t =
7500075000
begin match c with
7500175001
| Lswitch ( Lvar yy as switch_arg,
7500275002
({sw_blocks = []; sw_numblocks = true; sw_consts ;
75003-
sw_numconsts; sw_failaction = None; sw_names; } as body)
75003+
sw_numconsts; sw_failaction = None} as body)
7500475004
)
7500575005
when Ident.same xx yy
7500675006
&& complete_range sw_consts ~start:0 ~finish:range
7500775007
->
7500875008
Lswitch(switch_arg,
75009-
{ body with sw_failaction = Some b; sw_numconsts = false; sw_names; })
75009+
{ body with sw_failaction = Some b; sw_numconsts = false; })
7501075010
| _ -> Lifthenelse(a,b,c)
7501175011
end
7501275012
| _ -> Lifthenelse (a,b,c))
@@ -100887,7 +100887,7 @@ let rec no_side_effects (lam : Lam.t) : bool =
100887100887
-> false
100888100888
)
100889100889
| Llet (_,_, arg,body) -> no_side_effects arg && no_side_effects body
100890-
| Lswitch _ -> false
100890+
| Lswitch (_,_) -> false
100891100891
| Lstringswitch (_,_,_) -> false
100892100892
| Lstaticraise _ -> false
100893100893
| Lstaticcatch _ -> false
@@ -111196,20 +111196,10 @@ and compile_general_cases
111196111196
[switch ?default ?declaration switch_exp body]
111197111197
)
111198111198

111199-
and compile_cases ~is_tag cxt switch_exp table default sw_names =
111199+
and compile_cases cxt switch_exp table default get_name =
111200111200
compile_general_cases
111201-
(fun i ->
111202-
match sw_names with
111203-
| None -> None
111204-
| Some {Lam.blocks; consts} ->
111205-
Some (if is_tag then blocks.(i) else consts.(i)))
111206-
(fun i ->
111207-
let comment =
111208-
match sw_names with
111209-
| None -> None
111210-
| Some {Lam.blocks; consts} ->
111211-
Some (if is_tag then blocks.(i) else consts.(i)) in
111212-
{(E.small_int i) with comment})
111201+
get_name
111202+
(fun i -> {(E.small_int i) with comment = get_name i})
111213111203
E.int_equal
111214111204
cxt
111215111205
(fun ?default ?declaration e clauses ->
@@ -111245,6 +111235,11 @@ and compile_switch switch_arg sw (lambda_cxt : Lam_compile_context.t) =
111245111235
if sw_numblocks
111246111236
then Complete
111247111237
else Default x in
111238+
let get_name is_const i =
111239+
match sw_names with
111240+
| None -> None
111241+
| Some {blocks; consts} ->
111242+
Some (if is_const then consts.(i) else blocks.(i)) in
111248111243
let compile_whole (cxt : Lam_compile_context.t ) =
111249111244
match compile_lambda
111250111245
{cxt with continuation = NeedValue Not_tail}
@@ -111254,20 +111249,20 @@ and compile_switch switch_arg sw (lambda_cxt : Lam_compile_context.t) =
111254111249
| { block; value = Some e } ->
111255111250
block @
111256111251
(if sw_numconsts && sw_consts = [] then
111257-
compile_cases ~is_tag:true cxt (E.tag e) sw_blocks sw_blocks_default sw_names
111252+
compile_cases cxt (E.tag e) sw_blocks sw_blocks_default (get_name false)
111258111253
else if sw_numblocks && sw_blocks = [] then
111259-
compile_cases ~is_tag:false cxt e sw_consts sw_num_default sw_names
111254+
compile_cases cxt e sw_consts sw_num_default (get_name true)
111260111255
else
111261111256
(* [e] will be used twice *)
111262111257
let dispatch e =
111263111258
S.if_
111264111259
(E.is_type_number e )
111265-
(compile_cases ~is_tag:false cxt e sw_consts sw_num_default sw_names
111260+
(compile_cases cxt e sw_consts sw_num_default (get_name true)
111266111261
)
111267111262
(* default still needed, could simplified*)
111268111263
~else_:
111269-
(compile_cases ~is_tag:true cxt (E.tag e ) sw_blocks
111270-
sw_blocks_default sw_names) in
111264+
(compile_cases cxt (E.tag e ) sw_blocks
111265+
sw_blocks_default (get_name false)) in
111271111266
match e.expression_desc with
111272111267
| J.Var _ -> [ dispatch e]
111273111268
| _ ->
@@ -111445,15 +111440,15 @@ and compile_staticcatch (lam : Lam.t) (lambda_cxt : Lam_compile_context.t)=
111445111440
Js_output.append_output
111446111441
(Js_output.make (S.declare_variable ~kind:Variable v :: declares) )
111447111442
(Js_output.append_output lbody (Js_output.make (
111448-
compile_cases ~is_tag:false new_cxt exit_expr handlers NonComplete None) ~value:(E.var v )))
111443+
compile_cases new_cxt exit_expr handlers NonComplete (fun _ -> None)) ~value:(E.var v )))
111449111444
| Declare (kind, id)
111450111445
(* declare first this we will do branching*) ->
111451111446
let declares = S.declare_variable ~kind id :: declares in
111452111447
let new_cxt = {lambda_cxt with jmp_table = jmp_table; continuation = Assign id } in
111453111448
let lbody = compile_lambda new_cxt body in
111454111449
Js_output.append_output (Js_output.make declares)
111455111450
(Js_output.append_output lbody
111456-
(Js_output.make (compile_cases ~is_tag:false new_cxt exit_expr handlers NonComplete None)))
111451+
(Js_output.make (compile_cases new_cxt exit_expr handlers NonComplete (fun _ -> None))))
111457111452
(* place holder -- tell the compiler that
111458111453
we don't know if it's complete
111459111454
*)
@@ -111462,13 +111457,13 @@ and compile_staticcatch (lam : Lam.t) (lambda_cxt : Lam_compile_context.t)=
111462111457
let lbody = compile_lambda new_cxt body in
111463111458
Js_output.append_output (Js_output.make declares)
111464111459
(Js_output.append_output lbody
111465-
(Js_output.make (compile_cases ~is_tag:false new_cxt exit_expr handlers NonComplete None)))
111460+
(Js_output.make (compile_cases new_cxt exit_expr handlers NonComplete (fun _ -> None))))
111466111461
| Assign _ ->
111467111462
let new_cxt = {lambda_cxt with jmp_table = jmp_table } in
111468111463
let lbody = compile_lambda new_cxt body in
111469111464
Js_output.append_output (Js_output.make declares)
111470111465
(Js_output.append_output lbody
111471-
(Js_output.make (compile_cases ~is_tag:false new_cxt exit_expr handlers NonComplete None)))
111466+
(Js_output.make (compile_cases new_cxt exit_expr handlers NonComplete (fun _ -> None))))
111472111467

111473111468
and compile_sequand
111474111469
(l : Lam.t) (r : Lam.t) (lambda_cxt : Lam_compile_context.t) =
@@ -113232,8 +113227,7 @@ let convert (exports : Ident_set.t) (lam : Lambda.lambda) : Lam.t * Lam_module_i
113232113227

113233113228
(e,s)
113234113229

113235-
->
113236-
convert_switch e s
113230+
-> convert_switch e s
113237113231
| Lstringswitch (e, cases, default, _ ) ->
113238113232
Lam.stringswitch
113239113233
(convert_aux e)

lib/4.02.3/whole_compiler.ml

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -66573,13 +66573,13 @@ let if_ (a : t) (b : t) (c : t) : t =
6657366573
begin match c with
6657466574
| Lswitch ( Lvar yy as switch_arg,
6657566575
({sw_blocks = []; sw_numblocks = true; sw_consts ;
66576-
sw_numconsts; sw_failaction = None; sw_names; } as body)
66576+
sw_numconsts; sw_failaction = None} as body)
6657766577
)
6657866578
when Ident.same xx yy
6657966579
&& complete_range sw_consts ~start:0 ~finish:range
6658066580
->
6658166581
Lswitch(switch_arg,
66582-
{ body with sw_failaction = Some b; sw_numconsts = false; sw_names; })
66582+
{ body with sw_failaction = Some b; sw_numconsts = false; })
6658366583
| _ -> Lifthenelse(a,b,c)
6658466584
end
6658566585
| _ -> Lifthenelse (a,b,c))
@@ -91516,7 +91516,7 @@ let rec no_side_effects (lam : Lam.t) : bool =
9151691516
-> false
9151791517
)
9151891518
| Llet (_,_, arg,body) -> no_side_effects arg && no_side_effects body
91519-
| Lswitch _ -> false
91519+
| Lswitch (_,_) -> false
9152091520
| Lstringswitch (_,_,_) -> false
9152191521
| Lstaticraise _ -> false
9152291522
| Lstaticcatch _ -> false
@@ -102310,20 +102310,10 @@ and compile_general_cases
102310102310
[switch ?default ?declaration switch_exp body]
102311102311
)
102312102312

102313-
and compile_cases ~is_tag cxt switch_exp table default sw_names =
102313+
and compile_cases cxt switch_exp table default get_name =
102314102314
compile_general_cases
102315-
(fun i ->
102316-
match sw_names with
102317-
| None -> None
102318-
| Some {Lam.blocks; consts} ->
102319-
Some (if is_tag then blocks.(i) else consts.(i)))
102320-
(fun i ->
102321-
let comment =
102322-
match sw_names with
102323-
| None -> None
102324-
| Some {Lam.blocks; consts} ->
102325-
Some (if is_tag then blocks.(i) else consts.(i)) in
102326-
{(E.small_int i) with comment})
102315+
get_name
102316+
(fun i -> {(E.small_int i) with comment = get_name i})
102327102317
E.int_equal
102328102318
cxt
102329102319
(fun ?default ?declaration e clauses ->
@@ -102359,6 +102349,11 @@ and compile_switch switch_arg sw (lambda_cxt : Lam_compile_context.t) =
102359102349
if sw_numblocks
102360102350
then Complete
102361102351
else Default x in
102352+
let get_name is_const i =
102353+
match sw_names with
102354+
| None -> None
102355+
| Some {blocks; consts} ->
102356+
Some (if is_const then consts.(i) else blocks.(i)) in
102362102357
let compile_whole (cxt : Lam_compile_context.t ) =
102363102358
match compile_lambda
102364102359
{cxt with continuation = NeedValue Not_tail}
@@ -102368,20 +102363,20 @@ and compile_switch switch_arg sw (lambda_cxt : Lam_compile_context.t) =
102368102363
| { block; value = Some e } ->
102369102364
block @
102370102365
(if sw_numconsts && sw_consts = [] then
102371-
compile_cases ~is_tag:true cxt (E.tag e) sw_blocks sw_blocks_default sw_names
102366+
compile_cases cxt (E.tag e) sw_blocks sw_blocks_default (get_name false)
102372102367
else if sw_numblocks && sw_blocks = [] then
102373-
compile_cases ~is_tag:false cxt e sw_consts sw_num_default sw_names
102368+
compile_cases cxt e sw_consts sw_num_default (get_name true)
102374102369
else
102375102370
(* [e] will be used twice *)
102376102371
let dispatch e =
102377102372
S.if_
102378102373
(E.is_type_number e )
102379-
(compile_cases ~is_tag:false cxt e sw_consts sw_num_default sw_names
102374+
(compile_cases cxt e sw_consts sw_num_default (get_name true)
102380102375
)
102381102376
(* default still needed, could simplified*)
102382102377
~else_:
102383-
(compile_cases ~is_tag:true cxt (E.tag e ) sw_blocks
102384-
sw_blocks_default sw_names) in
102378+
(compile_cases cxt (E.tag e ) sw_blocks
102379+
sw_blocks_default (get_name false)) in
102385102380
match e.expression_desc with
102386102381
| J.Var _ -> [ dispatch e]
102387102382
| _ ->
@@ -102559,15 +102554,15 @@ and compile_staticcatch (lam : Lam.t) (lambda_cxt : Lam_compile_context.t)=
102559102554
Js_output.append_output
102560102555
(Js_output.make (S.declare_variable ~kind:Variable v :: declares) )
102561102556
(Js_output.append_output lbody (Js_output.make (
102562-
compile_cases ~is_tag:false new_cxt exit_expr handlers NonComplete None) ~value:(E.var v )))
102557+
compile_cases new_cxt exit_expr handlers NonComplete (fun _ -> None)) ~value:(E.var v )))
102563102558
| Declare (kind, id)
102564102559
(* declare first this we will do branching*) ->
102565102560
let declares = S.declare_variable ~kind id :: declares in
102566102561
let new_cxt = {lambda_cxt with jmp_table = jmp_table; continuation = Assign id } in
102567102562
let lbody = compile_lambda new_cxt body in
102568102563
Js_output.append_output (Js_output.make declares)
102569102564
(Js_output.append_output lbody
102570-
(Js_output.make (compile_cases ~is_tag:false new_cxt exit_expr handlers NonComplete None)))
102565+
(Js_output.make (compile_cases new_cxt exit_expr handlers NonComplete (fun _ -> None))))
102571102566
(* place holder -- tell the compiler that
102572102567
we don't know if it's complete
102573102568
*)
@@ -102576,13 +102571,13 @@ and compile_staticcatch (lam : Lam.t) (lambda_cxt : Lam_compile_context.t)=
102576102571
let lbody = compile_lambda new_cxt body in
102577102572
Js_output.append_output (Js_output.make declares)
102578102573
(Js_output.append_output lbody
102579-
(Js_output.make (compile_cases ~is_tag:false new_cxt exit_expr handlers NonComplete None)))
102574+
(Js_output.make (compile_cases new_cxt exit_expr handlers NonComplete (fun _ -> None))))
102580102575
| Assign _ ->
102581102576
let new_cxt = {lambda_cxt with jmp_table = jmp_table } in
102582102577
let lbody = compile_lambda new_cxt body in
102583102578
Js_output.append_output (Js_output.make declares)
102584102579
(Js_output.append_output lbody
102585-
(Js_output.make (compile_cases ~is_tag:false new_cxt exit_expr handlers NonComplete None)))
102580+
(Js_output.make (compile_cases new_cxt exit_expr handlers NonComplete (fun _ -> None))))
102586102581

102587102582
and compile_sequand
102588102583
(l : Lam.t) (r : Lam.t) (lambda_cxt : Lam_compile_context.t) =
@@ -110941,8 +110936,7 @@ let convert (exports : Ident_set.t) (lam : Lambda.lambda) : Lam.t * Lam_module_i
110941110936

110942110937
(e,s)
110943110938

110944-
->
110945-
convert_switch e s
110939+
-> convert_switch e s
110946110940
| Lstringswitch (e, cases, default, _ ) ->
110947110941
Lam.stringswitch
110948110942
(convert_aux e)

0 commit comments

Comments
 (0)