Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 607 lines (481 sloc) 25.366 kB
fccc685 Initial open-source release
MLstate authored
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 char : char -> QmlAst.expr
143 val unit : unit -> QmlAst.expr
144 val _false: unit -> QmlAst.expr
145 val _true: unit -> QmlAst.expr
146 val bool : bool -> QmlAst.expr
147
148 val letin : (QmlAst.ident * QmlAst.expr) list -> QmlAst.expr -> QmlAst.expr
149 val letrecin : (QmlAst.ident * QmlAst.expr) list -> QmlAst.expr -> QmlAst.expr
150 val stupid_letin : (QmlAst.ident * QmlAst.expr) list -> QmlAst.expr -> QmlAst.expr (* construct LetIn even when list is empty *)
151 val lambda : QmlAst.ident list -> QmlAst.expr -> QmlAst.expr
152 val apply : QmlAst.expr -> QmlAst.expr list -> QmlAst.expr
153
154 val may_lambda : QmlAst.ident list -> QmlAst.expr -> QmlAst.expr
155 val may_apply : QmlAst.expr -> QmlAst.expr list -> QmlAst.expr
156 (** same as [lambda] or [apply], except when the list is empty. In this case, they
157 just return the expression *)
158
159 val match_ : QmlAst.expr -> (QmlAst.pat * QmlAst.expr) list -> QmlAst.expr
160 val record : (string * QmlAst.expr) list -> QmlAst.expr
161 val dot : QmlAst.expr -> string -> QmlAst.expr
162 val extendrecord : string -> QmlAst.expr -> QmlAst.expr -> QmlAst.expr
163 val bypass : BslKey.t -> QmlAst.expr
164 val restricted_bypass : pass:string -> BslKey.t -> QmlAst.expr
165 val coerce : QmlAst.expr -> QmlAst.ty -> QmlAst.expr
166 val directive : QmlAst.qml_directive -> QmlAst.expr list -> QmlAst.ty list -> QmlAst.expr
167
168 (* parser : wait for type unification *)
169
170 (** {6 Patterns}*)
171
172 val patconst : QmlAst.const_expr -> QmlAst.pat
173 val patvar : QmlAst.ident -> QmlAst.pat
174 val patany : unit -> QmlAst.pat (** unit -> refresh annotation ! *)
175 val patemptyrecord : unit -> QmlAst.pat
176 val pat_opa_tuple : QmlAst.pat list -> QmlAst.pat
177 val patcoerce : QmlAst.pat -> QmlAst.ty -> QmlAst.pat
178 val pattrue: unit -> QmlAst.pat
179 val patfalse:unit -> QmlAst.pat
180 val patsome: QmlAst.ident -> QmlAst.pat
181 val patnone:unit -> QmlAst.pat
182
183
184 (** Sugar : produce patern on record (the terminaison can be '...' or closed) *)
185 (** use fold_right : keep the order *)
186 val patrecord : ?rowvar:QmlAst.pat_rowvar -> (string * QmlAst.pat) list -> QmlAst.pat
187 val patextendrecord : (string * QmlAst.pat) list -> QmlAst.pat
188
189 (** construct the pattern matching a list with the given subpatterns *)
190 val patlist : QmlAst.pat list -> QmlAst.pat
191
192 (** Helper to generate | x -> where x is fresh *)
193 val patfreshvar : string -> QmlAst.ident * QmlAst.pat
194
195 (** Other sugar *)
196 val list : QmlAst.expr list -> QmlAst.expr
197 val qml_tuple : QmlAst.expr list -> QmlAst.expr
198 val opa_tuple : QmlAst.expr list -> QmlAst.expr
199
200 (** if sugar *)
201 val ifthenelse : QmlAst.expr -> QmlAst.expr -> QmlAst.expr -> QmlAst.expr
202 end
203
204 (** UnValRec : (ex Triple Val Rec) : see the documentation in qmlAst.ml *)
205 module UnValRec :
206 sig
207 (** creates an unvalrec (cf. QmlAst ) *)
208 val make : ( QmlAst.ident * QmlAst.expr ) list -> QmlAst.unvalrec
209
210 (** sometime, there is no need to create the full unvalrec, but just some part of it *)
211 val letrec : ( QmlAst.ident * QmlAst.expr ) list -> QmlAst.expr
212
213 (** from a NewVal(Rec), gives a Let(Rec)In, the fiels list, and a rebuilder function ``à la Louis'' *)
214 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
215
216 (** Extra Higher Level API : transformation of code in a unvalrec passe *)
217 val unvalrec_code : QmlAst.code -> QmlAst.code
218
219 (** from an expr, makes a NewVal [("_", expr)] and a rebuilder function *)
220 val make_code_elt : QmlAst.expr -> QmlAst.code_elt * (QmlAst.code_elt -> QmlAst.expr)
221
222 (** same, but the rebuilder function is from maped_code_elt (expecting a M_NewVal) *)
223 val make_code_elt_maped : QmlAst.expr -> QmlAst.code_elt * (('a, 'b) QmlAst.maped_code_elt -> 'a)
224 end
225
226 module TypedExpr :
227 sig
228 type annotmap = QmlAst.annotmap
229 type gamma = QmlTypes.Env.t
230
231 (**
232 <!> Do not use the annotation of the given expression.
233 Prefer using a specilized constructor
234 *)
235 val make : ?pos:FilePos.pos -> annotmap -> QmlAst.expr -> QmlAst.ty -> annotmap * QmlAst.expr
236
237 (**
238 Refresh the annotations in the given expression
239 Copies only the restricted annot, i.e. ty, original, position (drop precise_let, precise_index)
240 *)
241 val copy : annotmap -> QmlAst.expr -> annotmap * QmlAst.expr
242 val shallow_copy_new : annotmap_old:annotmap -> annotmap -> QmlAst.expr -> annotmap * QmlAst.expr
243 val shallow_copy : annotmap -> QmlAst.expr -> annotmap * QmlAst.expr
244 val shallow_copys : annotmap -> QmlAst.expr list -> annotmap * QmlAst.expr list
245 (** Copy annotations of an expression from an old to a new annotmap *)
246 val copy_new : annotmap_old:annotmap -> annotmap -> QmlAst.expr -> annotmap * QmlAst.expr
247 val copy_new_when_possible : annotmap_old:annotmap -> annotmap -> QmlAst.expr -> annotmap * QmlAst.expr
248 (** A special version with a trace (source -> dest intmap) *)
249 val copy_with_trace : annotmap -> QmlAst.expr -> (annotmap * QmlAnnotMap.trace) * QmlAst.expr
250
251 (**
252 natives types
253 *)
254 val ty_string : QmlAst.ty
255 val ty_int : QmlAst.ty
256 val ty_float : QmlAst.ty
257
258 val bypass : ?pos:FilePos.pos -> annotmap -> BslKey.t -> QmlAst.ty -> annotmap * QmlAst.expr
259 val ident : ?pos:FilePos.pos -> annotmap -> QmlAst.ident -> QmlAst.ty -> annotmap * QmlAst.expr
260 val const : ?pos:FilePos.pos -> annotmap -> QmlAst.const_expr -> annotmap * QmlAst.expr
261 val unit : ?pos:FilePos.pos -> annotmap -> annotmap * QmlAst.expr
262 val cheap_void : ?pos:FilePos.pos -> annotmap -> gamma -> annotmap * QmlAst.expr
263 val int : ?pos:FilePos.pos -> annotmap -> int -> annotmap * QmlAst.expr
264 val float : ?pos:FilePos.pos -> annotmap -> float -> annotmap * QmlAst.expr
265 val string : ?pos:FilePos.pos -> annotmap -> string -> annotmap * QmlAst.expr
266
267 (* try to guess positions and types from given expressions, when possible *)
268 val coerce : annotmap -> QmlAst.expr -> QmlAst.ty -> annotmap * QmlAst.expr
269 val letin : annotmap -> (QmlAst.ident * QmlAst.expr) list -> QmlAst.expr -> annotmap * QmlAst.expr
270 val letrecin : annotmap -> (QmlAst.ident * QmlAst.expr) list -> QmlAst.expr -> annotmap * QmlAst.expr
271
272 (** lambda [(x : tx); (y : ty)] (m : t) : tx, ty -> t *)
273 val lambda : ?pos:FilePos.pos -> annotmap -> (QmlAst.ident * QmlAst.ty) list -> QmlAst.expr -> annotmap * QmlAst.expr
274 (** same as lambda, but when the list is empty, returns [e] and not [-> e] *)
275 val may_lambda : ?pos:FilePos.pos -> annotmap -> (QmlAst.ident * QmlAst.ty) list -> QmlAst.expr -> annotmap * QmlAst.expr
276
277 (** apply (m : tx, ty -> t) [(x : tx); (y : ty)] : t *)
278 val apply : gamma -> annotmap -> QmlAst.expr -> QmlAst.expr list -> annotmap * QmlAst.expr
279 (** [apply_partial] allows to apply not enough arguments or to apply one group of arguments
280 when the type has two arrows *)
281 val apply_partial : gamma -> annotmap -> QmlAst.expr -> QmlAst.expr list -> annotmap * QmlAst.expr
282 (** same as [may_lambda] *)
283 val may_apply : gamma -> annotmap -> QmlAst.expr -> QmlAst.expr list -> annotmap * QmlAst.expr
284
285 val apply_ty : ?pos:FilePos.pos -> annotmap -> QmlAst.expr -> QmlAst.expr list -> QmlAst.ty -> annotmap * QmlAst.expr
286
287 val record : ?pos:FilePos.pos -> ?extend:bool -> annotmap -> (string * QmlAst.expr) list -> annotmap * QmlAst.expr
288 val sum_element : ?pos:FilePos.pos -> ?ty:QmlAst.ty -> annotmap -> (string * QmlAst.expr) list -> annotmap * QmlAst.expr
289 val dot : gamma -> annotmap -> QmlAst.expr -> string -> annotmap * QmlAst.expr
290
291 (**{6 Match constructors}*)
292 (** [match_ annotmap matched l] make a match. [matched] it's matched
293 expression. And [l] is a list of patterns and expressions. All
294 pattern, expression is an entry of constructed match. The type
295 of match is the type of the first expression on [l]. [l] can't
296 be empty.
297
298 Warning : Types of expressions in [l] must be able to unify, but
299 is not checked *)
300 val match_ : ?pos:FilePos.pos -> annotmap -> QmlAst.expr -> (QmlAst.pat * QmlAst.expr) list
301 -> annotmap * QmlAst.expr
302
303 (**
304 Same than [match_] but use the given [ty] instead of taking the
305 type of the first production.
306 *)
307 val match_ty : ?pos:FilePos.pos -> annotmap -> QmlAst.expr -> (QmlAst.pat * QmlAst.expr) list
308 -> QmlAst.ty -> annotmap * QmlAst.expr
309
310 (* TODO: *)
311 (* val extendrecord : annotmap -> string -> QmlAst.expr -> QmlAst.expr -> annotmap * QmlAst.expr *)
312
313 (**
314 Use the module [QmlDirective] to guess the type of the node
315 *)
316 val directive: ?pos:FilePos.pos -> annotmap -> QmlAst.qml_directive -> QmlAst.expr list -> QmlAst.ty list -> annotmap * QmlAst.expr
317
318 (**
319 Do not use [QmlDirective] fot guessing the type of the node,
320 but use the given ty instead.
321 *)
322 val directive_ty: ?pos:FilePos.pos -> annotmap -> QmlAst.qml_directive -> QmlAst.expr list -> QmlAst.ty list -> QmlAst.ty -> annotmap * QmlAst.expr
323 val directive_id: ?pos:FilePos.pos -> annotmap -> QmlAst.qml_directive -> QmlAst.expr -> annotmap * QmlAst.expr
324
325 val _false:?pos:FilePos.pos -> annotmap * gamma -> annotmap * QmlAst.expr
326 val _true: ?pos:FilePos.pos -> annotmap * gamma -> annotmap * QmlAst.expr
327 val bool: ?pos:FilePos.pos -> annotmap * gamma -> bool -> annotmap * QmlAst.expr
328
329 val _false_no_named_type:?pos:FilePos.pos -> annotmap * gamma -> annotmap * QmlAst.expr
330 val _true_no_named_type: ?pos:FilePos.pos -> annotmap * gamma -> annotmap * QmlAst.expr
331 val bool_no_named_type: ?pos:FilePos.pos -> annotmap * gamma -> bool -> annotmap * QmlAst.expr
332
333 val opa_tuple_2 :
334 ?pos:FilePos.pos -> annotmap * gamma -> QmlAst.expr * QmlAst.expr -> annotmap * QmlAst.expr
335
336 val lambda_coerce : annotmap -> QmlAst.ident -> QmlAst.ty (* of ident *) -> QmlAst.expr -> annotmap * QmlAst.expr
337
338 (** {6 List constructors} *)
339 (** Generate a qml list reversed compare to the given list. *)
340 val rev_list : ?pos:FilePos.pos -> ?ty:QmlAst.ty -> annotmap * gamma -> QmlAst.expr list
341 -> annotmap * QmlAst.expr
342
343 (** Like that [make_rev_list], but generated list isn't reversed. *)
344 val list : ?pos:FilePos.pos -> ?ty:QmlAst.ty -> annotmap * gamma -> QmlAst.expr list -> annotmap * QmlAst.expr
345
346 (** Construct a list from a function [f] that able to create a typed
347 expression with an ['a], and from an ['a list]. Constructed qml
348 list is reversed compared to the given list. Optional [ty]
349 argument is type of generated qml list, by default it's a
350 variant.
351
352 WARNING : For consistency [f] must be generated typed expression
353 with comparable types, but [make_rev_list] doesn't check
354 that. *)
355 val rev_list_map :
356 ?pos:FilePos.pos -> ?ty:QmlAst.ty ->
357 (annotmap -> 'a -> annotmap * QmlAst.expr) ->
358 (annotmap * gamma) -> 'a list -> annotmap * QmlAst.expr
359
360 (** Like that [make_rev_list], but generated list isn't reversed. *)
361 val list_map :
362 ?pos:FilePos.pos -> ?ty:QmlAst.ty ->
363 (annotmap -> 'a -> annotmap * QmlAst.expr) ->
364 (annotmap * gamma) -> 'a list -> annotmap * QmlAst.expr
365
366 (** {Option constructors}*)
367 (** [some expr] Generate an [option] expression, like that in Opa
368 Syntax : [{some = expr}] *)
369 val some : ?pos:FilePos.pos -> annotmap -> gamma -> QmlAst.expr -> annotmap * QmlAst.expr
370
371 (** Generate an [option] expression, like that in Opa Syntax :
372 [{none}]. [ty] optional argument it's the type of option, if it
373 not given it's a type variable. *)
374 val none : ?pos:FilePos.pos -> ?ty:QmlAst.ty -> annotmap -> gamma -> annotmap * QmlAst.expr
375
376 val tagged_string : ?pos:FilePos.pos -> annotmap -> string -> QmlAst.tagged_string_kind -> annotmap * QmlAst.expr
377
378 end
379
380 (** Typed pattern and match constructor module
381
382 @author Quentin Bourgerie
383
384 Warning : I'm not sure of typing on field (needs review)
385 *)
386 module TypedPat :
387 sig
388 (**{6 Shortcut types} *)
389
390 type annotmap = QmlAst.annotmap
391
392 type gamma = QmlTypes.Env.t
393
394 (** same behaviour as in TypedExpr *)
395 val copy : annotmap -> QmlAst.pat -> annotmap * QmlAst.pat
396 val copy_new_when_possible : annotmap_old:annotmap -> annotmap -> QmlAst.pat -> annotmap * QmlAst.pat
397
398 (**{6 Basic constructors}*)
399 (**
400 [patmake annotmap pat0 ty] Make a typed pattern from a untyped
401 pattern ([pat]) and a type ([ty]). Returns updated annotmap and
402 typed pattern.
403 <!> The annotation of pat is not used, it is refreshed
404 *)
405 val make : ?pos:FilePos.pos -> annotmap -> QmlAst.pat -> QmlAst.ty -> annotmap * QmlAst.pat
406
407 (** Make a any typed pattern. If [ty] is not given, type is a type
408 variable *)
409 val any : ?pos:FilePos.pos -> ?ty:QmlAst.ty -> annotmap -> annotmap * QmlAst.pat
410
411 (** [patvar annotmap ident ty] Make a typed variable pattern from an
412 [ident] and a type ([ty]). Returns updated annotmap and typed
413 pattern.
414
415 Warning : [patvar] don't check if the given [ident] is
416 typed by [ty]. *)
417 val var : ?pos:FilePos.pos -> annotmap -> QmlAst.ident -> QmlAst.ty -> annotmap * QmlAst.pat
418
419 (** Make a typed pattern on empty record *)
420 val emptyrecord : ?pos:FilePos.pos -> annotmap -> annotmap * QmlAst.pat
421
422 (** {6 Record pattern constructors}*)
423 (** [record ~extend annotmap fields] make a pattern on record with a
424 list of fields. The first element of generated pattern it's the
425 first element of the list. If [extend] is setted to [true] then
426 the pattern is extensible, by default extend is [false]. *)
427 val record : ?pos:FilePos.pos -> ?extend:bool ->
428 annotmap -> (string * QmlAst.pat) list -> annotmap * QmlAst.pat
429
430 val tuple : ?pos:FilePos.pos -> annotmap -> QmlAst.pat list -> annotmap * QmlAst.pat
431
432 (** [some annotmap gamma pat] make a pattern on [{ some = pat
433 }]. This pattern it's typed by type [option]. *)
434 val some : ?pos:FilePos.pos -> annotmap -> gamma -> QmlAst.pat -> annotmap * QmlAst.pat
435
436 (** Make a pattern on [{none}]. This pattern it's typed by type
437 [option('a)] else if [ty] is given the it's typed by
438 [option(ty)].*)
439 val none : ?pos:FilePos.pos -> ?ty:QmlAst.ty -> annotmap -> gamma -> annotmap * QmlAst.pat
440
441 val bool : ?pos:FilePos.pos -> bool -> annotmap -> gamma -> annotmap * QmlAst.pat
442
443 (** [match_option annotmap gamma matched patsome ok_expr ko_expr]
444 generate a match on option, like this in OPA syntax :
445
446 [{
447 match matched with
448 | { some = patsome } -> ok_expr
449 | {none} -> ko_expr
450 }]
451
452 @param matched Expression to match. This expression must be type of
453 option.
454 @param patsome Pattern in some.
455 @param ok_expr Expression when match success.
456 @param ko_expr Expression when match failed.
457 @return (annotmap, match expression).
458 *)
459 val match_option : ?pos:FilePos.pos -> annotmap -> gamma -> QmlAst.expr -> QmlAst.pat
460 -> QmlAst.expr -> QmlAst.expr -> annotmap * QmlAst.expr
461
462 val list : ?pos:FilePos.pos -> annotmap -> QmlAst.pat list -> annotmap * QmlAst.pat
463
464 val ifthenelse : ?pos:FilePos.pos -> annotmap -> gamma -> QmlAst.expr
465 -> QmlAst.expr -> QmlAst.expr -> annotmap * QmlAst.expr
466 end
467
468 module TypedCode :
469 sig
470 val copy_new : annotmap_old:QmlAst.annotmap -> QmlAst.annotmap -> QmlAst.code -> QmlAst.annotmap * QmlAst.code
471 val copy_new_when_possible : annotmap_old:QmlAst.annotmap -> QmlAst.annotmap -> QmlAst.code -> QmlAst.annotmap * QmlAst.code
472 end
473
474 module UntypedExprWithLabel :
475 sig
476 (**
477 Usage of this module is discouraged: by giving explicitly an
478 annotation, you are able to break the strong invariant that
479 annotations are unique. It's generally better to use functions
480 from UntypedExpr (maybe followed by a call to the typer) or from
481 TypedExpr.
482 *)
483
484 val ident : ?label:Annot.label -> QmlAst.ident -> QmlAst.expr
485 val const : ?label:Annot.label -> QmlAst.const_expr -> QmlAst.expr
486 val int : ?label:Annot.label -> int -> QmlAst.expr
487 val float : ?label:Annot.label -> float -> QmlAst.expr
488 val string : ?label:Annot.label -> string -> QmlAst.expr
489 val char : ?label:Annot.label -> char -> QmlAst.expr
490
491 val directive : ?label:Annot.label -> QmlAst.qml_directive -> QmlAst.expr list -> QmlAst.ty list -> QmlAst.expr
492
493 val letin : ?label:Annot.label -> (QmlAst.ident * QmlAst.expr) list -> QmlAst.expr -> QmlAst.expr
494 val letrecin : ?label:Annot.label -> (QmlAst.ident * QmlAst.expr) list -> QmlAst.expr -> QmlAst.expr
495 val lambda1 : ?label:Annot.label -> QmlAst.ident -> QmlAst.expr -> QmlAst.expr
496 val lambda : ?label:Annot.label -> QmlAst.ident list -> QmlAst.expr -> QmlAst.expr
497 val apply1 : ?label:Annot.label -> QmlAst.expr -> QmlAst.expr -> QmlAst.expr
498 val apply : ?label:Annot.label -> QmlAst.expr -> QmlAst.expr list -> QmlAst.expr
499 val may_apply : ?label:Annot.label -> QmlAst.expr -> QmlAst.expr list -> QmlAst.expr
500 val match_ : ?label:Annot.label -> QmlAst.expr -> (QmlAst.pat * QmlAst.expr) list -> QmlAst.expr
501 val record : ?label:Annot.label -> (string * QmlAst.expr) list -> QmlAst.expr
502 val dot : ?label:Annot.label -> QmlAst.expr -> string -> QmlAst.expr
503 val extendrecord : ?label:Annot.label -> string -> QmlAst.expr -> QmlAst.expr -> QmlAst.expr
504 val bypass : ?label:Annot.label -> BslKey.t -> QmlAst.expr
505 val coerce : ?label:Annot.label -> QmlAst.expr -> QmlAst.ty -> QmlAst.expr
506 end
507
508 type stateful_constructor =
509 < make : QmlAst.expr -> QmlAst.ty -> QmlAst.expr;
510 make_from_annot : QmlAst.expr -> Annot.t -> QmlAst.expr;
511 (* make_from_annotated : 'a. expr0 -> 'a QmlAst.annot -> QmlAst.expr; *)
512 copy : QmlAst.expr -> QmlAst.expr;
513 shallow_copy_new : annotmap_old:QmlAst.annotmap -> QmlAst.expr -> QmlAst.expr;
514 shallow_copy : QmlAst.expr -> QmlAst.expr;
515 copy_new : annotmap_old:QmlAst.annotmap -> QmlAst.expr -> QmlAst.expr;
516
517 directive : QmlAst.qml_directive -> QmlAst.expr list -> QmlAst.ty list -> QmlAst.expr ;
518
519 ident : QmlAst.ident -> QmlAst.ty -> QmlAst.expr;
520 ident_from_annot : QmlAst.ident -> Annot.t -> QmlAst.expr;
521 (* ident_from_annotated : 'a. QmlAst.ident -> 'a QmlAst.annot -> QmlAst.expr; *)
522 const : QmlAst.const_expr -> QmlAst.expr;
523 unit : QmlAst.expr;
524 cheap_void : QmlAst.expr;
525 int : int -> QmlAst.expr;
526 float : float -> QmlAst.expr;
527 string : string -> QmlAst.expr;
528
529 coerce : QmlAst.expr -> QmlAst.ty -> QmlAst.expr;
530 letin : QmlAst.ident -> QmlAst.expr -> QmlAst.expr -> QmlAst.expr;
531 letins : (QmlAst.ident * QmlAst.expr) list -> QmlAst.expr -> QmlAst.expr;
532 letrec : QmlAst.ident -> QmlAst.expr -> QmlAst.expr -> QmlAst.expr;
533 letrecs : (QmlAst.ident * QmlAst.expr) list -> QmlAst.expr -> QmlAst.expr;
534 lambda : (QmlAst.ident * QmlAst.ty) list -> QmlAst.expr -> QmlAst.expr;
535 lambda_from_annot : (QmlAst.ident * Annot.t) list -> QmlAst.expr -> QmlAst.expr;
536 (* lambda_from_annotated : 'a. (QmlAst.ident * 'a QmlAst.annot) list -> QmlAst.expr -> QmlAst.expr; *)
537 apply : QmlAst.expr -> QmlAst.expr list -> QmlAst.expr;
538
539 record : (string * QmlAst.expr) list -> QmlAst.expr;
540 dot : QmlAst.expr -> string -> QmlAst.expr;
541
542 list : QmlAst.expr list -> QmlAst.expr;
543 false_: QmlAst.expr;
544 true_: QmlAst.expr;
545 bool : bool -> QmlAst.expr ;
546
547 opa_tuple_2 : QmlAst.expr * QmlAst.expr -> QmlAst.expr;
548
549 some : QmlAst.expr -> QmlAst.expr;
550 none : ?ty:QmlAst.ty -> unit -> QmlAst.expr;
551
552 bypass : BslKey.t -> QmlAst.ty -> QmlAst.expr;
553 bypass_from_annot : BslKey.t -> Annot.t -> QmlAst.expr;
554 (* bypass_from_annotated : 'a. BslKey.t -> 'a QmlAst.annot -> QmlAst.expr; *)
555 bypass_from_typer : BslKey.t -> (BslKey.t -> QmlAst.ty option) -> QmlAst.expr;
556
557 patvar : QmlAst.ident -> QmlAst.ty -> QmlAst.pat;
558 patany : QmlAst.pat;
559 patlist : QmlAst.pat list -> QmlAst.pat;
560 match_ : QmlAst.expr -> (QmlAst.pat * QmlAst.expr) list -> QmlAst.expr;
561
562 typed : bool;
563 gamma : TypedExpr.gamma;
564
565 tyname : string -> QmlAst.ty list -> QmlAst.ty;
566 tyoption : QmlAst.ty -> QmlAst.ty;
567 tylist : QmlAst.ty -> QmlAst.ty;
568
569 add_to_gamma : QmlAst.ident -> QmlAst.expr -> unit
570 >
571
572 val make_typed_cons :
573 TypedExpr.gamma -> TypedExpr.annotmap ->
574 stateful_constructor * (unit -> (TypedExpr.gamma * TypedExpr.annotmap))
575 (**
576 [make_cons gamma annotmap] allow you to write the same thing you would
577 with calls to TypedExpr in a much more concise way since the object
578 you create contains and updates the annotmap itself
579
580 If you want to build the term [error("blabla")], you would do:
581 {[[let cons, get_state = TypedExpr.make_cons gamma annotmap in
582 let e = cons#apply (cons#ident ident <<string -> 'a>>) (cons#string "blabla") in
583 get_state (), e ]}
584
585 Instead of
586 {[ let annotmap, ident = TypedExpr.ident annotmap ident <<string -> 'a>> in
587 let annotmap, string_expr = TypedExpr.string annotmap "blabla" in
588 let annotmap, app = TypedExpr.apply gamma annotmap ident string_expr in
589 (gamma, annotmap), app
590 ]}
591 @return the constructor object and a function that gives you the new state
592 *)
593
594 val untyped_cons : stateful_constructor
595 (**
596 same interface as [make_typed_cons _ _] except that the built terms
597 are untyped
598 *)
599
600 val make_cons :
601 typed:bool -> TypedExpr.gamma -> TypedExpr.annotmap ->
602 stateful_constructor * (unit -> (TypedExpr.gamma * TypedExpr.annotmap))
603 (**
604 Choose between the typed constructor and the untyped constructor
605 depending on the [typed] argument
606 *)
Something went wrong with that request. Please try again.