-
Notifications
You must be signed in to change notification settings - Fork 465
/
Copy pathjs_exp_make.mli
300 lines (198 loc) · 7.74 KB
/
js_exp_make.mli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In addition to the permissions granted to you by the LGPL, you may combine
* or link a "work that uses the Library" with a publicly distributed version
* of this file to produce a combined library or application, then distribute
* that combined work under the terms of your choosing, with no requirement
* to comply with the obligations normally placed on you by section 4 of the
* LGPL version 3 (or the corresponding section of a later version of the LGPL
* should you choose to use a later version).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
(** Creator utilities for the [J] module *)
(** check if a javascript ast is constant
The better signature might be
{[
J.expresssion -> Js_output.t
]}
for exmaple
{[
e ?print_int(3) : 0
--->
if(e){print_int(3)}
]}
*)
type t = J.expression
val extract_non_pure : t -> t option
type binary_op = ?comment:string -> t -> t -> t
type unary_op = ?comment:string -> t -> t
(** simplify
{[if b then ]}
there is no need to convert b into OCaml boolean under this scenario
*)
val ocaml_boolean_under_condition : t -> t
(* val bin : ?comment:string -> J.binop -> t -> t -> t *)
val mk :
?comment:string -> J.expression_desc -> t
val access : binary_op
val string_access : binary_op
val var : ?comment:string -> J.ident -> t
val runtime_var_dot : ?comment:string -> string -> string -> t
val runtime_var_vid : string -> string -> J.vident
val ml_var_dot : ?comment:string -> Ident.t -> string -> t
val external_var_dot : ?comment:string -> external_name:string -> ?dot:string -> Ident.t -> t
val ml_var : ?comment:string -> Ident.t -> t
val runtime_call : ?comment:string -> string -> string -> t list -> t
val public_method_call : string -> t -> t -> Int32.t -> t list -> t
val runtime_ref : string -> string -> t
val str :
?pure:bool ->
?comment:string ->
string ->
t
val unicode :
?comment:string ->
string ->
t
val ocaml_fun : ?comment:string ->
?immutable_mask:bool array -> J.ident list -> J.block -> t
val method_ : ?comment:string ->
?immutable_mask:bool array -> J.ident list -> J.block -> t
val econd : ?comment:string -> t -> t -> t -> t
val int : ?comment:string -> ?c:char -> int32 -> t
val nint : ?comment:string -> nativeint -> t
val small_int : int -> t
val float : ?comment:string -> string -> t
val empty_string_literal : t
(* TODO: we can do hash consing for small integers *)
val zero_int_literal : t
val one_int_literal : t
val zero_float_lit : t
val obj_int_tag_literal : t
(** [is_out e range] is equivalent to [e > range or e <0]
*)
val is_out : binary_op
val dot : ?comment:string -> t -> string -> t
val array_length : unary_op
val string_length : unary_op
val string_of_small_int_array : unary_op
val bytes_length : unary_op
val function_length : unary_op
val char_of_int : unary_op
val char_to_int : unary_op
val array_append : binary_op
val array_copy : unary_op
val string_append : binary_op
(**
When in ES6 mode, we can use Symbol to guarantee its uniquess,
we can not tag [js] object, since it can be frozen
*)
val var_dot : ?comment:string -> Ident.t -> string -> t
val bind_var_call : ?comment:string -> Ident.t -> string -> t list -> t
val bind_call : ?comment:string -> J.expression -> string -> J.expression list -> t
val js_global_dot : ?comment:string -> string -> string -> t
val index : ?comment:string -> t -> Int32.t -> t
(** if the expression is a temporay block which has no side effect,
write to it does not really make sense, optimize it away *)
val index_addr : ?comment:string -> yes:(t -> t) -> no:t -> t -> Js_op.jsint -> t
val assign : binary_op
val triple_equal : binary_op
(* TODO: reduce [triple_equal] use *)
val float_equal : binary_op
val int_equal : binary_op
val string_equal : binary_op
val is_type_number : unary_op
val typeof : unary_op
val to_int32 : unary_op
val to_uint32 : unary_op
val unchecked_int32_add : binary_op
val int32_add : binary_op
val unchecked_int32_minus : binary_op
val int32_minus : binary_op
val int32_mul : binary_op
val unchecked_int32_mul : binary_op
val int32_div : checked:bool -> binary_op
val int32_mod : checked:bool -> binary_op
val int32_lsl : binary_op
val int32_lsr : binary_op
val int32_asr : binary_op
val int32_bxor : binary_op
val int32_band : binary_op
val int32_bor : binary_op
val float_add : binary_op
val float_minus : binary_op
val float_mul : binary_op
val float_div : binary_op
val float_notequal : binary_op
val float_mod : binary_op
val int_comp : Lambda.comparison -> binary_op
val string_comp : Js_op.binop -> binary_op
val float_comp : Lambda.comparison -> binary_op
val js_comp : Lambda.comparison -> binary_op
val not : t -> t
val call : ?comment:string -> info:Js_call_info.t -> t -> t list -> t
val flat_call : binary_op
val dump : ?comment:string -> Js_op.level -> t list -> t
val anything_to_string : unary_op
(** see {!https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Unary_plus}*)
val to_number : unary_op
val int_to_string : unary_op
val to_json_string : unary_op
val new_ : ?comment:string -> J.expression -> J.expression list -> t
val arr : ?comment:string -> J.mutable_flag -> J.expression list -> t
val make_block :
?comment:string ->
J.expression -> J.tag_info -> J.expression list -> J.mutable_flag -> t
val uninitialized_object :
?comment:string -> J.expression -> J.expression -> t
val uninitialized_array : unary_op
val seq : binary_op
val fuse_to_seq : t -> t list -> t
val obj : ?comment:string -> J.property_map -> t
val caml_true : t
val caml_false : t
val bool : bool -> t
val unit : t
(** [unit] in ocaml will be compiled into [0] in js *)
val js_var : ?comment:string -> string -> t
val js_global : ?comment:string -> string -> t
val undefined : t
val is_caml_block : ?comment:string -> t -> t
val math : ?comment:string -> string -> t list -> t
(** [math "abs"] --> Math["abs"] *)
val tag : ?comment:string -> J.expression -> t
val set_tag : ?comment:string -> J.expression -> J.expression -> t
(** Note that this is coupled with how we encode block, if we use the
`Object.defineProperty(..)` since the array already hold the length,
this should be a nop
*)
val set_length : ?comment:string -> J.expression -> J.expression -> t
val obj_length : ?comment:string -> J.expression -> t
val bool_of_boolean : unary_op
val and_ : binary_op
val or_ : binary_op
(** we don't expose a general interface, since a general interface is generally not safe *)
val is_instance_array : unary_op
(** used combined with [caml_update_dummy]*)
val dummy_obj : ?comment:string -> unit -> t
(** convert a block to expresion by using IIFE *)
val of_block : ?comment:string -> ?e:J.expression -> J.statement list -> t
val bind : binary_op
val raw_js_code : ?comment:string -> J.code_info -> string -> t
val nil : t
val is_nil : unary_op
val js_bool : ?comment:string -> bool -> t
val is_undef : unary_op
val not_implemented : ?comment:string -> string -> t