Skip to content
This repository
Newer
Older
100644 604 lines (479 sloc) 25.291 kb
fccc6851 » MLstate
2011-06-21 Initial open-source release
1 (*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 *)
18
19 (**
20 Qml Ast Constructors.
21
22 Facilities for meta generation of ast (used in the trx parser of qml e.g.)
23
24 @author Rudy Sicard
25 @author Louis Gesbert
26 @author Mikolaj Konarsky
27 @author Valentin Gatien-Baron
28 @author Esther Baruk
29 @author Mathieu Barbin
30 @author David Rajchenbach-Teller
31 *)
32
33
34 module ExprIdent :
35 sig
36 val source : string -> QmlAst.ident
37 val next : string -> QmlAst.ident
38 val _type : ?check:bool -> string -> QmlAst.TypeIdent.t
39 end
40
41 (** Tuples *)
42 module Tuple :
43 sig
44 val string : int -> string
45 val typeident : int -> QmlAst.TypeIdent.t
46 val field : int -> string
47 val first_field : int
48
49 (** {6 Qml couples} *)
50 (**
51 @deprecated use opa tuple instead
52 *)
53 (** *)
54 val qml_fst : string
55 val qml_snd : string
56 end
57
58
59
60 (** TYPES *)
61
62 module Type :
63 sig
64
65 val typevar : QmlAst.typevar -> QmlAst.ty
66 val next_var : unit -> QmlAst.ty
67
68 module Row :
69 sig
70 exception Missing_field of string * string list
71
72 val make : ?extend:bool -> (string * QmlAst.ty) list -> QmlAst.ty_row
73 val make_qml_tuple : QmlAst.ty list -> QmlAst.ty
74 val make_opa_tuple : QmlAst.ty list -> QmlAst.ty
75
76 val to_list : QmlAst.ty_row -> (string * QmlAst.ty) list
77 val to_list_and_extend : QmlAst.ty_row -> (string * QmlAst.ty) list * QmlAst.rowvar option
78
79 val map : (QmlAst.ty -> QmlAst.ty) -> QmlAst.ty_row -> QmlAst.ty_row
80 val dot : QmlAst.ty_row -> string -> QmlAst.ty
81
82 (** The ordered make apply a List.sort on the input list before building the record *)
83 val ordered_make : ?extend:bool -> (string * QmlAst.ty) list -> QmlAst.ty_row
84
85 val sort : QmlAst.ty_row -> QmlAst.ty_row
86 end
87
88 module Col :
89 sig
90 val make : ?extend:bool -> (string * QmlAst.ty) list list -> QmlAst.ty_col
91 val sort : QmlAst.ty_col -> QmlAst.ty_col
92 end
93
94
95 module Arrow : sig
96 (** transform arrow type into a list of type, or a list of args and a result type
97 eventually result type can be expanded as a list using expandlast function:
98 -expandlast is called using the current position of result type in list and result type
99 (typically it used gamma and wanted type arity to do the expansion)
100 note :
101 *)
102 val to_rev_list : ?expandlast:(int -> QmlAst.ty -> QmlAst.ty list) -> QmlAst.ty -> QmlAst.ty list
103 val to_list : ?expandlast:(int -> QmlAst.ty -> QmlAst.ty list) -> QmlAst.ty -> QmlAst.ty list
104 val to_args_res : ?expandlast:(int -> QmlAst.ty -> QmlAst.ty list) -> QmlAst.ty -> (QmlAst.ty list * QmlAst.ty)
105
106 (** [drop nb ty] Drop the first [nb] arguments of [ty]. Argument
107 [ty] must be an arrow and must have at least [nb]
108 arguments else it raise [Invalid_argument].
109 @raise Invalid_argument when [ty] doesn't have at least [nb] arrows
110 *)
111 val drop : int -> QmlAst.ty -> QmlAst.ty
112 end
113
114 val sort : QmlAst.ty -> QmlAst.ty (* sorts all that needs to be sorted, recursively *)
115
116 end
117
118 (** UNTYPED EXPR *)
119 (** WARNING: no annotmap, no position ! *)
120 module UntypedExpr :
121 sig
122
123 (** Copy an expression with annot refresh *)
124 val copy : QmlAst.expr -> QmlAst.expr
125
126 (**
127 {6 Identifiers}
128 *)
129 val source : string -> QmlAst.expr
130 val ident : QmlAst.ident -> QmlAst.expr
131 val fresh_internal : string -> QmlAst.expr
132
133
134 (**
135 {6 Expressions}
136 *)
137
138 val const : QmlAst.const_expr -> QmlAst.expr
139 val int : int -> QmlAst.expr
140 val float : float -> QmlAst.expr
141 val string : string -> QmlAst.expr
142 val unit : unit -> QmlAst.expr
143 val _false: unit -> QmlAst.expr
144 val _true: unit -> QmlAst.expr
145 val bool : bool -> QmlAst.expr
146
147 val letin : (QmlAst.ident * QmlAst.expr) list -> QmlAst.expr -> QmlAst.expr
148 val letrecin : (QmlAst.ident * QmlAst.expr) list -> QmlAst.expr -> QmlAst.expr
149 val stupid_letin : (QmlAst.ident * QmlAst.expr) list -> QmlAst.expr -> QmlAst.expr (* construct LetIn even when list is empty *)
150 val lambda : QmlAst.ident list -> QmlAst.expr -> QmlAst.expr
151 val apply : QmlAst.expr -> QmlAst.expr list -> QmlAst.expr
152
153 val may_lambda : QmlAst.ident list -> QmlAst.expr -> QmlAst.expr
154 val may_apply : QmlAst.expr -> QmlAst.expr list -> QmlAst.expr
155 (** same as [lambda] or [apply], except when the list is empty. In this case, they
156 just return the expression *)
157
158 val match_ : QmlAst.expr -> (QmlAst.pat * QmlAst.expr) list -> QmlAst.expr
159 val record : (string * QmlAst.expr) list -> QmlAst.expr
160 val dot : QmlAst.expr -> string -> QmlAst.expr
161 val extendrecord : string -> QmlAst.expr -> QmlAst.expr -> QmlAst.expr
162 val bypass : BslKey.t -> QmlAst.expr
163 val restricted_bypass : pass:string -> BslKey.t -> QmlAst.expr
164 val coerce : QmlAst.expr -> QmlAst.ty -> QmlAst.expr
165 val directive : QmlAst.qml_directive -> QmlAst.expr list -> QmlAst.ty list -> QmlAst.expr
166
167 (* parser : wait for type unification *)
168
169 (** {6 Patterns}*)
170
171 val patconst : QmlAst.const_expr -> QmlAst.pat
172 val patvar : QmlAst.ident -> QmlAst.pat
173 val patany : unit -> QmlAst.pat (** unit -> refresh annotation ! *)
174 val patemptyrecord : unit -> QmlAst.pat
175 val pat_opa_tuple : QmlAst.pat list -> QmlAst.pat
176 val patcoerce : QmlAst.pat -> QmlAst.ty -> QmlAst.pat
177 val pattrue: unit -> QmlAst.pat
178 val patfalse:unit -> QmlAst.pat
179 val patsome: QmlAst.ident -> QmlAst.pat
180 val patnone:unit -> QmlAst.pat
181
182
183 (** Sugar : produce patern on record (the terminaison can be '...' or closed) *)
184 (** use fold_right : keep the order *)
185 val patrecord : ?rowvar:QmlAst.pat_rowvar -> (string * QmlAst.pat) list -> QmlAst.pat
186 val patextendrecord : (string * QmlAst.pat) list -> QmlAst.pat
187
188 (** construct the pattern matching a list with the given subpatterns *)
189 val patlist : QmlAst.pat list -> QmlAst.pat
190
191 (** Helper to generate | x -> where x is fresh *)
192 val patfreshvar : string -> QmlAst.ident * QmlAst.pat
193
194 (** Other sugar *)
195 val list : QmlAst.expr list -> QmlAst.expr
196 val qml_tuple : QmlAst.expr list -> QmlAst.expr
197 val opa_tuple : QmlAst.expr list -> QmlAst.expr
198
199 (** if sugar *)
200 val ifthenelse : QmlAst.expr -> QmlAst.expr -> QmlAst.expr -> QmlAst.expr
201 end
202
203 (** UnValRec : (ex Triple Val Rec) : see the documentation in qmlAst.ml *)
204 module UnValRec :
205 sig
206 (** creates an unvalrec (cf. QmlAst ) *)
207 val make : ( QmlAst.ident * QmlAst.expr ) list -> QmlAst.unvalrec
208
209 (** sometime, there is no need to create the full unvalrec, but just some part of it *)
210 val letrec : ( QmlAst.ident * QmlAst.expr ) list -> QmlAst.expr
211
212 (** from a NewVal(Rec), gives a Let(Rec)In, the fiels list, and a rebuilder function ``à la Louis'' *)
213 val make_let : QmlAst.code_elt -> ( string * QmlAst.ident * QmlAst.expr ) list * QmlAst.expr * (QmlAst.expr -> QmlAst.code_elt) * (Annot.t list * Annot.t list) list
214
215 (** Extra Higher Level API : transformation of code in a unvalrec passe *)
216 val unvalrec_code : QmlAst.code -> QmlAst.code
217
218 (** from an expr, makes a NewVal [("_", expr)] and a rebuilder function *)
219 val make_code_elt : QmlAst.expr -> QmlAst.code_elt * (QmlAst.code_elt -> QmlAst.expr)
220
221 (** same, but the rebuilder function is from maped_code_elt (expecting a M_NewVal) *)
222 val make_code_elt_maped : QmlAst.expr -> QmlAst.code_elt * (('a, 'b) QmlAst.maped_code_elt -> 'a)
223 end
224
225 module TypedExpr :
226 sig
227 type annotmap = QmlAst.annotmap
228 type gamma = QmlTypes.Env.t
229
230 (**
231 <!> Do not use the annotation of the given expression.
232 Prefer using a specilized constructor
233 *)
234 val make : ?pos:FilePos.pos -> annotmap -> QmlAst.expr -> QmlAst.ty -> annotmap * QmlAst.expr
235
236 (**
237 Refresh the annotations in the given expression
238 Copies only the restricted annot, i.e. ty, original, position (drop precise_let, precise_index)
239 *)
240 val copy : annotmap -> QmlAst.expr -> annotmap * QmlAst.expr
241 val shallow_copy_new : annotmap_old:annotmap -> annotmap -> QmlAst.expr -> annotmap * QmlAst.expr
242 val shallow_copy : annotmap -> QmlAst.expr -> annotmap * QmlAst.expr
243 val shallow_copys : annotmap -> QmlAst.expr list -> annotmap * QmlAst.expr list
244 (** Copy annotations of an expression from an old to a new annotmap *)
245 val copy_new : annotmap_old:annotmap -> annotmap -> QmlAst.expr -> annotmap * QmlAst.expr
246 val copy_new_when_possible : annotmap_old:annotmap -> annotmap -> QmlAst.expr -> annotmap * QmlAst.expr
247 (** A special version with a trace (source -> dest intmap) *)
248 val copy_with_trace : annotmap -> QmlAst.expr -> (annotmap * QmlAnnotMap.trace) * QmlAst.expr
249
250 (**
251 natives types
252 *)
253 val ty_string : QmlAst.ty
254 val ty_int : QmlAst.ty
255 val ty_float : QmlAst.ty
256
257 val bypass : ?pos:FilePos.pos -> annotmap -> BslKey.t -> QmlAst.ty -> annotmap * QmlAst.expr
258 val ident : ?pos:FilePos.pos -> annotmap -> QmlAst.ident -> QmlAst.ty -> annotmap * QmlAst.expr
259 val const : ?pos:FilePos.pos -> annotmap -> QmlAst.const_expr -> annotmap * QmlAst.expr
260 val unit : ?pos:FilePos.pos -> annotmap -> annotmap * QmlAst.expr
261 val cheap_void : ?pos:FilePos.pos -> annotmap -> gamma -> annotmap * QmlAst.expr
262 val int : ?pos:FilePos.pos -> annotmap -> int -> annotmap * QmlAst.expr
263 val float : ?pos:FilePos.pos -> annotmap -> float -> annotmap * QmlAst.expr
264 val string : ?pos:FilePos.pos -> annotmap -> string -> annotmap * QmlAst.expr
265
266 (* try to guess positions and types from given expressions, when possible *)
267 val coerce : annotmap -> QmlAst.expr -> QmlAst.ty -> annotmap * QmlAst.expr
268 val letin : annotmap -> (QmlAst.ident * QmlAst.expr) list -> QmlAst.expr -> annotmap * QmlAst.expr
269 val letrecin : annotmap -> (QmlAst.ident * QmlAst.expr) list -> QmlAst.expr -> annotmap * QmlAst.expr
270
271 (** lambda [(x : tx); (y : ty)] (m : t) : tx, ty -> t *)
272 val lambda : ?pos:FilePos.pos -> annotmap -> (QmlAst.ident * QmlAst.ty) list -> QmlAst.expr -> annotmap * QmlAst.expr
273 (** same as lambda, but when the list is empty, returns [e] and not [-> e] *)
274 val may_lambda : ?pos:FilePos.pos -> annotmap -> (QmlAst.ident * QmlAst.ty) list -> QmlAst.expr -> annotmap * QmlAst.expr
275
276 (** apply (m : tx, ty -> t) [(x : tx); (y : ty)] : t *)
75cbb3ee » BourgerieQuentin
2012-01-24 [enhance] compiler: QmlAstCons.apply added optional ty argument
277 val apply : ?ty:QmlAst.ty -> gamma -> annotmap -> QmlAst.expr -> QmlAst.expr list -> annotmap * QmlAst.expr
fccc6851 » MLstate
2011-06-21 Initial open-source release
278 (** [apply_partial] allows to apply not enough arguments or to apply one group of arguments
279 when the type has two arrows *)
280 val apply_partial : gamma -> annotmap -> QmlAst.expr -> QmlAst.expr list -> annotmap * QmlAst.expr
281 (** same as [may_lambda] *)
282 val may_apply : gamma -> annotmap -> QmlAst.expr -> QmlAst.expr list -> annotmap * QmlAst.expr
283
284 val apply_ty : ?pos:FilePos.pos -> annotmap -> QmlAst.expr -> QmlAst.expr list -> QmlAst.ty -> annotmap * QmlAst.expr
285
286 val record : ?pos:FilePos.pos -> ?extend:bool -> annotmap -> (string * QmlAst.expr) list -> annotmap * QmlAst.expr
287 val sum_element : ?pos:FilePos.pos -> ?ty:QmlAst.ty -> annotmap -> (string * QmlAst.expr) list -> annotmap * QmlAst.expr
288 val dot : gamma -> annotmap -> QmlAst.expr -> string -> annotmap * QmlAst.expr
289
290 (**{6 Match constructors}*)
291 (** [match_ annotmap matched l] make a match. [matched] it's matched
292 expression. And [l] is a list of patterns and expressions. All
293 pattern, expression is an entry of constructed match. The type
294 of match is the type of the first expression on [l]. [l] can't
295 be empty.
296
297 Warning : Types of expressions in [l] must be able to unify, but
298 is not checked *)
299 val match_ : ?pos:FilePos.pos -> annotmap -> QmlAst.expr -> (QmlAst.pat * QmlAst.expr) list
300 -> annotmap * QmlAst.expr
301
302 (**
303 Same than [match_] but use the given [ty] instead of taking the
304 type of the first production.
305 *)
306 val match_ty : ?pos:FilePos.pos -> annotmap -> QmlAst.expr -> (QmlAst.pat * QmlAst.expr) list
307 -> QmlAst.ty -> annotmap * QmlAst.expr
308
309 (* TODO: *)
310 (* val extendrecord : annotmap -> string -> QmlAst.expr -> QmlAst.expr -> annotmap * QmlAst.expr *)
311
312 (**
313 Use the module [QmlDirective] to guess the type of the node
314 *)
315 val directive: ?pos:FilePos.pos -> annotmap -> QmlAst.qml_directive -> QmlAst.expr list -> QmlAst.ty list -> annotmap * QmlAst.expr
316
317 (**
318 Do not use [QmlDirective] fot guessing the type of the node,
319 but use the given ty instead.
320 *)
321 val directive_ty: ?pos:FilePos.pos -> annotmap -> QmlAst.qml_directive -> QmlAst.expr list -> QmlAst.ty list -> QmlAst.ty -> annotmap * QmlAst.expr
322 val directive_id: ?pos:FilePos.pos -> annotmap -> QmlAst.qml_directive -> QmlAst.expr -> annotmap * QmlAst.expr
323
324 val _false:?pos:FilePos.pos -> annotmap * gamma -> annotmap * QmlAst.expr
325 val _true: ?pos:FilePos.pos -> annotmap * gamma -> annotmap * QmlAst.expr
326 val bool: ?pos:FilePos.pos -> annotmap * gamma -> bool -> annotmap * QmlAst.expr
327
328 val _false_no_named_type:?pos:FilePos.pos -> annotmap * gamma -> annotmap * QmlAst.expr
329 val _true_no_named_type: ?pos:FilePos.pos -> annotmap * gamma -> annotmap * QmlAst.expr
330 val bool_no_named_type: ?pos:FilePos.pos -> annotmap * gamma -> bool -> annotmap * QmlAst.expr
331
332 val opa_tuple_2 :
333 ?pos:FilePos.pos -> annotmap * gamma -> QmlAst.expr * QmlAst.expr -> annotmap * QmlAst.expr
334
335 val lambda_coerce : annotmap -> QmlAst.ident -> QmlAst.ty (* of ident *) -> QmlAst.expr -> annotmap * QmlAst.expr
336
337 (** {6 List constructors} *)
338 (** Generate a qml list reversed compare to the given list. *)
339 val rev_list : ?pos:FilePos.pos -> ?ty:QmlAst.ty -> annotmap * gamma -> QmlAst.expr list
340 -> annotmap * QmlAst.expr
341
342 (** Like that [make_rev_list], but generated list isn't reversed. *)
343 val list : ?pos:FilePos.pos -> ?ty:QmlAst.ty -> annotmap * gamma -> QmlAst.expr list -> annotmap * QmlAst.expr
344
345 (** Construct a list from a function [f] that able to create a typed
346 expression with an ['a], and from an ['a list]. Constructed qml
347 list is reversed compared to the given list. Optional [ty]
348 argument is type of generated qml list, by default it's a
349 variant.
350
351 WARNING : For consistency [f] must be generated typed expression
352 with comparable types, but [make_rev_list] doesn't check
353 that. *)
354 val rev_list_map :
355 ?pos:FilePos.pos -> ?ty:QmlAst.ty ->
356 (annotmap -> 'a -> annotmap * QmlAst.expr) ->
357 (annotmap * gamma) -> 'a list -> annotmap * QmlAst.expr
358
359 (** Like that [make_rev_list], but generated list isn't reversed. *)
360 val list_map :
361 ?pos:FilePos.pos -> ?ty:QmlAst.ty ->
362 (annotmap -> 'a -> annotmap * QmlAst.expr) ->
363 (annotmap * gamma) -> 'a list -> annotmap * QmlAst.expr
364
365 (** {Option constructors}*)
366 (** [some expr] Generate an [option] expression, like that in Opa
367 Syntax : [{some = expr}] *)
368 val some : ?pos:FilePos.pos -> annotmap -> gamma -> QmlAst.expr -> annotmap * QmlAst.expr
369
370 (** Generate an [option] expression, like that in Opa Syntax :
371 [{none}]. [ty] optional argument it's the type of option, if it
372 not given it's a type variable. *)
373 val none : ?pos:FilePos.pos -> ?ty:QmlAst.ty -> annotmap -> gamma -> annotmap * QmlAst.expr
374
375 val tagged_string : ?pos:FilePos.pos -> annotmap -> string -> QmlAst.tagged_string_kind -> annotmap * QmlAst.expr
376
377 end
378
379 (** Typed pattern and match constructor module
380
381 @author Quentin Bourgerie
382
383 Warning : I'm not sure of typing on field (needs review)
384 *)
385 module TypedPat :
386 sig
387 (**{6 Shortcut types} *)
388
389 type annotmap = QmlAst.annotmap
390
391 type gamma = QmlTypes.Env.t
392
393 (** same behaviour as in TypedExpr *)
394 val copy : annotmap -> QmlAst.pat -> annotmap * QmlAst.pat
395 val copy_new_when_possible : annotmap_old:annotmap -> annotmap -> QmlAst.pat -> annotmap * QmlAst.pat
396
397 (**{6 Basic constructors}*)
398 (**
399 [patmake annotmap pat0 ty] Make a typed pattern from a untyped
400 pattern ([pat]) and a type ([ty]). Returns updated annotmap and
401 typed pattern.
402 <!> The annotation of pat is not used, it is refreshed
403 *)
404 val make : ?pos:FilePos.pos -> annotmap -> QmlAst.pat -> QmlAst.ty -> annotmap * QmlAst.pat
405
406 (** Make a any typed pattern. If [ty] is not given, type is a type
407 variable *)
408 val any : ?pos:FilePos.pos -> ?ty:QmlAst.ty -> annotmap -> annotmap * QmlAst.pat
409
410 (** [patvar annotmap ident ty] Make a typed variable pattern from an
411 [ident] and a type ([ty]). Returns updated annotmap and typed
412 pattern.
413
414 Warning : [patvar] don't check if the given [ident] is
415 typed by [ty]. *)
416 val var : ?pos:FilePos.pos -> annotmap -> QmlAst.ident -> QmlAst.ty -> annotmap * QmlAst.pat
417
418 (** Make a typed pattern on empty record *)
419 val emptyrecord : ?pos:FilePos.pos -> annotmap -> annotmap * QmlAst.pat
420
421 (** {6 Record pattern constructors}*)
422 (** [record ~extend annotmap fields] make a pattern on record with a
423 list of fields. The first element of generated pattern it's the
424 first element of the list. If [extend] is setted to [true] then
425 the pattern is extensible, by default extend is [false]. *)
426 val record : ?pos:FilePos.pos -> ?extend:bool ->
427 annotmap -> (string * QmlAst.pat) list -> annotmap * QmlAst.pat
428
429 val tuple : ?pos:FilePos.pos -> annotmap -> QmlAst.pat list -> annotmap * QmlAst.pat
430
431 (** [some annotmap gamma pat] make a pattern on [{ some = pat
432 }]. This pattern it's typed by type [option]. *)
433 val some : ?pos:FilePos.pos -> annotmap -> gamma -> QmlAst.pat -> annotmap * QmlAst.pat
434
435 (** Make a pattern on [{none}]. This pattern it's typed by type
436 [option('a)] else if [ty] is given the it's typed by
437 [option(ty)].*)
438 val none : ?pos:FilePos.pos -> ?ty:QmlAst.ty -> annotmap -> gamma -> annotmap * QmlAst.pat
439
440 val bool : ?pos:FilePos.pos -> bool -> annotmap -> gamma -> annotmap * QmlAst.pat
441
442 (** [match_option annotmap gamma matched patsome ok_expr ko_expr]
443 generate a match on option, like this in OPA syntax :
444
445 [{
446 match matched with
447 | { some = patsome } -> ok_expr
448 | {none} -> ko_expr
449 }]
450
451 @param matched Expression to match. This expression must be type of
452 option.
453 @param patsome Pattern in some.
454 @param ok_expr Expression when match success.
455 @param ko_expr Expression when match failed.
456 @return (annotmap, match expression).
457 *)
458 val match_option : ?pos:FilePos.pos -> annotmap -> gamma -> QmlAst.expr -> QmlAst.pat
459 -> QmlAst.expr -> QmlAst.expr -> annotmap * QmlAst.expr
460
461 val list : ?pos:FilePos.pos -> annotmap -> QmlAst.pat list -> annotmap * QmlAst.pat
462
463 val ifthenelse : ?pos:FilePos.pos -> annotmap -> gamma -> QmlAst.expr
464 -> QmlAst.expr -> QmlAst.expr -> annotmap * QmlAst.expr
465 end
466
467 module TypedCode :
468 sig
469 val copy_new : annotmap_old:QmlAst.annotmap -> QmlAst.annotmap -> QmlAst.code -> QmlAst.annotmap * QmlAst.code
470 val copy_new_when_possible : annotmap_old:QmlAst.annotmap -> QmlAst.annotmap -> QmlAst.code -> QmlAst.annotmap * QmlAst.code
471 end
472
473 module UntypedExprWithLabel :
474 sig
475 (**
476 Usage of this module is discouraged: by giving explicitly an
477 annotation, you are able to break the strong invariant that
478 annotations are unique. It's generally better to use functions
479 from UntypedExpr (maybe followed by a call to the typer) or from
480 TypedExpr.
481 *)
482
483 val ident : ?label:Annot.label -> QmlAst.ident -> QmlAst.expr
484 val const : ?label:Annot.label -> QmlAst.const_expr -> QmlAst.expr
485 val int : ?label:Annot.label -> int -> QmlAst.expr
486 val float : ?label:Annot.label -> float -> QmlAst.expr
487 val string : ?label:Annot.label -> string -> QmlAst.expr
488
489 val directive : ?label:Annot.label -> QmlAst.qml_directive -> QmlAst.expr list -> QmlAst.ty list -> QmlAst.expr
490
491 val letin : ?label:Annot.label -> (QmlAst.ident * QmlAst.expr) list -> QmlAst.expr -> QmlAst.expr
492 val letrecin : ?label:Annot.label -> (QmlAst.ident * QmlAst.expr) list -> QmlAst.expr -> QmlAst.expr
493 val lambda1 : ?label:Annot.label -> QmlAst.ident -> QmlAst.expr -> QmlAst.expr
494 val lambda : ?label:Annot.label -> QmlAst.ident list -> QmlAst.expr -> QmlAst.expr
495 val apply1 : ?label:Annot.label -> QmlAst.expr -> QmlAst.expr -> QmlAst.expr
496 val apply : ?label:Annot.label -> QmlAst.expr -> QmlAst.expr list -> QmlAst.expr
497 val may_apply : ?label:Annot.label -> QmlAst.expr -> QmlAst.expr list -> QmlAst.expr
498 val match_ : ?label:Annot.label -> QmlAst.expr -> (QmlAst.pat * QmlAst.expr) list -> QmlAst.expr
499 val record : ?label:Annot.label -> (string * QmlAst.expr) list -> QmlAst.expr
500 val dot : ?label:Annot.label -> QmlAst.expr -> string -> QmlAst.expr
501 val extendrecord : ?label:Annot.label -> string -> QmlAst.expr -> QmlAst.expr -> QmlAst.expr
502 val bypass : ?label:Annot.label -> BslKey.t -> QmlAst.expr
503 val coerce : ?label:Annot.label -> QmlAst.expr -> QmlAst.ty -> QmlAst.expr
504 end
505
506 type stateful_constructor =
507 < make : QmlAst.expr -> QmlAst.ty -> QmlAst.expr;
508 make_from_annot : QmlAst.expr -> Annot.t -> QmlAst.expr;
509 (* make_from_annotated : 'a. expr0 -> 'a QmlAst.annot -> QmlAst.expr; *)
510 copy : QmlAst.expr -> QmlAst.expr;
511 shallow_copy_new : annotmap_old:QmlAst.annotmap -> QmlAst.expr -> QmlAst.expr;
512 shallow_copy : QmlAst.expr -> QmlAst.expr;
513 copy_new : annotmap_old:QmlAst.annotmap -> QmlAst.expr -> QmlAst.expr;
514
515 directive : QmlAst.qml_directive -> QmlAst.expr list -> QmlAst.ty list -> QmlAst.expr ;
516
517 ident : QmlAst.ident -> QmlAst.ty -> QmlAst.expr;
518 ident_from_annot : QmlAst.ident -> Annot.t -> QmlAst.expr;
519 (* ident_from_annotated : 'a. QmlAst.ident -> 'a QmlAst.annot -> QmlAst.expr; *)
520 const : QmlAst.const_expr -> QmlAst.expr;
521 unit : QmlAst.expr;
522 cheap_void : QmlAst.expr;
523 int : int -> QmlAst.expr;
524 float : float -> QmlAst.expr;
525 string : string -> QmlAst.expr;
526
527 coerce : QmlAst.expr -> QmlAst.ty -> QmlAst.expr;
528 letin : QmlAst.ident -> QmlAst.expr -> QmlAst.expr -> QmlAst.expr;
529 letins : (QmlAst.ident * QmlAst.expr) list -> QmlAst.expr -> QmlAst.expr;
530 letrec : QmlAst.ident -> QmlAst.expr -> QmlAst.expr -> QmlAst.expr;
531 letrecs : (QmlAst.ident * QmlAst.expr) list -> QmlAst.expr -> QmlAst.expr;
532 lambda : (QmlAst.ident * QmlAst.ty) list -> QmlAst.expr -> QmlAst.expr;
533 lambda_from_annot : (QmlAst.ident * Annot.t) list -> QmlAst.expr -> QmlAst.expr;
534 (* lambda_from_annotated : 'a. (QmlAst.ident * 'a QmlAst.annot) list -> QmlAst.expr -> QmlAst.expr; *)
535 apply : QmlAst.expr -> QmlAst.expr list -> QmlAst.expr;
536
537 record : (string * QmlAst.expr) list -> QmlAst.expr;
538 dot : QmlAst.expr -> string -> QmlAst.expr;
539
540 list : QmlAst.expr list -> QmlAst.expr;
541 false_: QmlAst.expr;
542 true_: QmlAst.expr;
543 bool : bool -> QmlAst.expr ;
544
545 opa_tuple_2 : QmlAst.expr * QmlAst.expr -> QmlAst.expr;
546
547 some : QmlAst.expr -> QmlAst.expr;
548 none : ?ty:QmlAst.ty -> unit -> QmlAst.expr;
549
550 bypass : BslKey.t -> QmlAst.ty -> QmlAst.expr;
551 bypass_from_annot : BslKey.t -> Annot.t -> QmlAst.expr;
552 (* bypass_from_annotated : 'a. BslKey.t -> 'a QmlAst.annot -> QmlAst.expr; *)
553 bypass_from_typer : BslKey.t -> (BslKey.t -> QmlAst.ty option) -> QmlAst.expr;
554
555 patvar : QmlAst.ident -> QmlAst.ty -> QmlAst.pat;
556 patany : QmlAst.pat;
557 patlist : QmlAst.pat list -> QmlAst.pat;
558 match_ : QmlAst.expr -> (QmlAst.pat * QmlAst.expr) list -> QmlAst.expr;
559
560 typed : bool;
561 gamma : TypedExpr.gamma;
562
563 tyname : string -> QmlAst.ty list -> QmlAst.ty;
564 tyoption : QmlAst.ty -> QmlAst.ty;
565 tylist : QmlAst.ty -> QmlAst.ty;
566
567 add_to_gamma : QmlAst.ident -> QmlAst.expr -> unit
568 >
569
570 val make_typed_cons :
571 TypedExpr.gamma -> TypedExpr.annotmap ->
572 stateful_constructor * (unit -> (TypedExpr.gamma * TypedExpr.annotmap))
573 (**
574 [make_cons gamma annotmap] allow you to write the same thing you would
575 with calls to TypedExpr in a much more concise way since the object
576 you create contains and updates the annotmap itself
577
578 If you want to build the term [error("blabla")], you would do:
579 {[[let cons, get_state = TypedExpr.make_cons gamma annotmap in
580 let e = cons#apply (cons#ident ident <<string -> 'a>>) (cons#string "blabla") in
581 get_state (), e ]}
582
583 Instead of
584 {[ let annotmap, ident = TypedExpr.ident annotmap ident <<string -> 'a>> in
585 let annotmap, string_expr = TypedExpr.string annotmap "blabla" in
586 let annotmap, app = TypedExpr.apply gamma annotmap ident string_expr in
587 (gamma, annotmap), app
588 ]}
589 @return the constructor object and a function that gives you the new state
590 *)
591
592 val untyped_cons : stateful_constructor
593 (**
594 same interface as [make_typed_cons _ _] except that the built terms
595 are untyped
596 *)
597
598 val make_cons :
599 typed:bool -> TypedExpr.gamma -> TypedExpr.annotmap ->
600 stateful_constructor * (unit -> (TypedExpr.gamma * TypedExpr.annotmap))
601 (**
602 Choose between the typed constructor and the untyped constructor
603 depending on the [typed] argument
604 *)
Something went wrong with that request. Please try again.