comparison ppc/dict.mli @ 0:bfdcc3820b32

Basis
author Mike Spivey <mike@cs.ox.ac.uk>
date Thu, 05 Oct 2017 08:04:15 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:bfdcc3820b32
1 (* ppc/dict.mli *)
2 (* Copyright (c) 2017 J. M. Spivey *)
3
4 (* This module defines the types that represent definitions and Pascal
5 types in the semantic analyser, and provides an abstract data type of
6 'environments' used in the analyser. There are also some functions that
7 operate on types. *)
8
9 (* |ident| -- type of identifiers *)
10 type ident
11
12 (* |intern| -- find an identifier *)
13 val intern : string -> ident
14
15 val spelling : ident -> string
16
17 val fId : ident -> Print.arg
18
19 (* |location| -- runtime locations *)
20 type location =
21 Local of int (* Local (offset) *)
22 | Global of Keiko.symbol (* Global (label) *)
23 | Nowhere (* Compile-time only *)
24
25 (* |Loc| -- printf format for locations *)
26 val fLoc: location -> Print.arg
27
28 (* |libid| -- type of picoPascal library procedures *)
29 type libid = ChrFun | OrdFun | PrintNum | PrintChar | PrintString
30 | NewLine | ReadChar | ExitProc | NewProc | ArgcFun | ArgvProc
31 | OpenIn | CloseIn | Operator of Keiko.op
32
33 val fLibId : libid -> Print.arg
34
35 (* |def_kind| -- kinds of definition *)
36 type def_kind =
37 ConstDef of int (* Constant (value) *)
38 | StringDef (* String constant *)
39 | TypeDef (* Type *)
40 | VarDef (* Variable *)
41 | CParamDef (* Value parameter *)
42 | VParamDef (* Var parameter *)
43 | FieldDef (* Field of record *)
44 | ProcDef (* Procedure *)
45 | PParamDef (* Proc parameter *)
46 | LibDef of libproc (* Lib proc (data) *)
47 | HoleDef of ptype ref (* Pending type *)
48 | DummyDef (* Dummy *)
49
50 (* |def| -- definitions in environment *)
51 and def =
52 { d_tag: ident; (* Name *)
53 d_kind: def_kind; (* Kind of object *)
54 d_type: ptype; (* Type *)
55 d_level: int; (* Static level *)
56 mutable d_addr: location } (* Run-time location *)
57
58 and basic_type = VoidType | IntType | CharType | BoolType | AddrType
59
60 (* |ptype| -- picoPascal types *)
61 and ptype =
62 { t_id: int; (* Unique identifier *)
63 t_guts: type_guts; (* Shape of the type *)
64 t_rep: Mach.metrics } (* Runtime representation *)
65
66 and type_guts =
67 BasicType of basic_type
68 | ArrayType of int * ptype
69 | RecordType of def list
70 | ProcType of proc_data
71 | PointerType of ptype ref
72
73 (* |proc_data| -- data about a procedure type *)
74 and proc_data =
75 { p_fparams: def list;
76 p_pcount : int;
77 p_result: ptype }
78
79 (* |libproc| -- data about a library procedure *)
80 and libproc =
81 { q_id: libid;
82 q_nargs: int;
83 q_argtypes: ptype list }
84
85 val offset_of : def -> int
86
87 val integer : ptype
88 val character : ptype
89 val boolean : ptype
90 val voidtype : ptype
91 val addrtype : ptype
92
93 type environment
94
95 (* |new_block| -- add a new top block *)
96 val new_block : environment -> environment
97
98 (* |add_block| -- add an existing def list as top block *)
99 val add_block : def list -> environment -> environment
100
101 (* |top_block| -- return top block as a def list *)
102 val top_block : environment -> def list
103
104 (* |define| -- add a definition, raise Exit if already declared *)
105 val define : def -> environment -> environment
106
107 (* |replace| -- replace tentative definition with final definition *)
108 val replace : def -> environment -> environment
109
110 (* |find_def| -- search a def list or raise Not_found *)
111 val find_def : ident -> def list -> def
112
113 (* |lookup| -- search an environment or raise Not_found *)
114 val lookup : ident -> environment -> def
115
116 (* |empty| -- empty environment *)
117 val empty : environment
118
119
120 (* Here are some functions that operate on types. The chief one is the
121 function |same_type| that tests whether two types are the same; it
122 uses name equivalence.
123
124 |match_args| checks two formal paramter lists for 'congurence', i.e.,
125 that corresponding parameters have the same types, and that value
126 parameters are not confused with var parameters. This test is used
127 for procedures that take other procedures as parameters. *)
128
129 (* |row| -- construct array type *)
130 val row : int -> ptype -> ptype
131
132 (* |mk_type| -- construct new (uniquely labelled) type *)
133 val mk_type : type_guts -> Mach.metrics -> ptype
134
135 (* |discrete| -- test if a type has discrete values *)
136 val discrete : ptype -> bool
137
138 (* |scalar| -- test if a type is simple *)
139 val scalar : ptype -> bool
140
141 (* |is_string| -- test if a type is 'array N of char' *)
142 val is_string : ptype -> bool
143
144 (* |bound| -- get bound of array type *)
145 val bound : ptype -> int
146
147 (* |is_pointer| -- test if a type is 'pointer to T' *)
148 val is_pointer : ptype -> bool
149
150 (* |base_type| -- get base type of pointer or array *)
151 val base_type : ptype -> ptype
152
153 (* |get_proc| -- get data from procedure type *)
154 val get_proc : ptype -> proc_data
155
156 (* |same_type| -- test two types for equality (name equivalence) *)
157 val same_type : ptype -> ptype -> bool
158
159 (* |match_args| -- test two formal parameter lists for congruence *)
160 val match_args : def list -> def list -> bool
161