| 1 |
(* -*-tuareg-*- *) |
| 2 |
|
| 3 |
(* Caml script to include for debugging the checker. |
| 4 |
Usage: from the checker/ directory launch ocaml toplevel and then |
| 5 |
type #use"include";; |
| 6 |
This command loads the relevant modules, defines some pretty |
| 7 |
printers, and provides functions to interactively check modules |
| 8 |
(mainly run_l and norec). |
| 9 |
*) |
| 10 |
|
| 11 |
#cd "..";; |
| 12 |
#directory "lib";; |
| 13 |
#directory "kernel";; |
| 14 |
#directory "checker";; |
| 15 |
#directory "+threads";; |
| 16 |
|
| 17 |
#load "unix.cma";; |
| 18 |
#load"threads.cma";; |
| 19 |
#load "str.cma";; |
| 20 |
#load "gramlib.cma";; |
| 21 |
(*#load "toplevellib.cma";; |
| 22 |
|
| 23 |
#directory "/usr/lib/ocaml/compiler-libs/utils";; |
| 24 |
let _ = Clflags.recursive_types:=true;; |
| 25 |
*) |
| 26 |
#load "check.cma";; |
| 27 |
|
| 28 |
open Typeops;; |
| 29 |
open Check;; |
| 30 |
|
| 31 |
open Pp;; |
| 32 |
open CErrors;; |
| 33 |
open Util;; |
| 34 |
open Names;; |
| 35 |
open Term;; |
| 36 |
open Environ;; |
| 37 |
open Declarations;; |
| 38 |
open Mod_checking;; |
| 39 |
open Cic;; |
| 40 |
|
| 41 |
let pr_id id = str(string_of_id id) |
| 42 |
let pr_na = function Name id -> pr_id id | _ -> str"_";; |
| 43 |
let prdp dp = pp(str(string_of_dirpath dp));; |
| 44 |
(* |
| 45 |
let prc c = pp(Himsg.pr_lconstr_env (Check.get_env()) c);; |
| 46 |
let prcs cs = prc (Declarations.force cs);; |
| 47 |
let pru u = pp(str(Univ.string_of_universe u));;*) |
| 48 |
let pru u = pp(Univ.pr_uni u);; |
| 49 |
let prlab l = pp(str(string_of_label l));; |
| 50 |
let prid id = pp(pr_id id);; |
| 51 |
let prcon c = pp(Indtypes.prcon c);; |
| 52 |
let prkn kn = pp(Indtypes.prkn kn);; |
| 53 |
|
| 54 |
|
| 55 |
let prus g = pp(Univ.pr_universes g);; |
| 56 |
|
| 57 |
let prcstrs c = |
| 58 |
let g = Univ.merge_constraints c Univ.initial_universes in |
| 59 |
pp(Univ.pr_universes g);; |
| 60 |
(*let prcstrs c = pp(Univ.pr_constraints c);; *) |
| 61 |
(* |
| 62 |
let prenvu e = |
| 63 |
let u = universes e in |
| 64 |
let pu = |
| 65 |
str "UNIVERSES:"++fnl()++str" "++hov 0 (Univ.pr_universes u) ++fnl() in |
| 66 |
pp pu;; |
| 67 |
|
| 68 |
let prenv e = |
| 69 |
let ctx1 = named_context e in |
| 70 |
let ctx2 = rel_context e in |
| 71 |
let pe = |
| 72 |
hov 1 (str"[" ++ |
| 73 |
prlist_with_sep spc (fun (na,_,_) -> pr_id na) (List.rev ctx1)++ |
| 74 |
str"]") ++ spc() ++ |
| 75 |
hov 1 (str"[" ++ |
| 76 |
prlist_with_sep spc (fun (na,_,_) -> pr_na na) (List.rev ctx2)++ |
| 77 |
str"]") in |
| 78 |
pp pe;; |
| 79 |
*) |
| 80 |
|
| 81 |
(* |
| 82 |
let prsub s = |
| 83 |
let string_of_mp mp = |
| 84 |
let s = string_of_mp mp in |
| 85 |
(match mp with MPbound _ -> "#bound."|_->"")^s in |
| 86 |
pp (hv 0 |
| 87 |
(fold_subst |
| 88 |
(fun msid mp strm -> |
| 89 |
str "S " ++ str (debug_string_of_msid msid) ++ str " |-> " ++ |
| 90 |
str (string_of_mp mp) ++ fnl() ++ strm) |
| 91 |
(fun mbid mp strm -> |
| 92 |
str"B " ++ str (debug_string_of_mbid mbid) ++ str " |-> " ++ |
| 93 |
str (string_of_mp mp) ++ fnl() ++ strm) |
| 94 |
(fun mp1 mp strm -> |
| 95 |
str"P " ++ str (string_of_mp mp1) ++ str " |-> " ++ |
| 96 |
str (string_of_mp mp) ++ fnl() ++ strm) s (mt()))) |
| 97 |
;; |
| 98 |
*) |
| 99 |
|
| 100 |
#install_printer prid;; |
| 101 |
#install_printer prcon;; |
| 102 |
#install_printer prlab;; |
| 103 |
#install_printer prdp;; |
| 104 |
#install_printer prkn;; |
| 105 |
#install_printer pru;; |
| 106 |
(* |
| 107 |
#install_printer prc;; |
| 108 |
#install_printer prcs;; |
| 109 |
*) |
| 110 |
#install_printer prcstrs;; |
| 111 |
(*#install_printer prus;;*) |
| 112 |
(*#install_printer prenv;;*) |
| 113 |
(*#install_printer prenvu;; |
| 114 |
#install_printer prsub;;*) |
| 115 |
|
| 116 |
Checker.init_with_argv [|"";"-coqlib";"."|];; |
| 117 |
Flags.quiet := false;; |
| 118 |
Flags.debug := true;; |
| 119 |
Sys.catch_break true;; |
| 120 |
|
| 121 |
let module_of_file f = |
| 122 |
let (_,mb,_,_) = Obj.magic ((intern_from_file f).library_compiled) in |
| 123 |
(mb:Cic.module_body) |
| 124 |
;; |
| 125 |
let deref_mod md s = |
| 126 |
let l = match md.mod_expr with |
| 127 |
Struct(NoFunctor l) -> l |
| 128 |
| FullStruct -> |
| 129 |
(match md.mod_type with |
| 130 |
NoFunctor l -> l) |
| 131 |
in |
| 132 |
List.assoc (label_of_id(id_of_string s)) l |
| 133 |
;; |
| 134 |
(* |
| 135 |
let mod_access m fld = |
| 136 |
match m.mod_expr with |
| 137 |
Some(SEBstruct l) -> List.assoc fld l |
| 138 |
| _ -> failwith "bad structure type" |
| 139 |
;; |
| 140 |
*) |
| 141 |
let parse_dp s = |
| 142 |
make_dirpath(List.rev_map id_of_string (Str.split(Str.regexp"\\.") s)) |
| 143 |
;; |
| 144 |
let parse_sp s = |
| 145 |
let l = List.rev (Str.split(Str.regexp"\\.") s) in |
| 146 |
{dirpath=List.tl l; basename=List.hd l};; |
| 147 |
let parse_kn s = |
| 148 |
let l = List.rev (Str.split(Str.regexp"\\.") s) in |
| 149 |
let dp = make_dirpath(List.map id_of_string(List.tl l)) in |
| 150 |
make_kn(MPfile dp) empty_dirpath (label_of_id (id_of_string (List.hd l))) |
| 151 |
;; |
| 152 |
let parse_con s = |
| 153 |
let l = List.rev (Str.split(Str.regexp"\\.") s) in |
| 154 |
let dp = make_dirpath(List.map id_of_string(List.tl l)) in |
| 155 |
make_con(MPfile dp) empty_dirpath (label_of_id (id_of_string (List.hd l))) |
| 156 |
;; |
| 157 |
let get_mod dp = |
| 158 |
lookup_module dp (Safe_typing.get_env()) |
| 159 |
;; |
| 160 |
let get_mod_type dp = |
| 161 |
lookup_modtype dp (Safe_typing.get_env()) |
| 162 |
;; |
| 163 |
let get_cst kn = |
| 164 |
lookup_constant kn (Safe_typing.get_env()) |
| 165 |
;; |
| 166 |
|
| 167 |
let read_mod s f = |
| 168 |
let lib = intern_from_file (parse_dp s,f) in |
| 169 |
((Obj.magic lib.library_compiled): |
| 170 |
dir_path * |
| 171 |
module_body * |
| 172 |
(dir_path * Digest.t) list);; |
| 173 |
|
| 174 |
|
| 175 |
let expln f x = |
| 176 |
try f x |
| 177 |
with UserError(_,strm) as e -> |
| 178 |
msgnl strm; raise e |
| 179 |
|
| 180 |
let admit_l l = |
| 181 |
let l = List.map parse_sp l in |
| 182 |
Check.recheck_library ~admit:l ~check:l;; |
| 183 |
let run_l l = |
| 184 |
Check.recheck_library ~admit:[] ~check:(List.map parse_sp l);; |
| 185 |
let norec q = |
| 186 |
Check.recheck_library ~norec:[parse_sp q] ~admit:[] ~check:[];; |
| 187 |
|
| 188 |
(* |
| 189 |
admit_l["Bool";"OrderedType";"DecidableType"];; |
| 190 |
run_l["FSetInterface"];; |
| 191 |
*) |