| 1 |
abate |
4 |
(* Typed abstract syntax *)
|
| 2 |
|
|
|
| 3 |
abate |
5 |
(* Some sub-expression may have to be type-checked several times.
|
| 4 |
|
|
We first build the ``skeleton'' of the typed ast
|
| 5 |
|
|
(basically the parsed ast with types and patterns replaced with there
|
| 6 |
|
|
internal representation), then type check it.
|
| 7 |
|
|
|
| 8 |
|
|
The exp_typ and br_typ fields are updated to capture all the possible
|
| 9 |
|
|
values than can result from the expression or flow to the branch
|
| 10 |
|
|
*)
|
| 11 |
|
|
|
| 12 |
abate |
4 |
open Location
|
| 13 |
|
|
|
| 14 |
|
|
type tpat = Patterns.node
|
| 15 |
|
|
type ttyp = Types.node
|
| 16 |
|
|
|
| 17 |
abate |
5 |
type texpr = { loc : Location.loc;
|
| 18 |
|
|
mutable exp_typ : Types.descr;
|
| 19 |
|
|
exp_descr : texpr';
|
| 20 |
|
|
fv : string list
|
| 21 |
|
|
}
|
| 22 |
abate |
4 |
and texpr' =
|
| 23 |
|
|
(* CDuce is a Lambda-calculus ... *)
|
| 24 |
|
|
| Var of string
|
| 25 |
|
|
| Apply of texpr * texpr
|
| 26 |
|
|
| Abstraction of abstr
|
| 27 |
|
|
|
| 28 |
|
|
(* Data constructors *)
|
| 29 |
|
|
| Cst of Types.const
|
| 30 |
|
|
| Pair of texpr * texpr
|
| 31 |
|
|
| RecordLitt of (Types.label * texpr) list
|
| 32 |
|
|
|
| 33 |
|
|
(* Data destructors *)
|
| 34 |
|
|
| Op of op * texpr
|
| 35 |
|
|
| Match of texpr * branches
|
| 36 |
|
|
| Map of texpr * branches
|
| 37 |
|
|
|
| 38 |
|
|
and abstr = {
|
| 39 |
|
|
fun_name : string option;
|
| 40 |
abate |
5 |
fun_iface : (ttyp * ttyp) list;
|
| 41 |
abate |
4 |
fun_body : branches
|
| 42 |
|
|
}
|
| 43 |
|
|
|
| 44 |
|
|
and branches = branch list
|
| 45 |
abate |
5 |
and branch =
|
| 46 |
|
|
{ mutable used : bool;
|
| 47 |
|
|
mutable br_typ : Types.descr;
|
| 48 |
|
|
br_pat : tpat;
|
| 49 |
|
|
br_body : texpr }
|
| 50 |
abate |
4 |
|
| 51 |
|
|
and op = string
|
| 52 |
|
|
|