| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
open Names |
| 14 |
|
| 15 |
module InfvInst = |
| 16 |
struct |
| 17 |
type t = bool array |
| 18 |
let empty = [||] |
| 19 |
let compare i1 i2 = CArray.compare Bool.compare i1 i2 |
| 20 |
let equal i1 i2 = Int.equal (compare i1 i2) 0 |
| 21 |
|
| 22 |
let generate actx = |
| 23 |
let names = UVars.AbstractContext.names actx in |
| 24 |
let quals = Array.length names.UVars.quals in |
| 25 |
let init n = |
| 26 |
let ans = Array.make quals true in |
| 27 |
let n = ref n in |
| 28 |
for i = 0 to quals - 1 do |
| 29 |
let b = !n mod 2 = 0 in |
| 30 |
ans.(i) <- b; |
| 31 |
n := !n / 2 |
| 32 |
done; |
| 33 |
ans |
| 34 |
in |
| 35 |
List.init (1 lsl quals) init |
| 36 |
|
| 37 |
let default actx = |
| 38 |
let names = UVars.AbstractContext.names actx in |
| 39 |
let quals = Array.length names.UVars.quals in |
| 40 |
Array.make quals true |
| 41 |
|
| 42 |
let ground inst = |
| 43 |
let qvars, _ = UVars.Instance.to_array inst in |
| 44 |
let map q = match q with |
| 45 |
| Sorts.Quality.QConstant (QProp | QSProp) -> false |
| 46 |
| Sorts.Quality.QConstant QType -> true |
| 47 |
| Sorts.Quality.QVar qv -> |
| 48 |
match Sorts.QVar.repr qv with |
| 49 |
| Var _ -> CErrors.anomaly (Pp.str "Non-ground instance") |
| 50 |
| Unif _ | Global _ -> true |
| 51 |
in |
| 52 |
Array.map map qvars |
| 53 |
|
| 54 |
let instantiate actx inst = |
| 55 |
let u = UVars.make_abstract_instance actx in |
| 56 |
let fl l = l in |
| 57 |
let fq q = match Sorts.QVar.var_index q with |
| 58 |
| None -> assert false |
| 59 |
| Some i -> |
| 60 |
if inst.(i) then Sorts.Quality.qtype |
| 61 |
else Sorts.Quality.qsprop |
| 62 |
in |
| 63 |
UVars.Instance.subst_fn (fq, fl) u |
| 64 |
|
| 65 |
let encode inst = |
| 66 |
if Array.for_all (fun b -> b) inst then None |
| 67 |
else |
| 68 |
let len = Array.length inst in |
| 69 |
Some (String.init len (fun i -> if inst.(i) then 'X' else 'O')) |
| 70 |
|
| 71 |
end |
| 72 |
|
| 73 |
type global = { glob : GlobRef.t; inst : InfvInst.t } |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
type kill_reason = |
| 86 |
| Ktype |
| 87 |
| Kprop |
| 88 |
| Kimplicit of global * int |
| 89 |
|
| 90 |
type sign = Keep | Kill of kill_reason |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
type signature = sign list |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
type ml_type = |
| 99 |
| Tarr of ml_type * ml_type |
| 100 |
| Tglob of global * ml_type list |
| 101 |
| Tvar of int |
| 102 |
| Tvar' of int |
| 103 |
| Tmeta of ml_meta |
| 104 |
| Tdummy of kill_reason |
| 105 |
| Tunknown |
| 106 |
| Taxiom |
| 107 |
|
| 108 |
and ml_meta = { id : int; mutable contents : ml_type option } |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
type ml_schema = int * ml_type |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
type inductive_kind = |
| 118 |
| Singleton |
| 119 |
| Coinductive |
| 120 |
| Standard |
| 121 |
| Record of global option list |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
type ml_ind_packet = { |
| 132 |
ip_typename : Id.t; |
| 133 |
ip_typename_ref : global; |
| 134 |
ip_consnames : Id.t array; |
| 135 |
ip_consnames_ref : global array; |
| 136 |
ip_logical : bool; |
| 137 |
ip_sign : signature; |
| 138 |
ip_vars : Id.t list; |
| 139 |
ip_types : (ml_type list) array |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
type equiv = |
| 145 |
| NoEquiv |
| 146 |
| Equiv of KerName.t |
| 147 |
| RenEquiv of string |
| 148 |
|
| 149 |
type ml_ind = { |
| 150 |
ind_kind : inductive_kind; |
| 151 |
ind_nparams : int; |
| 152 |
ind_packets : ml_ind_packet array; |
| 153 |
ind_equiv : equiv |
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
type ml_ident = |
| 159 |
| Dummy |
| 160 |
| Id of Id.t |
| 161 |
| Tmp of Id.t |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
type ml_branch = ml_ident list * ml_pattern * ml_ast |
| 175 |
|
| 176 |
and ml_ast = |
| 177 |
| MLrel of int |
| 178 |
| MLapp of ml_ast * ml_ast list |
| 179 |
| MLlam of ml_ident * ml_ast |
| 180 |
| MLletin of ml_ident * ml_ast * ml_ast |
| 181 |
| MLglob of global |
| 182 |
| MLcons of ml_type * global * ml_ast list |
| 183 |
| MLtuple of ml_ast list |
| 184 |
| MLcase of ml_type * ml_ast * ml_branch array |
| 185 |
| MLfix of int * Id.t array * ml_ast array |
| 186 |
| MLexn of string |
| 187 |
| MLdummy of kill_reason |
| 188 |
| MLaxiom of string |
| 189 |
| MLmagic of ml_ast |
| 190 |
| MLuint of Uint63.t |
| 191 |
| MLfloat of Float64.t |
| 192 |
| MLstring of Pstring.t |
| 193 |
| MLparray of ml_ast array * ml_ast |
| 194 |
|
| 195 |
and ml_pattern = |
| 196 |
| Pcons of global * ml_pattern list |
| 197 |
| Ptuple of ml_pattern list |
| 198 |
| Prel of int |
| 199 |
| Pwild |
| 200 |
| Pusual of global |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
type ml_decl = |
| 205 |
| Dind of ml_ind |
| 206 |
| Dtype of global * Id.t list * ml_type |
| 207 |
| Dterm of global * ml_ast * ml_type |
| 208 |
| Dfix of global array * ml_ast array * ml_type array |
| 209 |
|
| 210 |
type ml_spec = |
| 211 |
| Sind of ml_ind |
| 212 |
| Stype of global * Id.t list * ml_type option |
| 213 |
| Sval of global * ml_type |
| 214 |
|
| 215 |
type ml_specif = |
| 216 |
| Spec of ml_spec |
| 217 |
| Smodule of ml_module_type |
| 218 |
| Smodtype of ml_module_type |
| 219 |
|
| 220 |
and ml_module_type = |
| 221 |
| MTident of ModPath.t |
| 222 |
| MTfunsig of MBId.t * ml_module_type * ml_module_type |
| 223 |
| MTsig of ModPath.t * ml_module_sig |
| 224 |
| MTwith of ml_module_type * ml_with_declaration |
| 225 |
|
| 226 |
and ml_with_declaration = |
| 227 |
| ML_With_type of InfvInst.t * Id.t list * Id.t list * ml_type |
| 228 |
| ML_With_module of Id.t list * ModPath.t |
| 229 |
|
| 230 |
and ml_module_sig = (Id.t * ml_specif) list |
| 231 |
|
| 232 |
type ml_structure_elem = |
| 233 |
| SEdecl of ml_decl |
| 234 |
| SEmodule of ml_module |
| 235 |
| SEmodtype of ml_module_type |
| 236 |
|
| 237 |
and ml_module_expr = |
| 238 |
| MEident of ModPath.t |
| 239 |
| MEfunctor of MBId.t * ml_module_type * ml_module_expr |
| 240 |
| MEstruct of ModPath.t * ml_module_structure |
| 241 |
| MEapply of ml_module_expr * ml_module_expr |
| 242 |
|
| 243 |
and ml_module_structure = (Id.t * ml_structure_elem) list |
| 244 |
|
| 245 |
and ml_module = |
| 246 |
{ ml_mod_expr : ml_module_expr; |
| 247 |
ml_mod_type : ml_module_type } |
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
type ml_structure = (ModPath.t * ml_module_structure) list |
| 253 |
|
| 254 |
type ml_signature = (ModPath.t * ml_module_sig) list |
| 255 |
|
| 256 |
type unsafe_needs = { |
| 257 |
mldummy : bool; |
| 258 |
tdummy : bool; |
| 259 |
tunknown : bool; |
| 260 |
magic : bool |
| 261 |
} |
| 262 |
|
| 263 |
type 's language_descr = { |
| 264 |
keywords : Id.Set.t; |
| 265 |
|
| 266 |
|
| 267 |
file_suffix : string; |
| 268 |
file_naming : 's -> DirPath.t -> string; |
| 269 |
|
| 270 |
preamble : |
| 271 |
's -> Id.t -> Pp.t option -> DirPath.Set.t -> unsafe_needs -> |
| 272 |
Pp.t; |
| 273 |
pp_struct : 's -> ml_structure -> Pp.t; |
| 274 |
|
| 275 |
|
| 276 |
sig_suffix : string option; |
| 277 |
|
| 278 |
sig_preamble : |
| 279 |
's -> Id.t -> Pp.t option -> DirPath.Set.t -> unsafe_needs -> |
| 280 |
Pp.t; |
| 281 |
pp_sig : 's -> ml_signature -> Pp.t; |
| 282 |
|
| 283 |
|
| 284 |
pp_decl : 's -> ml_decl -> Pp.t; |
| 285 |
|
| 286 |
} |