| 1 |
(* Typed abstract syntax *)
|
| 2 |
|
| 3 |
(* 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 |
open Location
|
| 13 |
|
| 14 |
type tpat = Patterns.node
|
| 15 |
type ttyp = Types.node
|
| 16 |
|
| 17 |
type texpr = { exp_loc : loc;
|
| 18 |
mutable exp_typ : Types.descr;
|
| 19 |
exp_descr : texpr';
|
| 20 |
}
|
| 21 |
and texpr' =
|
| 22 |
| DebugTyper of ttyp
|
| 23 |
|
| 24 |
(* CDuce is a Lambda-calculus ... *)
|
| 25 |
| Var of string
|
| 26 |
| Apply of texpr * texpr
|
| 27 |
| Abstraction of abstr
|
| 28 |
|
| 29 |
(* Data constructors *)
|
| 30 |
| Cst of Types.const
|
| 31 |
| Pair of texpr * texpr
|
| 32 |
| RecordLitt of (Types.label * texpr) list
|
| 33 |
|
| 34 |
(* Data destructors *)
|
| 35 |
| Op of string * texpr list
|
| 36 |
| Match of texpr * branches
|
| 37 |
| Map of texpr * branches
|
| 38 |
| Dot of (texpr * Types.label)
|
| 39 |
|
| 40 |
and abstr = {
|
| 41 |
fun_name : string option;
|
| 42 |
fun_iface : (Types.descr * Types.descr) list;
|
| 43 |
fun_body : branches;
|
| 44 |
fun_typ : Types.descr;
|
| 45 |
fun_fv : string list;
|
| 46 |
}
|
| 47 |
|
| 48 |
and branches = {
|
| 49 |
mutable br_typ : Types.descr;
|
| 50 |
br_accept : Types.descr;
|
| 51 |
br_branches: branch list;
|
| 52 |
|
| 53 |
mutable br_compiled : compiled_branches option;
|
| 54 |
}
|
| 55 |
and branch = {
|
| 56 |
mutable br_used : bool;
|
| 57 |
br_pat : tpat;
|
| 58 |
br_body : texpr
|
| 59 |
}
|
| 60 |
and compiled_branches = {
|
| 61 |
actions : Patterns.Compile.actions;
|
| 62 |
rhs : (texpr * (string * int) list) array
|
| 63 |
}
|