Skip to content

Commit 8d20d89

Browse files
committed
optimize the generated code
1 parent 7ddef8e commit 8d20d89

File tree

10 files changed

+1412
-1630
lines changed

10 files changed

+1412
-1630
lines changed

jscomp/core/js_fold.ml

Lines changed: 143 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -1,222 +1,194 @@
11

22
open J
3-
let [@inline] unknown o _ = o
3+
let [@inline] unknown _self _ = _self
44
class fold =
5-
object ((o : 'self_type))
5+
object ((_self : 'self_type))
66
method option :
77
'a. ('self_type -> 'a -> 'self_type) -> 'a option -> 'self_type =
8-
fun _f_a -> function | None -> o | Some _x -> let o = _f_a o _x in o
8+
fun _f_a -> function | None -> _self | Some _x -> let _self = _f_a _self _x in _self
99
method list :
1010
'a. ('self_type -> 'a -> 'self_type) -> 'a list -> 'self_type =
1111
fun _f_a ->
1212
function
13-
| [] -> o
14-
| _x :: _x_i1 -> let o = _f_a o _x in let o = o#list _f_a _x_i1 in o
15-
method label : label -> 'self_type = unknown o
16-
method required_modules : required_modules -> 'self_type = o#list (fun o -> o#module_id)
17-
method ident : ident -> 'self_type = unknown o
18-
method module_id : module_id -> 'self_type = fun { id = _x0;kind = _x1} -> let o = o#ident _x0 in
19-
let o = unknown o _x1 in o
13+
| [] -> _self
14+
| _x :: _x_i1 -> let _self = _f_a _self _x in let _self = _self#list _f_a _x_i1 in _self
15+
method label : label -> 'self_type = unknown _self
16+
method required_modules : required_modules -> 'self_type = _self#list (fun _self -> _self#module_id)
17+
method ident : ident -> 'self_type = unknown _self
18+
method module_id : module_id -> 'self_type = fun { id = _x0;kind = _x1} -> let _self = _self#ident _x0 in _self
2019
method vident : vident -> 'self_type = function
2120
| Id ( _x0) ->
22-
let o = o#ident _x0 in
23-
o
21+
let _self = _self#ident _x0 in
22+
_self
2423
|Qualified ( _x0,_x1) ->
25-
let o = o#module_id _x0 in
26-
let o = o#option (fun o -> unknown o) _x1 in
27-
o
28-
method exception_ident : exception_ident -> 'self_type = o#ident
29-
method for_ident : for_ident -> 'self_type = o#ident
30-
method for_direction : for_direction -> 'self_type = unknown o
31-
method property_map : property_map -> 'self_type = o#list (fun o -> fun ( _x0,_x1) -> let o = unknown o _x0 in let o = o#expression _x1 in o)
32-
method length_object : length_object -> 'self_type = unknown o
24+
let _self = _self#module_id _x0 in
25+
let _self = _self#option (fun _self -> unknown _self) _x1 in
26+
_self
27+
method exception_ident : exception_ident -> 'self_type = _self#ident
28+
method for_ident : for_ident -> 'self_type = _self#ident
29+
method for_direction : for_direction -> 'self_type = unknown _self
30+
method property_map : property_map -> 'self_type = _self#list (fun _self -> fun ( _x0,_x1) -> let _self = _self#expression _x1 in _self)
31+
method length_object : length_object -> 'self_type = unknown _self
3332
method expression_desc : expression_desc -> 'self_type = function
3433
| Length ( _x0,_x1) ->
35-
let o = o#expression _x0 in
36-
let o = o#length_object _x1 in
37-
o
34+
let _self = _self#expression _x0 in
35+
let _self = _self#length_object _x1 in
36+
_self
3837
|Char_of_int ( _x0) ->
39-
let o = o#expression _x0 in
40-
o
38+
let _self = _self#expression _x0 in
39+
_self
4140
|Char_to_int ( _x0) ->
42-
let o = o#expression _x0 in
43-
o
41+
let _self = _self#expression _x0 in
42+
_self
4443
|Is_null_or_undefined ( _x0) ->
45-
let o = o#expression _x0 in
46-
o
44+
let _self = _self#expression _x0 in
45+
_self
4746
|String_append ( _x0,_x1) ->
48-
let o = o#expression _x0 in
49-
let o = o#expression _x1 in
50-
o
51-
|Bool ( _x0) ->
52-
let o = unknown o _x0 in
53-
o
47+
let _self = _self#expression _x0 in
48+
let _self = _self#expression _x1 in
49+
_self
50+
|Bool _ -> _self
5451
|Typeof ( _x0) ->
55-
let o = o#expression _x0 in
56-
o
52+
let _self = _self#expression _x0 in
53+
_self
5754
|Js_not ( _x0) ->
58-
let o = o#expression _x0 in
59-
o
55+
let _self = _self#expression _x0 in
56+
_self
6057
|Seq ( _x0,_x1) ->
61-
let o = o#expression _x0 in
62-
let o = o#expression _x1 in
63-
o
58+
let _self = _self#expression _x0 in
59+
let _self = _self#expression _x1 in
60+
_self
6461
|Cond ( _x0,_x1,_x2) ->
65-
let o = o#expression _x0 in
66-
let o = o#expression _x1 in
67-
let o = o#expression _x2 in
68-
o
62+
let _self = _self#expression _x0 in
63+
let _self = _self#expression _x1 in
64+
let _self = _self#expression _x2 in
65+
_self
6966
|Bin ( _x0,_x1,_x2) ->
70-
let o = unknown o _x0 in
71-
let o = o#expression _x1 in
72-
let o = o#expression _x2 in
73-
o
67+
let _self = _self#expression _x1 in
68+
let _self = _self#expression _x2 in
69+
_self
7470
|FlatCall ( _x0,_x1) ->
75-
let o = o#expression _x0 in
76-
let o = o#expression _x1 in
77-
o
71+
let _self = _self#expression _x0 in
72+
let _self = _self#expression _x1 in
73+
_self
7874
|Call ( _x0,_x1,_x2) ->
79-
let o = o#expression _x0 in
80-
let o = o#list (fun o -> o#expression) _x1 in
81-
let o = unknown o _x2 in
82-
o
75+
let _self = _self#expression _x0 in
76+
let _self = _self#list (fun _self -> _self#expression) _x1 in
77+
_self
8378
|String_index ( _x0,_x1) ->
84-
let o = o#expression _x0 in
85-
let o = o#expression _x1 in
86-
o
79+
let _self = _self#expression _x0 in
80+
let _self = _self#expression _x1 in
81+
_self
8782
|Array_index ( _x0,_x1) ->
88-
let o = o#expression _x0 in
89-
let o = o#expression _x1 in
90-
o
83+
let _self = _self#expression _x0 in
84+
let _self = _self#expression _x1 in
85+
_self
9186
|Static_index ( _x0,_x1,_x2) ->
92-
let o = o#expression _x0 in
93-
let o = unknown o _x1 in
94-
let o = o#option (fun o -> unknown o) _x2 in
95-
o
87+
let _self = _self#expression _x0 in
88+
let _self = _self#option (fun _self -> unknown _self) _x2 in
89+
_self
9690
|New ( _x0,_x1) ->
97-
let o = o#expression _x0 in
98-
let o = o#option (fun o -> o#list (fun o -> o#expression)) _x1 in
99-
o
91+
let _self = _self#expression _x0 in
92+
let _self = _self#option (fun _self -> _self#list (fun _self -> _self#expression)) _x1 in
93+
_self
10094
|Var ( _x0) ->
101-
let o = o#vident _x0 in
102-
o
95+
let _self = _self#vident _x0 in
96+
_self
10397
|Fun ( _x0,_x1,_x2,_x3) ->
104-
let o = unknown o _x0 in
105-
let o = o#list (fun o -> o#ident) _x1 in
106-
let o = o#block _x2 in
107-
let o = unknown o _x3 in
108-
o
109-
|Str ( _x0,_x1) ->
110-
let o = unknown o _x0 in
111-
let o = unknown o _x1 in
112-
o
113-
|Unicode ( _x0) ->
114-
let o = unknown o _x0 in
115-
o
116-
|Raw_js_code ( _x0) ->
117-
let o = unknown o _x0 in
118-
o
98+
let _self = _self#list (fun _self -> _self#ident) _x1 in
99+
let _self = _self#block _x2 in
100+
_self
101+
|Str _ -> _self
102+
|Unicode _ -> _self
103+
|Raw_js_code _ -> _self
119104
|Array ( _x0,_x1) ->
120-
let o = o#list (fun o -> o#expression) _x0 in
121-
let o = unknown o _x1 in
122-
o
105+
let _self = _self#list (fun _self -> _self#expression) _x0 in
106+
_self
123107
|Optional_block ( _x0,_x1) ->
124-
let o = o#expression _x0 in
125-
let o = unknown o _x1 in
126-
o
108+
let _self = _self#expression _x0 in
109+
_self
127110
|Caml_block ( _x0,_x1,_x2,_x3) ->
128-
let o = o#list (fun o -> o#expression) _x0 in
129-
let o = unknown o _x1 in
130-
let o = o#expression _x2 in
131-
let o = unknown o _x3 in
132-
o
111+
let _self = _self#list (fun _self -> _self#expression) _x0 in
112+
let _self = _self#expression _x2 in
113+
_self
133114
|Caml_block_tag ( _x0) ->
134-
let o = o#expression _x0 in
135-
o
136-
|Number ( _x0) ->
137-
let o = unknown o _x0 in
138-
o
115+
let _self = _self#expression _x0 in
116+
_self
117+
|Number _ -> _self
139118
|Object ( _x0) ->
140-
let o = o#property_map _x0 in
141-
o
142-
|Undefined -> o
143-
|Null -> o
144-
method for_ident_expression : for_ident_expression -> 'self_type = o#expression
145-
method finish_ident_expression : finish_ident_expression -> 'self_type = o#expression
119+
let _self = _self#property_map _x0 in
120+
_self
121+
|Undefined -> _self
122+
|Null -> _self
123+
method for_ident_expression : for_ident_expression -> 'self_type = _self#expression
124+
method finish_ident_expression : finish_ident_expression -> 'self_type = _self#expression
146125
method statement_desc : statement_desc -> 'self_type = function
147126
| Block ( _x0) ->
148-
let o = o#block _x0 in
149-
o
127+
let _self = _self#block _x0 in
128+
_self
150129
|Variable ( _x0) ->
151-
let o = o#variable_declaration _x0 in
152-
o
130+
let _self = _self#variable_declaration _x0 in
131+
_self
153132
|Exp ( _x0) ->
154-
let o = o#expression _x0 in
155-
o
133+
let _self = _self#expression _x0 in
134+
_self
156135
|If ( _x0,_x1,_x2) ->
157-
let o = o#expression _x0 in
158-
let o = o#block _x1 in
159-
let o = o#block _x2 in
160-
o
136+
let _self = _self#expression _x0 in
137+
let _self = _self#block _x1 in
138+
let _self = _self#block _x2 in
139+
_self
161140
|While ( _x0,_x1,_x2,_x3) ->
162-
let o = o#option (fun o -> o#label) _x0 in
163-
let o = o#expression _x1 in
164-
let o = o#block _x2 in
165-
let o = unknown o _x3 in
166-
o
141+
let _self = _self#option (fun _self -> _self#label) _x0 in
142+
let _self = _self#expression _x1 in
143+
let _self = _self#block _x2 in
144+
_self
167145
|ForRange ( _x0,_x1,_x2,_x3,_x4,_x5) ->
168-
let o = o#option (fun o -> o#for_ident_expression) _x0 in
169-
let o = o#finish_ident_expression _x1 in
170-
let o = o#for_ident _x2 in
171-
let o = o#for_direction _x3 in
172-
let o = o#block _x4 in
173-
let o = unknown o _x5 in
174-
o
146+
let _self = _self#option (fun _self -> _self#for_ident_expression) _x0 in
147+
let _self = _self#finish_ident_expression _x1 in
148+
let _self = _self#for_ident _x2 in
149+
let _self = _self#for_direction _x3 in
150+
let _self = _self#block _x4 in
151+
_self
175152
|Continue ( _x0) ->
176-
let o = o#label _x0 in
177-
o
178-
|Break -> o
153+
let _self = _self#label _x0 in
154+
_self
155+
|Break -> _self
179156
|Return ( _x0) ->
180-
let o = o#expression _x0 in
181-
o
157+
let _self = _self#expression _x0 in
158+
_self
182159
|Int_switch ( _x0,_x1,_x2) ->
183-
let o = o#expression _x0 in
184-
let o = o#list (fun o -> o#int_clause) _x1 in
185-
let o = o#option (fun o -> o#block) _x2 in
186-
o
160+
let _self = _self#expression _x0 in
161+
let _self = _self#list (fun _self -> _self#int_clause) _x1 in
162+
let _self = _self#option (fun _self -> _self#block) _x2 in
163+
_self
187164
|String_switch ( _x0,_x1,_x2) ->
188-
let o = o#expression _x0 in
189-
let o = o#list (fun o -> o#string_clause) _x1 in
190-
let o = o#option (fun o -> o#block) _x2 in
191-
o
165+
let _self = _self#expression _x0 in
166+
let _self = _self#list (fun _self -> _self#string_clause) _x1 in
167+
let _self = _self#option (fun _self -> _self#block) _x2 in
168+
_self
192169
|Throw ( _x0) ->
193-
let o = o#expression _x0 in
194-
o
170+
let _self = _self#expression _x0 in
171+
_self
195172
|Try ( _x0,_x1,_x2) ->
196-
let o = o#block _x0 in
197-
let o = o#option (fun o -> fun ( _x0,_x1) -> let o = o#exception_ident _x0 in let o = o#block _x1 in o) _x1 in
198-
let o = o#option (fun o -> o#block) _x2 in
199-
o
200-
|Debugger -> o
201-
method expression : expression -> 'self_type = fun { expression_desc = _x0;comment = _x1} -> let o = o#expression_desc _x0 in
202-
let o = o#option (fun o -> unknown o) _x1 in o
203-
method statement : statement -> 'self_type = fun { statement_desc = _x0;comment = _x1} -> let o = o#statement_desc _x0 in
204-
let o = o#option (fun o -> unknown o) _x1 in o
205-
method variable_declaration : variable_declaration -> 'self_type = fun { ident = _x0;value = _x1;property = _x2;ident_info = _x3} -> let o = o#ident _x0 in
206-
let o = o#option (fun o -> o#expression) _x1 in
207-
let o = unknown o _x2 in
208-
let o = unknown o _x3 in o
209-
method string_clause : string_clause -> 'self_type = fun ( _x0,_x1) -> let o = unknown o _x0 in let o = o#case_clause _x1 in o
210-
method int_clause : int_clause -> 'self_type = fun ( _x0,_x1) -> let o = unknown o _x0 in let o = o#case_clause _x1 in o
211-
method case_clause : case_clause -> 'self_type = fun { switch_body = _x0;should_break = _x1;comment = _x2} -> let o = o#block _x0 in
212-
let o = unknown o _x1 in
213-
let o = o#option (fun o -> unknown o) _x2 in o
214-
method block : block -> 'self_type = o#list (fun o -> o#statement)
215-
method program : program -> 'self_type = fun { block = _x0;exports = _x1;export_set = _x2} -> let o = o#block _x0 in
216-
let o = unknown o _x1 in
217-
let o = unknown o _x2 in o
218-
method deps_program : deps_program -> 'self_type = fun { program = _x0;modules = _x1;side_effect = _x2} -> let o = o#program _x0 in
219-
let o = o#required_modules _x1 in
220-
let o = o#option (fun o -> unknown o) _x2 in o
173+
let _self = _self#block _x0 in
174+
let _self = _self#option (fun _self -> fun ( _x0,_x1) -> let _self = _self#exception_ident _x0 in let _self = _self#block _x1 in _self) _x1 in
175+
let _self = _self#option (fun _self -> _self#block) _x2 in
176+
_self
177+
|Debugger -> _self
178+
method expression : expression -> 'self_type = fun { expression_desc = _x0;comment = _x1} -> let _self = _self#expression_desc _x0 in
179+
let _self = _self#option (fun _self -> unknown _self) _x1 in _self
180+
method statement : statement -> 'self_type = fun { statement_desc = _x0;comment = _x1} -> let _self = _self#statement_desc _x0 in
181+
let _self = _self#option (fun _self -> unknown _self) _x1 in _self
182+
method variable_declaration : variable_declaration -> 'self_type = fun { ident = _x0;value = _x1;property = _x2;ident_info = _x3} -> let _self = _self#ident _x0 in
183+
let _self = _self#option (fun _self -> _self#expression) _x1 in _self
184+
method string_clause : string_clause -> 'self_type = fun ( _x0,_x1) -> let _self = _self#case_clause _x1 in _self
185+
method int_clause : int_clause -> 'self_type = fun ( _x0,_x1) -> let _self = _self#case_clause _x1 in _self
186+
method case_clause : case_clause -> 'self_type = fun { switch_body = _x0;should_break = _x1;comment = _x2} -> let _self = _self#block _x0 in
187+
let _self = _self#option (fun _self -> unknown _self) _x2 in _self
188+
method block : block -> 'self_type = _self#list (fun _self -> _self#statement)
189+
method program : program -> 'self_type = fun { block = _x0;exports = _x1;export_set = _x2} -> let _self = _self#block _x0 in _self
190+
method deps_program : deps_program -> 'self_type = fun { program = _x0;modules = _x1;side_effect = _x2} -> let _self = _self#program _x0 in
191+
let _self = _self#required_modules _x1 in
192+
let _self = _self#option (fun _self -> unknown _self) _x2 in _self
221193
end
222194

0 commit comments

Comments
 (0)