| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
open Util |
| 12 |
open Names |
| 13 |
|
| 14 |
let make_dir l = DirPath.make (List.rev_map Id.of_string l) |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
let rocq = Libnames.rocq_init_string |
| 20 |
|
| 21 |
let init_dir = [ rocq; "Init"] |
| 22 |
|
| 23 |
let jmeq_module_name = ["Stdlib";"Logic";"JMeq"] |
| 24 |
|
| 25 |
let table : GlobRef.t CString.Map.t ref = |
| 26 |
Summary.ref ~name:"rocqlib_registered" CString.Map.empty |
| 27 |
|
| 28 |
let get_lib_refs () = |
| 29 |
CString.Map.bindings !table |
| 30 |
|
| 31 |
let has_ref s = CString.Map.mem s !table |
| 32 |
|
| 33 |
let check_ref s gr = |
| 34 |
match CString.Map.find s !table with |
| 35 |
| r -> GlobRef.UserOrd.equal r gr |
| 36 |
| exception Not_found -> false |
| 37 |
|
| 38 |
let check_ind_ref s ind = check_ref s (GlobRef.IndRef ind) |
| 39 |
|
| 40 |
exception NotFoundRef of string |
| 41 |
|
| 42 |
let () = CErrors.register_handler (function |
| 43 |
| NotFoundRef s -> Some Pp.(str "not found in table: " ++ str s) |
| 44 |
| _ -> None) |
| 45 |
|
| 46 |
let lib_ref s = |
| 47 |
try CString.Map.find s !table |
| 48 |
with Not_found -> raise (NotFoundRef s) |
| 49 |
|
| 50 |
let lib_ref_opt s = CString.Map.find_opt s !table |
| 51 |
|
| 52 |
let add_ref s c = |
| 53 |
table := CString.Map.add s c !table |
| 54 |
|
| 55 |
let cache_ref (s,c) = |
| 56 |
add_ref s c |
| 57 |
|
| 58 |
let (inRocqlibRef : Libobject.locality * (string * GlobRef.t) -> Libobject.obj) = |
| 59 |
let open Libobject in |
| 60 |
declare_object @@ object_with_locality "COQLIBREF" |
| 61 |
~cache:cache_ref |
| 62 |
~subst:(Some ident_subst_function) |
| 63 |
~discharge:(fun x -> x) |
| 64 |
|
| 65 |
|
| 66 |
let register_ref local s c = |
| 67 |
Lib.add_leaf @@ inRocqlibRef (local,(s,c)) |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
let check_required_library d = |
| 75 |
let dir = make_dir d in |
| 76 |
try |
| 77 |
let _ : Mod_declarations.module_body = Global.lookup_module (ModPath.MPfile dir) in |
| 78 |
() |
| 79 |
with Not_found -> |
| 80 |
let in_current_dir = match Lib.current_mp () with |
| 81 |
| MPfile dp -> DirPath.equal dir dp |
| 82 |
| _ -> false |
| 83 |
in |
| 84 |
if not in_current_dir then |
| 85 |
CErrors.user_err Pp.(str "Library " ++ DirPath.print dir |
| 86 |
++ str " has to be required first.") |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
let logic_module_name = init_dir@["Logic"] |
| 93 |
|
| 94 |
let datatypes_module_name = init_dir@["Datatypes"] |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
type rocq_sigma_data = { |
| 100 |
proj1 : GlobRef.t; |
| 101 |
proj2 : GlobRef.t; |
| 102 |
elim : GlobRef.t; |
| 103 |
intro : GlobRef.t; |
| 104 |
typ : GlobRef.t } |
| 105 |
|
| 106 |
let build_sigma_gen str = |
| 107 |
{ typ = lib_ref ("core." ^ str ^ ".type"); |
| 108 |
elim = lib_ref ("core." ^ str ^ ".rect"); |
| 109 |
intro = lib_ref ("core." ^ str ^ ".intro"); |
| 110 |
proj1 = lib_ref ("core." ^ str ^ ".proj1"); |
| 111 |
proj2 = lib_ref ("core." ^ str ^ ".proj2"); |
| 112 |
} |
| 113 |
|
| 114 |
let build_prod () = build_sigma_gen "prod" |
| 115 |
let build_sigma () = build_sigma_gen "sig" |
| 116 |
let build_sigma_type () = build_sigma_gen "sigT" |
| 117 |
|
| 118 |
|
| 119 |
type rocq_eq_data = { |
| 120 |
eq : GlobRef.t; |
| 121 |
ind : GlobRef.t; |
| 122 |
refl : GlobRef.t; |
| 123 |
sym : GlobRef.t; |
| 124 |
trans: GlobRef.t; |
| 125 |
congr: GlobRef.t } |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
let build_eqdata_gen str = { |
| 130 |
eq = lib_ref ("core." ^ str ^ ".type"); |
| 131 |
ind = lib_ref ("core." ^ str ^ ".ind"); |
| 132 |
refl = lib_ref ("core." ^ str ^ ".refl"); |
| 133 |
sym = lib_ref ("core." ^ str ^ ".sym"); |
| 134 |
trans = lib_ref ("core." ^ str ^ ".trans"); |
| 135 |
congr = lib_ref ("core." ^ str ^ ".congr"); |
| 136 |
} |
| 137 |
|
| 138 |
let build_rocq_eq_data () = build_eqdata_gen "eq" |
| 139 |
let build_rocq_jmeq_data () = build_eqdata_gen "JMeq" |
| 140 |
let build_rocq_identity_data () = build_eqdata_gen "identity" |