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