typed.ml 1.34 KB
Newer Older
1
2
(* Typed abstract syntax *) 

3
4
5
6
7
8
9
10
11
(*  Some sub-expression may have to be type-checked several times.
    We first build the ``skeleton'' of the typed ast
    (basically the parsed ast with types and patterns replaced with there
    internal representation), then type check it.

    The exp_typ and br_typ fields are updated to capture all the possible
    values than can result from the expression or flow to the branch
*)

12
13
14
15
16
open Location

type tpat = Patterns.node
type ttyp = Types.node

17
type texpr  = { exp_loc : loc; 
18
19
20
		mutable exp_typ : Types.descr; 
		exp_descr : texpr';
	      }
21
and  texpr' = 
22
23
  | DebugTyper of ttyp

24
25
26
27
28
29
30
31
32
33
34
  (* CDuce is a Lambda-calculus ... *)
  | Var of string
  | Apply of texpr * texpr
  | Abstraction of abstr
      
  (* Data constructors *)
  | Cst of Types.const
  | Pair of texpr * texpr
  | RecordLitt of (Types.label * texpr) list
      
  (* Data destructors *)
35
  | Op of string * texpr list
36
37
  | Match of texpr * branches
  | Map of texpr * branches
38
  | Dot of (texpr * Types.label)
39
40
41

and abstr = { 
  fun_name : string option; 
42
  fun_iface : (Types.descr * Types.descr) list;
43
44
45
  fun_body : branches;
  fun_typ  : Types.descr;
  fun_fv   : string list;
46
47
}

48
49
and branches = { 
  mutable br_typ : Types.descr;
50
  br_accept : Types.descr;
51
52
53
54
55
56
57
  br_branches: branch list
}
and branch = { 
  mutable br_used : bool; 
  br_pat : tpat; 
  br_body :  texpr 
}