annotate lab4/dict.mli @ 1:b5139af1a420 tip basis

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