| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
let protocol_version = "20240517" |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
type msg_format = Richpp of { width : int; depth : int } | Ppcmds |
| 18 |
let msg_format = ref (Richpp { width = 72; depth = max_int }) |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
open Util |
| 23 |
open Interface |
| 24 |
open Serialize |
| 25 |
open Xml_datatype |
| 26 |
|
| 27 |
|
| 28 |
module Xml_marshalling = struct |
| 29 |
|
| 30 |
let of_search_cst = function |
| 31 |
| Name_Pattern s -> |
| 32 |
constructor "search_cst" "name_pattern" [of_string s] |
| 33 |
| Type_Pattern s -> |
| 34 |
constructor "search_cst" "type_pattern" [of_string s] |
| 35 |
| SubType_Pattern s -> |
| 36 |
constructor "search_cst" "subtype_pattern" [of_string s] |
| 37 |
| In_Module m -> |
| 38 |
constructor "search_cst" "in_module" [of_list of_string m] |
| 39 |
| Include_Blacklist -> |
| 40 |
constructor "search_cst" "include_blacklist" [] |
| 41 |
let to_search_cst = do_match "search_cst" (fun s args -> match s with |
| 42 |
| "name_pattern" -> Name_Pattern (to_string (singleton args)) |
| 43 |
| "type_pattern" -> Type_Pattern (to_string (singleton args)) |
| 44 |
| "subtype_pattern" -> SubType_Pattern (to_string (singleton args)) |
| 45 |
| "in_module" -> In_Module (to_list to_string (singleton args)) |
| 46 |
| "include_blacklist" -> empty args; Include_Blacklist |
| 47 |
| x -> raise (Marshal_error("search",PCData x))) |
| 48 |
|
| 49 |
let of_rocq_object f ans = |
| 50 |
let prefix = of_list of_string ans.coq_object_prefix in |
| 51 |
let qualid = of_list of_string ans.coq_object_qualid in |
| 52 |
let obj = f ans.coq_object_object in |
| 53 |
Element ("coq_object", [], [prefix; qualid; obj]) |
| 54 |
|
| 55 |
let to_rocq_object f = function |
| 56 |
| Element ("coq_object", [], [prefix; qualid; obj]) -> |
| 57 |
let prefix = to_list to_string prefix in |
| 58 |
let qualid = to_list to_string qualid in |
| 59 |
let obj = f obj in { |
| 60 |
coq_object_prefix = prefix; |
| 61 |
coq_object_qualid = qualid; |
| 62 |
coq_object_object = obj; |
| 63 |
} |
| 64 |
| x -> raise (Marshal_error("coq_object",x)) |
| 65 |
|
| 66 |
let of_option_value = function |
| 67 |
| IntValue i -> constructor "option_value" "intvalue" [of_option of_int i] |
| 68 |
| BoolValue b -> constructor "option_value" "boolvalue" [of_bool b] |
| 69 |
| StringValue s -> constructor "option_value" "stringvalue" [of_string s] |
| 70 |
| StringOptValue s -> constructor "option_value" "stringoptvalue" [of_option of_string s] |
| 71 |
let to_option_value = do_match "option_value" (fun s args -> match s with |
| 72 |
| "intvalue" -> IntValue (to_option to_int (singleton args)) |
| 73 |
| "boolvalue" -> BoolValue (to_bool (singleton args)) |
| 74 |
| "stringvalue" -> StringValue (to_string (singleton args)) |
| 75 |
| "stringoptvalue" -> StringOptValue (to_option to_string (singleton args)) |
| 76 |
| x -> raise (Marshal_error("*value",PCData x))) |
| 77 |
|
| 78 |
let of_option_state s = |
| 79 |
Element ("option_state", [], [ |
| 80 |
of_bool s.opt_sync; |
| 81 |
of_bool s.opt_depr; |
| 82 |
of_option_value s.opt_value]) |
| 83 |
let to_option_state = function |
| 84 |
| Element ("option_state", [], [sync; depr; value]) -> { |
| 85 |
opt_sync = to_bool sync; |
| 86 |
opt_depr = to_bool depr; |
| 87 |
opt_value = to_option_value value } |
| 88 |
| x -> raise (Marshal_error("option_state",x)) |
| 89 |
|
| 90 |
let to_stateid = function |
| 91 |
| Element ("state_id",["val",i],[]) -> |
| 92 |
let id = int_of_string i in |
| 93 |
Stateid.of_int id |
| 94 |
| _ -> raise (Invalid_argument "to_state_id") |
| 95 |
|
| 96 |
let of_stateid i = Element ("state_id",["val",string_of_int (Stateid.to_int i)],[]) |
| 97 |
|
| 98 |
let to_routeid = function |
| 99 |
| Element ("route_id",["val",i],[]) -> |
| 100 |
let id = int_of_string i in id |
| 101 |
| _ -> raise (Invalid_argument "to_route_id") |
| 102 |
|
| 103 |
let of_routeid i = Element ("route_id",["val",string_of_int i],[]) |
| 104 |
|
| 105 |
let of_box (ppb : Pp.block_type) = let open Pp in match ppb with |
| 106 |
| Pp_hbox -> constructor "ppbox" "hbox" [] |
| 107 |
| Pp_vbox i -> constructor "ppbox" "vbox" [of_int i] |
| 108 |
| Pp_hvbox i -> constructor "ppbox" "hvbox" [of_int i] |
| 109 |
| Pp_hovbox i -> constructor "ppbox" "hovbox" [of_int i] |
| 110 |
|
| 111 |
let to_box = let open Pp in |
| 112 |
do_match "ppbox" (fun s args -> match s with |
| 113 |
| "hbox" -> empty args; Pp_hbox |
| 114 |
| "vbox" -> Pp_vbox (to_int (singleton args)) |
| 115 |
| "hvbox" -> Pp_hvbox (to_int (singleton args)) |
| 116 |
| "hovbox" -> Pp_hovbox (to_int (singleton args)) |
| 117 |
| x -> raise (Marshal_error("*ppbox",PCData x)) |
| 118 |
) |
| 119 |
|
| 120 |
let rec of_pp (pp : Pp.t) = let open Pp in match Pp.repr pp with |
| 121 |
| Ppcmd_empty -> constructor "ppdoc" "empty" [] |
| 122 |
| Ppcmd_string s -> constructor "ppdoc" "string" [of_string s] |
| 123 |
| Ppcmd_sized_string (n,s) -> constructor "ppdoc" "string" [of_string s] |
| 124 |
| Ppcmd_glue sl -> constructor "ppdoc" "glue" [of_list of_pp sl] |
| 125 |
| Ppcmd_box (bt,s) -> constructor "ppdoc" "box" [of_pair of_box of_pp (bt,s)] |
| 126 |
| Ppcmd_tag (t,s) -> constructor "ppdoc" "tag" [of_pair of_string of_pp (t,s)] |
| 127 |
| Ppcmd_print_break (i,j) |
| 128 |
-> constructor "ppdoc" "break" [of_pair of_int of_int (i,j)] |
| 129 |
| Ppcmd_force_newline -> constructor "ppdoc" "newline" [] |
| 130 |
| Ppcmd_comment cmd -> constructor "ppdoc" "comment" [of_list of_string cmd] |
| 131 |
|
| 132 |
|
| 133 |
let rec to_pp xpp = let open Pp in |
| 134 |
Pp.unrepr @@ |
| 135 |
do_match "ppdoc" (fun s args -> match s with |
| 136 |
| "empty" -> empty args; Ppcmd_empty |
| 137 |
| "string" -> Ppcmd_string (to_string (singleton args)) |
| 138 |
| "glue" -> Ppcmd_glue (to_list to_pp (singleton args)) |
| 139 |
| "box" -> let (bt,s) = to_pair to_box to_pp (singleton args) in |
| 140 |
Ppcmd_box(bt,s) |
| 141 |
| "tag" -> let (tg,s) = to_pair to_string to_pp (singleton args) in |
| 142 |
Ppcmd_tag(tg,s) |
| 143 |
| "break" -> let (i,j) = to_pair to_int to_int (singleton args) in |
| 144 |
Ppcmd_print_break(i, j) |
| 145 |
| "newline" -> Ppcmd_force_newline |
| 146 |
| "comment" -> Ppcmd_comment (to_list to_string (singleton args)) |
| 147 |
| x -> raise (Marshal_error("*ppdoc",PCData x)) |
| 148 |
) xpp |
| 149 |
|
| 150 |
let of_richpp x = Element ("richpp", [], [x]) |
| 151 |
|
| 152 |
|
| 153 |
let of_pp (pp : Pp.t) = |
| 154 |
match !msg_format with |
| 155 |
| Richpp { width; depth } -> |
| 156 |
of_richpp (Richpp.richpp_of_pp ~width ~depth pp) |
| 157 |
| Ppcmds -> of_pp pp |
| 158 |
|
| 159 |
let of_dbcontinue_opt opt = |
| 160 |
let code = match opt with |
| 161 |
| StepIn -> 0 |
| 162 |
| StepOver -> 1 |
| 163 |
| StepOut -> 2 |
| 164 |
| Continue -> 3 |
| 165 |
| Interrupt -> 4 |
| 166 |
in |
| 167 |
of_int code |
| 168 |
|
| 169 |
let to_dbcontinue_opt opt = |
| 170 |
match to_int opt with |
| 171 |
| 0 -> StepIn |
| 172 |
| 1 -> StepOver |
| 173 |
| 2 -> StepOut |
| 174 |
| 3 -> Continue |
| 175 |
| 4 -> Interrupt |
| 176 |
| _ -> failwith "to_dbcontinue_opt" |
| 177 |
|
| 178 |
let of_value f = function |
| 179 |
| Good x -> Element ("value", ["val", "good"], [f x]) |
| 180 |
| Fail (id,loc, msg) -> |
| 181 |
let id = of_stateid id in |
| 182 |
Element ("value", ["val", "fail"], [id; of_option of_loc loc; of_pp msg]) |
| 183 |
|
| 184 |
let to_value f = function |
| 185 |
| Element ("value", attrs, l) -> |
| 186 |
let ans = massoc "val" attrs in |
| 187 |
if ans = "good" then Good (f (singleton l)) |
| 188 |
else if ans = "fail" then |
| 189 |
let (id, loc, msg) = match l with [id; loc; msg] -> (id, loc, msg) | _ -> raise (Marshal_error("val",PCData "no id attribute")) in |
| 190 |
let id = to_stateid id in |
| 191 |
let loc = to_option to_loc loc in |
| 192 |
let msg = to_pp msg in |
| 193 |
Fail (id, loc, msg) |
| 194 |
else raise (Marshal_error("good or fail",PCData ans)) |
| 195 |
| x -> raise (Marshal_error("value",x)) |
| 196 |
|
| 197 |
let of_status s = |
| 198 |
let of_so = of_option of_string in |
| 199 |
let of_sl = of_list of_string in |
| 200 |
Element ("status", [], [ |
| 201 |
of_sl s.status_path; |
| 202 |
of_so s.status_proofname; |
| 203 |
of_sl s.status_allproofs; |
| 204 |
of_int s.status_proofnum; ]) |
| 205 |
let to_status = function |
| 206 |
| Element ("status", [], [path; name; prfs; pnum]) -> { |
| 207 |
status_path = to_list to_string path; |
| 208 |
status_proofname = to_option to_string name; |
| 209 |
status_allproofs = to_list to_string prfs; |
| 210 |
status_proofnum = to_int pnum; } |
| 211 |
| x -> raise (Marshal_error("status",x)) |
| 212 |
|
| 213 |
let of_evar s = Element ("evar", [], [PCData s.evar_info]) |
| 214 |
let to_evar = function |
| 215 |
| Element ("evar", [], data) -> { evar_info = raw_string data; } |
| 216 |
| x -> raise (Marshal_error("evar",x)) |
| 217 |
|
| 218 |
let of_goal g = |
| 219 |
let hyp = of_list of_pp g.goal_hyp in |
| 220 |
let ccl = of_pp g.goal_ccl in |
| 221 |
let id = of_string g.goal_id in |
| 222 |
let name = of_option of_string g.goal_name in |
| 223 |
Element ("goal", [], [id; hyp; ccl; name]) |
| 224 |
let to_goal = function |
| 225 |
| Element ("goal", [], [id; hyp; ccl; name]) -> |
| 226 |
let hyp = to_list to_pp hyp in |
| 227 |
let ccl = to_pp ccl in |
| 228 |
let id = to_string id in |
| 229 |
let name = to_option to_string name in |
| 230 |
{ goal_hyp = hyp; goal_ccl = ccl; goal_id = id; goal_name = name; } |
| 231 |
| x -> raise (Marshal_error("goal",x)) |
| 232 |
|
| 233 |
let of_goals g = |
| 234 |
let of_glist = of_list of_goal in |
| 235 |
let fg = of_list of_goal g.fg_goals in |
| 236 |
let bg = of_list (of_pair of_glist of_glist) g.bg_goals in |
| 237 |
let shelf = of_list of_goal g.shelved_goals in |
| 238 |
let given_up = of_list of_goal g.given_up_goals in |
| 239 |
Element ("goals", [], [fg; bg; shelf; given_up]) |
| 240 |
let to_goals = function |
| 241 |
| Element ("goals", [], [fg; bg; shelf; given_up]) -> |
| 242 |
let to_glist = to_list to_goal in |
| 243 |
let fg = to_list to_goal fg in |
| 244 |
let bg = to_list (to_pair to_glist to_glist) bg in |
| 245 |
let shelf = to_list to_goal shelf in |
| 246 |
let given_up = to_list to_goal given_up in |
| 247 |
{ fg_goals = fg; bg_goals = bg; shelved_goals = shelf; |
| 248 |
given_up_goals = given_up } |
| 249 |
| x -> raise (Marshal_error("goals",x)) |
| 250 |
|
| 251 |
let of_goal_flags f = |
| 252 |
let mode = of_string f.gf_mode in |
| 253 |
let fg = of_bool f.gf_fg in |
| 254 |
let bg = of_bool f.gf_bg in |
| 255 |
let shelved = of_bool f.gf_shelved in |
| 256 |
let given_up = of_bool f.gf_given_up in |
| 257 |
Element ("goal_flags", [], [mode; fg; bg; shelved; given_up]) |
| 258 |
let to_goal_flags = function |
| 259 |
| Element ("goal_flags", [], [mode; fg; bg; shelved; given_up]) -> |
| 260 |
{ gf_mode = to_string mode; |
| 261 |
gf_fg = to_bool fg; |
| 262 |
gf_bg = to_bool bg; |
| 263 |
gf_shelved = to_bool shelved; |
| 264 |
gf_given_up = to_bool given_up } |
| 265 |
| x -> raise (Marshal_error("goal_flags", x)) |
| 266 |
|
| 267 |
let of_rocq_info info = |
| 268 |
let version = of_string info.coqtop_version in |
| 269 |
let protocol = of_string info.protocol_version in |
| 270 |
let release = of_string info.release_date in |
| 271 |
let compile = of_string info.compile_date in |
| 272 |
Element ("coq_info", [], [version; protocol; release; compile]) |
| 273 |
let to_rocq_info = function |
| 274 |
| Element ("coq_info", [], [version; protocol; release; compile]) -> { |
| 275 |
coqtop_version = to_string version; |
| 276 |
protocol_version = to_string protocol; |
| 277 |
release_date = to_string release; |
| 278 |
compile_date = to_string compile; } |
| 279 |
| x -> raise (Marshal_error("coq_info",x)) |
| 280 |
|
| 281 |
end |
| 282 |
include Xml_marshalling |
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
module ReifType : sig |
| 287 |
|
| 288 |
type 'a val_t |
| 289 |
|
| 290 |
val unit_t : unit val_t |
| 291 |
val string_t : string val_t |
| 292 |
val int_t : int val_t |
| 293 |
val bool_t : bool val_t |
| 294 |
val xml_t : Xml_datatype.xml val_t |
| 295 |
|
| 296 |
val option_t : 'a val_t -> 'a option val_t |
| 297 |
val list_t : 'a val_t -> 'a list val_t |
| 298 |
val pair_t : 'a val_t -> 'b val_t -> ('a * 'b) val_t |
| 299 |
val union_t : 'a val_t -> 'b val_t -> ('a ,'b) union val_t |
| 300 |
|
| 301 |
val goals_t : goals val_t |
| 302 |
val goal_flags_t : goal_flags val_t |
| 303 |
val evar_t : evar val_t |
| 304 |
val state_t : status val_t |
| 305 |
val option_state_t : option_state val_t |
| 306 |
val option_value_t : option_value val_t |
| 307 |
val rocq_info_t : coq_info val_t |
| 308 |
val rocq_object_t : 'a val_t -> 'a coq_object val_t |
| 309 |
val state_id_t : state_id val_t |
| 310 |
val route_id_t : route_id val_t |
| 311 |
val search_cst_t : search_constraint val_t |
| 312 |
val pp_t : Pp.t val_t |
| 313 |
val db_cont_opt_t : db_continue_opt val_t |
| 314 |
|
| 315 |
val of_value_type : 'a val_t -> 'a -> xml |
| 316 |
val to_value_type : 'a val_t -> xml -> 'a |
| 317 |
|
| 318 |
val print : 'a val_t -> 'a -> string |
| 319 |
|
| 320 |
type value_type |
| 321 |
val erase : 'a val_t -> value_type |
| 322 |
val print_type : value_type -> string |
| 323 |
|
| 324 |
val document_type_encoding : (xml -> string) -> unit |
| 325 |
|
| 326 |
end = struct |
| 327 |
|
| 328 |
type _ val_t = |
| 329 |
| Unit : unit val_t |
| 330 |
| String : string val_t |
| 331 |
| Int : int val_t |
| 332 |
| Bool : bool val_t |
| 333 |
| Xml : Xml_datatype.xml val_t |
| 334 |
|
| 335 |
| Option : 'a val_t -> 'a option val_t |
| 336 |
| List : 'a val_t -> 'a list val_t |
| 337 |
| Pair : 'a val_t * 'b val_t -> ('a * 'b) val_t |
| 338 |
| Union : 'a val_t * 'b val_t -> ('a, 'b) union val_t |
| 339 |
|
| 340 |
| Goals : goals val_t |
| 341 |
| Goal_flags : goal_flags val_t |
| 342 |
| Evar : evar val_t |
| 343 |
| State : status val_t |
| 344 |
| Option_state : option_state val_t |
| 345 |
| Option_value : option_value val_t |
| 346 |
| Rocq_info : coq_info val_t |
| 347 |
| Rocq_object : 'a val_t -> 'a coq_object val_t |
| 348 |
| State_id : state_id val_t |
| 349 |
| Route_id : route_id val_t |
| 350 |
| Search_cst : search_constraint val_t |
| 351 |
| Pp : Pp.t val_t |
| 352 |
| DbContinueOpt : db_continue_opt val_t |
| 353 |
|
| 354 |
type value_type = Value_type : 'a val_t -> value_type |
| 355 |
|
| 356 |
let erase (x : 'a val_t) = Value_type x |
| 357 |
|
| 358 |
let unit_t = Unit |
| 359 |
let string_t = String |
| 360 |
let int_t = Int |
| 361 |
let bool_t = Bool |
| 362 |
let xml_t = Xml |
| 363 |
|
| 364 |
let option_t x = Option x |
| 365 |
let list_t x = List x |
| 366 |
let pair_t x y = Pair (x, y) |
| 367 |
let union_t x y = Union (x, y) |
| 368 |
|
| 369 |
let goals_t = Goals |
| 370 |
let goal_flags_t = Goal_flags |
| 371 |
let evar_t = Evar |
| 372 |
let state_t = State |
| 373 |
let option_state_t = Option_state |
| 374 |
let option_value_t = Option_value |
| 375 |
let rocq_info_t = Rocq_info |
| 376 |
let rocq_object_t x = Rocq_object x |
| 377 |
let state_id_t = State_id |
| 378 |
let route_id_t = Route_id |
| 379 |
let search_cst_t = Search_cst |
| 380 |
let pp_t = Pp |
| 381 |
let db_cont_opt_t = DbContinueOpt |
| 382 |
|
| 383 |
let of_value_type (ty : 'a val_t) : 'a -> xml = |
| 384 |
let rec convert : type a. a val_t -> a -> xml = function |
| 385 |
| Unit -> of_unit |
| 386 |
| Bool -> of_bool |
| 387 |
| Xml -> (fun x -> x) |
| 388 |
| String -> of_string |
| 389 |
| Int -> of_int |
| 390 |
| State -> of_status |
| 391 |
| Option_state -> of_option_state |
| 392 |
| Option_value -> of_option_value |
| 393 |
| Rocq_info -> of_rocq_info |
| 394 |
| Goals -> of_goals |
| 395 |
| Goal_flags -> of_goal_flags |
| 396 |
| Evar -> of_evar |
| 397 |
| List t -> (of_list (convert t)) |
| 398 |
| Option t -> (of_option (convert t)) |
| 399 |
| Rocq_object t -> (of_rocq_object (convert t)) |
| 400 |
| Pair (t1,t2) -> (of_pair (convert t1) (convert t2)) |
| 401 |
| Union (t1,t2) -> (of_union (convert t1) (convert t2)) |
| 402 |
| State_id -> of_stateid |
| 403 |
| Route_id -> of_routeid |
| 404 |
| Search_cst -> of_search_cst |
| 405 |
| Pp -> of_pp |
| 406 |
| DbContinueOpt -> of_dbcontinue_opt |
| 407 |
in |
| 408 |
convert ty |
| 409 |
|
| 410 |
let to_value_type (ty : 'a val_t) : xml -> 'a = |
| 411 |
let rec convert : type a. a val_t -> xml -> a = function |
| 412 |
| Unit -> to_unit |
| 413 |
| Bool -> to_bool |
| 414 |
| Xml -> (fun x -> x) |
| 415 |
| String -> to_string |
| 416 |
| Int -> to_int |
| 417 |
| State -> to_status |
| 418 |
| Option_state -> to_option_state |
| 419 |
| Option_value -> to_option_value |
| 420 |
| Rocq_info -> to_rocq_info |
| 421 |
| Goals -> to_goals |
| 422 |
| Goal_flags -> to_goal_flags |
| 423 |
| Evar -> to_evar |
| 424 |
| List t -> (to_list (convert t)) |
| 425 |
| Option t -> (to_option (convert t)) |
| 426 |
| Rocq_object t -> (to_rocq_object (convert t)) |
| 427 |
| Pair (t1,t2) -> (to_pair (convert t1) (convert t2)) |
| 428 |
| Union (t1,t2) -> (to_union (convert t1) (convert t2)) |
| 429 |
| State_id -> to_stateid |
| 430 |
| Route_id -> to_routeid |
| 431 |
| Search_cst -> to_search_cst |
| 432 |
| Pp -> to_pp |
| 433 |
| DbContinueOpt -> to_dbcontinue_opt |
| 434 |
in |
| 435 |
convert ty |
| 436 |
|
| 437 |
let pr_unit () = "" |
| 438 |
let pr_string s = Printf.sprintf "%S" s |
| 439 |
let pr_int i = string_of_int i |
| 440 |
let pr_bool b = Printf.sprintf "%B" b |
| 441 |
let pr_goal (g : goals) = |
| 442 |
if g.fg_goals = [] then |
| 443 |
if g.bg_goals = [] then "Proof completed." |
| 444 |
else |
| 445 |
let rec pr_focus _ = function |
| 446 |
| [] -> assert false |
| 447 |
| [lg, rg] -> Printf.sprintf "%i" (List.length lg + List.length rg) |
| 448 |
| (lg, rg) :: l -> |
| 449 |
Printf.sprintf "%i:%a" |
| 450 |
(List.length lg + List.length rg) pr_focus l in |
| 451 |
Printf.sprintf "Still focused: [%a]." pr_focus g.bg_goals |
| 452 |
else |
| 453 |
let pr_goal { goal_hyp = hyps; goal_ccl = goal } = |
| 454 |
"[" ^ String.concat "; " (List.map Pp.string_of_ppcmds hyps) ^ " |- " ^ |
| 455 |
Pp.string_of_ppcmds goal ^ "]" in |
| 456 |
String.concat " " (List.map pr_goal g.fg_goals) |
| 457 |
let pr_goal_flags (g : goal_flags) = |
| 458 |
Printf.sprintf "{ fg := %s; bg := %s; shelved := %s; given_up := %s }" |
| 459 |
(pr_bool g.gf_fg) (pr_bool g.gf_bg) (pr_bool g.gf_shelved) (pr_bool g.gf_given_up) |
| 460 |
let pr_evar (e : evar) = "[" ^ e.evar_info ^ "]" |
| 461 |
let pr_status (s : status) = |
| 462 |
let path = |
| 463 |
let l = String.concat "." s.status_path in |
| 464 |
"path=" ^ l ^ ";" in |
| 465 |
let name = match s.status_proofname with |
| 466 |
| None -> "no proof;" |
| 467 |
| Some n -> "proof = " ^ n ^ ";" in |
| 468 |
"Status: " ^ path ^ name |
| 469 |
let pr_rocq_info (i : coq_info) = "FIXME" |
| 470 |
let pr_option_value = function |
| 471 |
| IntValue None -> "none" |
| 472 |
| IntValue (Some i) -> string_of_int i |
| 473 |
| StringValue s -> s |
| 474 |
| StringOptValue None -> "none" |
| 475 |
| StringOptValue (Some s) -> s |
| 476 |
| BoolValue b -> if b then "true" else "false" |
| 477 |
let pr_option_state (s : option_state) = |
| 478 |
Printf.sprintf "sync := %b; depr := %b; value := %s\n" |
| 479 |
s.opt_sync s.opt_depr (pr_option_value s.opt_value) |
| 480 |
let pr_list pr l = "["^String.concat ";" (List.map pr l)^"]" |
| 481 |
let pr_option pr = function None -> "None" | Some x -> "Some("^pr x^")" |
| 482 |
let pr_rocq_object (o : 'a coq_object) = "FIXME" |
| 483 |
let pr_pair pr1 pr2 (a,b) = "("^pr1 a^","^pr2 b^")" |
| 484 |
let pr_union pr1 pr2 = function Inl x -> "Inl "^pr1 x | Inr x -> "Inr "^pr2 x |
| 485 |
let pr_state_id = Stateid.to_string |
| 486 |
let pr_db_continue_opt = function |
| 487 |
| StepIn -> "StepIn" |
| 488 |
| StepOver -> "StepOver" |
| 489 |
| StepOut -> "StepOut" |
| 490 |
| Continue -> "Continue" |
| 491 |
| Interrupt -> "Interrupt" |
| 492 |
|
| 493 |
let pr_search_cst = function |
| 494 |
| Name_Pattern s -> "Name_Pattern " ^ s |
| 495 |
| Type_Pattern s -> "Type_Pattern " ^ s |
| 496 |
| SubType_Pattern s -> "SubType_Pattern " ^ s |
| 497 |
| In_Module s -> "In_Module " ^ String.concat "." s |
| 498 |
| Include_Blacklist -> "Include_Blacklist" |
| 499 |
|
| 500 |
let pr_pp = Pp.string_of_ppcmds |
| 501 |
|
| 502 |
let rec print : type a. a val_t -> a -> string = function |
| 503 |
| Unit -> pr_unit |
| 504 |
| Bool -> pr_bool |
| 505 |
| String -> pr_string |
| 506 |
| Xml -> Xml_printer.to_string_fmt |
| 507 |
| Int -> pr_int |
| 508 |
| State -> pr_status |
| 509 |
| Option_state -> pr_option_state |
| 510 |
| Option_value -> pr_option_value |
| 511 |
| Search_cst -> pr_search_cst |
| 512 |
| Rocq_info -> pr_rocq_info |
| 513 |
| Goals -> pr_goal |
| 514 |
| Goal_flags -> pr_goal_flags |
| 515 |
| Evar -> pr_evar |
| 516 |
| List t -> (pr_list (print t)) |
| 517 |
| Option t -> (pr_option (print t)) |
| 518 |
| Rocq_object t -> pr_rocq_object |
| 519 |
| Pair (t1,t2) -> (pr_pair (print t1) (print t2)) |
| 520 |
| Union (t1,t2) -> (pr_union (print t1) (print t2)) |
| 521 |
| State_id -> pr_state_id |
| 522 |
| Route_id -> pr_int |
| 523 |
| Pp -> pr_pp |
| 524 |
| DbContinueOpt -> pr_db_continue_opt |
| 525 |
|
| 526 |
|
| 527 |
type 'a exists = bool |
| 528 |
|
| 529 |
let rec print_val_t : type a. a val_t -> string = function |
| 530 |
| Unit -> "unit" |
| 531 |
| Bool -> "bool" |
| 532 |
| String -> "string" |
| 533 |
| Xml -> "xml" |
| 534 |
| Int -> "int" |
| 535 |
| State -> assert(true : status exists); "Interface.status" |
| 536 |
| Option_state -> assert(true : option_state exists); "Interface.option_state" |
| 537 |
| Option_value -> assert(true : option_value exists); "Interface.option_value" |
| 538 |
| Search_cst -> assert(true : search_constraint exists); "Interface.search_constraint" |
| 539 |
| Rocq_info -> assert(true : coq_info exists); "Interface.coq_info" |
| 540 |
| Goals -> assert(true : goals exists); "Interface.goals" |
| 541 |
| Goal_flags -> assert(true : goal_flags exists); "Interface.goal_flags" |
| 542 |
| Evar -> assert(true : evar exists); "Interface.evar" |
| 543 |
| List t -> Printf.sprintf "(%s list)" (print_val_t t) |
| 544 |
| Option t -> Printf.sprintf "(%s option)" (print_val_t t) |
| 545 |
| Rocq_object t -> assert(true : 'a coq_object exists); |
| 546 |
Printf.sprintf "(%s Interface.coq_object)" (print_val_t t) |
| 547 |
| Pair (t1,t2) -> Printf.sprintf "(%s * %s)" (print_val_t t1) (print_val_t t2) |
| 548 |
| Union (t1,t2) -> assert(true : ('a,'b) CSig.union exists); |
| 549 |
Printf.sprintf "((%s, %s) CSig.union)" (print_val_t t1) (print_val_t t2) |
| 550 |
| State_id -> assert(true : Stateid.t exists); "Stateid.t" |
| 551 |
| Route_id -> assert(true : route_id exists); "route_id" |
| 552 |
| Pp -> assert(true : Pp.t exists); "Pp.t" |
| 553 |
| DbContinueOpt -> assert(true : db_continue_opt exists); "Interface.dbcontinue_opt" |
| 554 |
|
| 555 |
let print_type = function Value_type ty -> print_val_t ty |
| 556 |
|
| 557 |
let document_type_encoding pr_xml = |
| 558 |
Printf.printf "\n=== Data encoding by examples ===\n\n"; |
| 559 |
Printf.printf "%s:\n\n%s\n\n" (print_val_t Unit) (pr_xml (of_unit ())); |
| 560 |
Printf.printf "%s:\n\n%s\n%s\n\n" (print_val_t Bool) |
| 561 |
(pr_xml (of_bool true)) (pr_xml (of_bool false)); |
| 562 |
Printf.printf "%s:\n\n%s\n\n" (print_val_t String) (pr_xml (of_string "hello")); |
| 563 |
Printf.printf "%s:\n\n%s\n\n" (print_val_t Int) (pr_xml (of_int 256)); |
| 564 |
Printf.printf "%s:\n\n%s\n\n" (print_val_t State_id) (pr_xml (of_stateid Stateid.initial)); |
| 565 |
Printf.printf "%s:\n\n%s\n\n" (print_val_t (List Int)) (pr_xml (of_list of_int [3;4;5])); |
| 566 |
Printf.printf "%s:\n\n%s\n%s\n\n" (print_val_t (Option Int)) |
| 567 |
(pr_xml (of_option of_int (Some 3))) (pr_xml (of_option of_int None)); |
| 568 |
Printf.printf "%s:\n\n%s\n\n" (print_val_t (Pair (Bool,Int))) |
| 569 |
(pr_xml (of_pair of_bool of_int (false,3))); |
| 570 |
Printf.printf "%s:\n\n%s\n\n" (print_val_t (Union (Bool,Int))) |
| 571 |
(pr_xml (of_union of_bool of_int (Inl false))); |
| 572 |
Printf.printf "%s:\n\n%s\n\n" (print_val_t Pp) |
| 573 |
(pr_xml (of_pp Pp.(hv 3 (str "foo" ++ spc () ++ str "bar") ))); |
| 574 |
print_endline ("All other types are records represented by a node named like the OCaml\n"^ |
| 575 |
"type which contains a flattened n-tuple. We provide one example.\n"); |
| 576 |
Printf.printf "%s:\n\n%s\n\n" (print_val_t Option_state) |
| 577 |
(pr_xml (of_option_state { opt_sync = true; opt_depr = false; |
| 578 |
opt_value = IntValue (Some 37) })); |
| 579 |
|
| 580 |
end |
| 581 |
open ReifType |
| 582 |
|
| 583 |
|
| 584 |
let add_sty_t : add_sty val_t = |
| 585 |
pair_t (pair_t (pair_t (pair_t string_t int_t) (pair_t state_id_t bool_t)) int_t) |
| 586 |
(pair_t int_t int_t) |
| 587 |
let edit_at_sty_t : edit_at_sty val_t = state_id_t |
| 588 |
let query_sty_t : query_sty val_t = pair_t route_id_t (pair_t string_t state_id_t) |
| 589 |
let goals_sty_t : goals_sty val_t = unit_t |
| 590 |
let evars_sty_t : evars_sty val_t = unit_t |
| 591 |
let hints_sty_t : hints_sty val_t = unit_t |
| 592 |
let status_sty_t : status_sty val_t = bool_t |
| 593 |
let search_sty_t : search_sty val_t = list_t (pair_t search_cst_t bool_t) |
| 594 |
let get_options_sty_t : get_options_sty val_t = unit_t |
| 595 |
let set_options_sty_t : set_options_sty val_t = |
| 596 |
list_t (pair_t (list_t string_t) option_value_t) |
| 597 |
let mkcases_sty_t : mkcases_sty val_t = string_t |
| 598 |
let quit_sty_t : quit_sty val_t = unit_t |
| 599 |
let wait_sty_t : wait_sty val_t = unit_t |
| 600 |
let about_sty_t : about_sty val_t = unit_t |
| 601 |
let init_sty_t : init_sty val_t = option_t string_t |
| 602 |
let interp_sty_t : interp_sty val_t = pair_t (pair_t bool_t bool_t) string_t |
| 603 |
let stop_worker_sty_t : stop_worker_sty val_t = string_t |
| 604 |
let print_ast_sty_t : print_ast_sty val_t = state_id_t |
| 605 |
let annotate_sty_t : annotate_sty val_t = string_t |
| 606 |
let proof_diff_sty_t : proof_diff_sty val_t = pair_t string_t state_id_t |
| 607 |
let db_cmd_sty_t : db_cmd_sty val_t = string_t |
| 608 |
let db_upd_bpts_sty_t : db_upd_bpts_sty val_t = |
| 609 |
list_t (pair_t (pair_t string_t int_t) bool_t) |
| 610 |
let db_continue_sty_t : db_continue_sty val_t = db_cont_opt_t |
| 611 |
let db_stack_sty_t : db_stack_sty val_t = unit_t |
| 612 |
let db_vars_sty_t : db_vars_sty val_t = int_t |
| 613 |
let db_configd_sty_t : db_configd_sty val_t = unit_t |
| 614 |
let subgoals_sty_t : subgoals_sty val_t = goal_flags_t |
| 615 |
|
| 616 |
let add_rty_t : add_rty val_t = |
| 617 |
pair_t state_id_t (union_t unit_t state_id_t) |
| 618 |
let edit_at_rty_t : edit_at_rty val_t = |
| 619 |
union_t unit_t (pair_t state_id_t (pair_t state_id_t state_id_t)) |
| 620 |
let query_rty_t : query_rty val_t = unit_t |
| 621 |
let goals_rty_t : goals_rty val_t = option_t goals_t |
| 622 |
let evars_rty_t : evars_rty val_t = option_t (list_t evar_t) |
| 623 |
let hints_rty_t : hints_rty val_t = |
| 624 |
let hint = list_t (pair_t string_t string_t) in |
| 625 |
option_t (pair_t (list_t hint) hint) |
| 626 |
let status_rty_t : status_rty val_t = state_t |
| 627 |
let search_rty_t : search_rty val_t = list_t (rocq_object_t string_t) |
| 628 |
let get_options_rty_t : get_options_rty val_t = |
| 629 |
list_t (pair_t (list_t string_t) option_state_t) |
| 630 |
let set_options_rty_t : set_options_rty val_t = unit_t |
| 631 |
let mkcases_rty_t : mkcases_rty val_t = list_t (list_t string_t) |
| 632 |
let quit_rty_t : quit_rty val_t = unit_t |
| 633 |
let wait_rty_t : wait_rty val_t = unit_t |
| 634 |
let about_rty_t : about_rty val_t = rocq_info_t |
| 635 |
let init_rty_t : init_rty val_t = state_id_t |
| 636 |
let interp_rty_t : interp_rty val_t = pair_t state_id_t (union_t string_t string_t) |
| 637 |
let stop_worker_rty_t : stop_worker_rty val_t = unit_t |
| 638 |
let print_ast_rty_t : print_ast_rty val_t = xml_t |
| 639 |
let annotate_rty_t : annotate_rty val_t = xml_t |
| 640 |
let proof_diff_rty_t : proof_diff_rty val_t = pp_t |
| 641 |
let db_cmd_rty_t : db_cmd_rty val_t = unit_t |
| 642 |
let db_upd_bpts_rty_t : db_upd_bpts_rty val_t = unit_t |
| 643 |
let db_continue_rty_t : db_continue_rty val_t = unit_t |
| 644 |
let db_stack_rty_t : db_stack_rty val_t = |
| 645 |
list_t (pair_t string_t (option_t (pair_t string_t (list_t int_t)))) |
| 646 |
let db_vars_rty_t : db_vars_rty val_t = |
| 647 |
list_t (pair_t string_t pp_t) |
| 648 |
let db_configd_rty_t : db_configd_rty val_t = unit_t |
| 649 |
let subgoals_rty_t : subgoals_rty val_t = option_t goals_t |
| 650 |
|
| 651 |
let ($) x = erase x |
| 652 |
let calls = [| |
| 653 |
"Add", ($)add_sty_t, ($)add_rty_t; |
| 654 |
"Edit_at", ($)edit_at_sty_t, ($)edit_at_rty_t; |
| 655 |
"Query", ($)query_sty_t, ($)query_rty_t; |
| 656 |
"Goal", ($)goals_sty_t, ($)goals_rty_t; |
| 657 |
"Evars", ($)evars_sty_t, ($)evars_rty_t; |
| 658 |
"Hints", ($)hints_sty_t, ($)hints_rty_t; |
| 659 |
"Status", ($)status_sty_t, ($)status_rty_t; |
| 660 |
"Search", ($)search_sty_t, ($)search_rty_t; |
| 661 |
"GetOptions", ($)get_options_sty_t, ($)get_options_rty_t; |
| 662 |
"SetOptions", ($)set_options_sty_t, ($)set_options_rty_t; |
| 663 |
"MkCases", ($)mkcases_sty_t, ($)mkcases_rty_t; |
| 664 |
"Quit", ($)quit_sty_t, ($)quit_rty_t; |
| 665 |
"Wait", ($)wait_sty_t, ($)wait_rty_t; |
| 666 |
"About", ($)about_sty_t, ($)about_rty_t; |
| 667 |
"Init", ($)init_sty_t, ($)init_rty_t; |
| 668 |
"Interp", ($)interp_sty_t, ($)interp_rty_t; |
| 669 |
"StopWorker", ($)stop_worker_sty_t, ($)stop_worker_rty_t; |
| 670 |
"PrintAst", ($)print_ast_sty_t, ($)print_ast_rty_t; |
| 671 |
"Annotate", ($)annotate_sty_t, ($)annotate_rty_t; |
| 672 |
"PDiff", ($)proof_diff_sty_t, ($)proof_diff_rty_t; |
| 673 |
"Db_cmd", ($)db_cmd_sty_t, ($)db_cmd_rty_t; |
| 674 |
"Db_upd_bpts",($)db_upd_bpts_sty_t, ($)db_upd_bpts_rty_t; |
| 675 |
"Db_continue",($)db_continue_sty_t, ($)db_continue_rty_t; |
| 676 |
"Db_stack", ($)db_stack_sty_t, ($)db_stack_rty_t; |
| 677 |
"Db_vars", ($)db_vars_sty_t, ($)db_vars_rty_t; |
| 678 |
"Db_configd", ($)db_configd_sty_t, ($)db_configd_rty_t; |
| 679 |
"Subgoals", ($)subgoals_sty_t, ($)subgoals_rty_t; |
| 680 |
|] |
| 681 |
|
| 682 |
type 'a call = |
| 683 |
| Add : add_sty -> add_rty call |
| 684 |
| Edit_at : edit_at_sty -> edit_at_rty call |
| 685 |
| Query : query_sty -> query_rty call |
| 686 |
| Goal : goals_sty -> goals_rty call |
| 687 |
| Evars : evars_sty -> evars_rty call |
| 688 |
| Hints : hints_sty -> hints_rty call |
| 689 |
| Status : status_sty -> status_rty call |
| 690 |
| Search : search_sty -> search_rty call |
| 691 |
| GetOptions : get_options_sty -> get_options_rty call |
| 692 |
| SetOptions : set_options_sty -> set_options_rty call |
| 693 |
| MkCases : mkcases_sty -> mkcases_rty call |
| 694 |
| Quit : quit_sty -> quit_rty call |
| 695 |
| About : about_sty -> about_rty call |
| 696 |
| Init : init_sty -> init_rty call |
| 697 |
| StopWorker : stop_worker_sty -> stop_worker_rty call |
| 698 |
|
| 699 |
| Wait : wait_sty -> wait_rty call |
| 700 |
|
| 701 |
| Interp : interp_sty -> interp_rty call |
| 702 |
| PrintAst : print_ast_sty -> print_ast_rty call |
| 703 |
| Annotate : annotate_sty -> annotate_rty call |
| 704 |
| PDiff : proof_diff_sty -> proof_diff_rty call |
| 705 |
| Db_cmd : db_cmd_sty -> db_cmd_rty call |
| 706 |
| Db_upd_bpts: db_upd_bpts_sty -> db_upd_bpts_rty call |
| 707 |
| Db_continue: db_continue_sty -> db_continue_rty call |
| 708 |
| Db_stack : db_stack_sty -> db_stack_rty call |
| 709 |
| Db_vars : db_vars_sty -> db_vars_rty call |
| 710 |
| Db_configd : db_configd_sty -> db_configd_rty call |
| 711 |
| Subgoals : subgoals_sty -> subgoals_rty call |
| 712 |
|
| 713 |
|
| 714 |
let id_of_call : type a. a call -> int = function |
| 715 |
| Add _ -> 0 |
| 716 |
| Edit_at _ -> 1 |
| 717 |
| Query _ -> 2 |
| 718 |
| Goal _ -> 3 |
| 719 |
| Evars _ -> 4 |
| 720 |
| Hints _ -> 5 |
| 721 |
| Status _ -> 6 |
| 722 |
| Search _ -> 7 |
| 723 |
| GetOptions _ -> 8 |
| 724 |
| SetOptions _ -> 9 |
| 725 |
| MkCases _ -> 10 |
| 726 |
| Quit _ -> 11 |
| 727 |
| Wait _ -> 12 |
| 728 |
| About _ -> 13 |
| 729 |
| Init _ -> 14 |
| 730 |
| Interp _ -> 15 |
| 731 |
| StopWorker _ -> 16 |
| 732 |
| PrintAst _ -> 17 |
| 733 |
| Annotate _ -> 18 |
| 734 |
| PDiff _ -> 19 |
| 735 |
| Db_cmd _ -> 20 |
| 736 |
| Db_upd_bpts _-> 21 |
| 737 |
| Db_continue _-> 22 |
| 738 |
| Db_stack _ -> 23 |
| 739 |
| Db_vars _ -> 24 |
| 740 |
| Db_configd _ -> 25 |
| 741 |
| Subgoals _ -> 26 |
| 742 |
|
| 743 |
let str_of_call c = pi1 calls.(id_of_call c) |
| 744 |
|
| 745 |
type unknown_call = Unknown : 'a call -> unknown_call |
| 746 |
|
| 747 |
|
| 748 |
let add x : add_rty call = Add x |
| 749 |
let edit_at x : edit_at_rty call = Edit_at x |
| 750 |
let query x : query_rty call = Query x |
| 751 |
let goals x : goals_rty call = Goal x |
| 752 |
let evars x : evars_rty call = Evars x |
| 753 |
let hints x : hints_rty call = Hints x |
| 754 |
let status x : status_rty call = Status x |
| 755 |
let get_options x : get_options_rty call = GetOptions x |
| 756 |
let set_options x : set_options_rty call = SetOptions x |
| 757 |
let mkcases x : mkcases_rty call = MkCases x |
| 758 |
let search x : search_rty call = Search x |
| 759 |
let quit x : quit_rty call = Quit x |
| 760 |
let init x : init_rty call = Init x |
| 761 |
let wait x : wait_rty call = Wait x |
| 762 |
let interp x : interp_rty call = Interp x |
| 763 |
let stop_worker x : stop_worker_rty call = StopWorker x |
| 764 |
let print_ast x : print_ast_rty call = PrintAst x |
| 765 |
let annotate x : annotate_rty call = Annotate x |
| 766 |
let proof_diff x : proof_diff_rty call = PDiff x |
| 767 |
let db_cmd x : db_cmd_rty call = Db_cmd x |
| 768 |
let db_upd_bpts x : db_upd_bpts_rty call = Db_upd_bpts x |
| 769 |
let db_continue x : db_continue_rty call = Db_continue x |
| 770 |
let db_stack x : db_stack_rty call = Db_stack x |
| 771 |
let db_vars x : db_vars_rty call = Db_vars x |
| 772 |
let db_configd x : db_configd_rty call = Db_configd x |
| 773 |
let subgoals x : subgoals_rty call = Subgoals x |
| 774 |
|
| 775 |
let abstract_eval_call : type a. _ -> a call -> bool * a value = fun handler c -> |
| 776 |
let send = ref true in |
| 777 |
let mkGood : type a. a -> bool * a value = fun x -> !send, (Good x) in |
| 778 |
try |
| 779 |
match c with |
| 780 |
| Add x -> mkGood (handler.add x) |
| 781 |
| Edit_at x -> mkGood (handler.edit_at x) |
| 782 |
| Query x -> mkGood (handler.query x) |
| 783 |
| Goal x -> mkGood (handler.goals x) |
| 784 |
| Evars x -> mkGood (handler.evars x) |
| 785 |
| Hints x -> mkGood (handler.hints x) |
| 786 |
| Status x -> mkGood (handler.status x) |
| 787 |
| Search x -> mkGood (handler.search x) |
| 788 |
| GetOptions x -> mkGood (handler.get_options x) |
| 789 |
| SetOptions x -> mkGood (handler.set_options x) |
| 790 |
| MkCases x -> mkGood (handler.mkcases x) |
| 791 |
| Quit x -> mkGood (handler.quit x) |
| 792 |
| Wait x -> mkGood (handler.wait x) |
| 793 |
| About x -> mkGood (handler.about x) |
| 794 |
| Init x -> mkGood (handler.init x) |
| 795 |
| Interp x -> mkGood (handler.interp x) |
| 796 |
| StopWorker x -> mkGood (handler.stop_worker x) |
| 797 |
| PrintAst x -> mkGood (handler.print_ast x) |
| 798 |
| Annotate x -> mkGood (handler.annotate x) |
| 799 |
| PDiff x -> mkGood (handler.proof_diff x) |
| 800 |
| Db_cmd x -> mkGood (handler.db_cmd x) |
| 801 |
| Db_upd_bpts x-> mkGood (handler.db_upd_bpts x) |
| 802 |
| Db_continue x-> mkGood (handler.db_continue x) |
| 803 |
| Db_stack x -> send := false; mkGood (handler.db_stack x) |
| 804 |
| Db_vars x -> send := false; mkGood (handler.db_vars x) |
| 805 |
| Db_configd x -> mkGood (handler.db_configd x) |
| 806 |
| Subgoals x -> mkGood (handler.subgoals x) |
| 807 |
with any -> |
| 808 |
let any = Exninfo.capture any in |
| 809 |
true, Fail (handler.handle_exn any) |
| 810 |
|
| 811 |
|
| 812 |
let of_answer : type a. a call -> a value -> xml = function |
| 813 |
| Add _ -> of_value (of_value_type add_rty_t ) |
| 814 |
| Edit_at _ -> of_value (of_value_type edit_at_rty_t ) |
| 815 |
| Query _ -> of_value (of_value_type query_rty_t ) |
| 816 |
| Goal _ -> of_value (of_value_type goals_rty_t ) |
| 817 |
| Evars _ -> of_value (of_value_type evars_rty_t ) |
| 818 |
| Hints _ -> of_value (of_value_type hints_rty_t ) |
| 819 |
| Status _ -> of_value (of_value_type status_rty_t ) |
| 820 |
| Search _ -> of_value (of_value_type search_rty_t ) |
| 821 |
| GetOptions _ -> of_value (of_value_type get_options_rty_t) |
| 822 |
| SetOptions _ -> of_value (of_value_type set_options_rty_t) |
| 823 |
| MkCases _ -> of_value (of_value_type mkcases_rty_t ) |
| 824 |
| Quit _ -> of_value (of_value_type quit_rty_t ) |
| 825 |
| Wait _ -> of_value (of_value_type wait_rty_t ) |
| 826 |
| About _ -> of_value (of_value_type about_rty_t ) |
| 827 |
| Init _ -> of_value (of_value_type init_rty_t ) |
| 828 |
| Interp _ -> of_value (of_value_type interp_rty_t ) |
| 829 |
| StopWorker _ -> of_value (of_value_type stop_worker_rty_t) |
| 830 |
| PrintAst _ -> of_value (of_value_type print_ast_rty_t ) |
| 831 |
| Annotate _ -> of_value (of_value_type annotate_rty_t ) |
| 832 |
| PDiff _ -> of_value (of_value_type proof_diff_rty_t ) |
| 833 |
| Db_cmd _ -> of_value (of_value_type db_cmd_rty_t ) |
| 834 |
| Db_upd_bpts _-> of_value (of_value_type db_upd_bpts_rty_t) |
| 835 |
| Db_continue _-> of_value (of_value_type db_continue_rty_t) |
| 836 |
| Db_stack _ -> of_value (of_value_type db_stack_rty_t ) |
| 837 |
| Db_vars _ -> of_value (of_value_type db_vars_rty_t ) |
| 838 |
| Db_configd _ -> of_value (of_value_type db_configd_rty_t ) |
| 839 |
| Subgoals _ -> of_value (of_value_type subgoals_rty_t) |
| 840 |
|
| 841 |
let of_answer msg_fmt = |
| 842 |
msg_format := msg_fmt; of_answer |
| 843 |
|
| 844 |
let to_answer : type a. a call -> xml -> a value = function |
| 845 |
| Add _ -> to_value (to_value_type add_rty_t ) |
| 846 |
| Edit_at _ -> to_value (to_value_type edit_at_rty_t ) |
| 847 |
| Query _ -> to_value (to_value_type query_rty_t ) |
| 848 |
| Goal _ -> to_value (to_value_type goals_rty_t ) |
| 849 |
| Evars _ -> to_value (to_value_type evars_rty_t ) |
| 850 |
| Hints _ -> to_value (to_value_type hints_rty_t ) |
| 851 |
| Status _ -> to_value (to_value_type status_rty_t ) |
| 852 |
| Search _ -> to_value (to_value_type search_rty_t ) |
| 853 |
| GetOptions _ -> to_value (to_value_type get_options_rty_t) |
| 854 |
| SetOptions _ -> to_value (to_value_type set_options_rty_t) |
| 855 |
| MkCases _ -> to_value (to_value_type mkcases_rty_t ) |
| 856 |
| Quit _ -> to_value (to_value_type quit_rty_t ) |
| 857 |
| Wait _ -> to_value (to_value_type wait_rty_t ) |
| 858 |
| About _ -> to_value (to_value_type about_rty_t ) |
| 859 |
| Init _ -> to_value (to_value_type init_rty_t ) |
| 860 |
| Interp _ -> to_value (to_value_type interp_rty_t ) |
| 861 |
| StopWorker _ -> to_value (to_value_type stop_worker_rty_t) |
| 862 |
| PrintAst _ -> to_value (to_value_type print_ast_rty_t ) |
| 863 |
| Annotate _ -> to_value (to_value_type annotate_rty_t ) |
| 864 |
| PDiff _ -> to_value (to_value_type proof_diff_rty_t ) |
| 865 |
| Db_cmd _ -> to_value (to_value_type db_cmd_rty_t ) |
| 866 |
| Db_upd_bpts _-> to_value (to_value_type db_upd_bpts_rty_t) |
| 867 |
| Db_continue _-> to_value (to_value_type db_continue_rty_t) |
| 868 |
| Db_stack _ -> to_value (to_value_type db_stack_rty_t ) |
| 869 |
| Db_vars _ -> to_value (to_value_type db_vars_rty_t ) |
| 870 |
| Db_configd _ -> to_value (to_value_type db_configd_rty_t ) |
| 871 |
| Subgoals _ -> to_value (to_value_type subgoals_rty_t ) |
| 872 |
|
| 873 |
let of_call : type a. a call -> xml = fun q -> |
| 874 |
let mkCall x = constructor "call" (str_of_call q) [x] in |
| 875 |
match q with |
| 876 |
| Add x -> mkCall (of_value_type add_sty_t x) |
| 877 |
| Edit_at x -> mkCall (of_value_type edit_at_sty_t x) |
| 878 |
| Query x -> mkCall (of_value_type query_sty_t x) |
| 879 |
| Goal x -> mkCall (of_value_type goals_sty_t x) |
| 880 |
| Evars x -> mkCall (of_value_type evars_sty_t x) |
| 881 |
| Hints x -> mkCall (of_value_type hints_sty_t x) |
| 882 |
| Status x -> mkCall (of_value_type status_sty_t x) |
| 883 |
| Search x -> mkCall (of_value_type search_sty_t x) |
| 884 |
| GetOptions x -> mkCall (of_value_type get_options_sty_t x) |
| 885 |
| SetOptions x -> mkCall (of_value_type set_options_sty_t x) |
| 886 |
| MkCases x -> mkCall (of_value_type mkcases_sty_t x) |
| 887 |
| Quit x -> mkCall (of_value_type quit_sty_t x) |
| 888 |
| Wait x -> mkCall (of_value_type wait_sty_t x) |
| 889 |
| About x -> mkCall (of_value_type about_sty_t x) |
| 890 |
| Init x -> mkCall (of_value_type init_sty_t x) |
| 891 |
| Interp x -> mkCall (of_value_type interp_sty_t x) |
| 892 |
| StopWorker x -> mkCall (of_value_type stop_worker_sty_t x) |
| 893 |
| PrintAst x -> mkCall (of_value_type print_ast_sty_t x) |
| 894 |
| Annotate x -> mkCall (of_value_type annotate_sty_t x) |
| 895 |
| PDiff x -> mkCall (of_value_type proof_diff_sty_t x) |
| 896 |
| Db_cmd x -> mkCall (of_value_type db_cmd_sty_t x) |
| 897 |
| Db_upd_bpts x-> mkCall (of_value_type db_upd_bpts_sty_t x) |
| 898 |
| Db_continue x-> mkCall (of_value_type db_continue_sty_t x) |
| 899 |
| Db_stack x -> mkCall (of_value_type db_stack_sty_t x) |
| 900 |
| Db_vars x -> mkCall (of_value_type db_vars_sty_t x) |
| 901 |
| Db_configd x -> mkCall (of_value_type db_configd_sty_t x) |
| 902 |
| Subgoals x -> mkCall (of_value_type subgoals_sty_t x) |
| 903 |
|
| 904 |
let to_call : xml -> unknown_call = |
| 905 |
do_match "call" (fun s a -> |
| 906 |
let mkCallArg vt a = to_value_type vt (singleton a) in |
| 907 |
match s with |
| 908 |
| "Add" -> Unknown (Add (mkCallArg add_sty_t a)) |
| 909 |
| "Edit_at" -> Unknown (Edit_at (mkCallArg edit_at_sty_t a)) |
| 910 |
| "Query" -> Unknown (Query (mkCallArg query_sty_t a)) |
| 911 |
| "Goal" -> Unknown (Goal (mkCallArg goals_sty_t a)) |
| 912 |
| "Evars" -> Unknown (Evars (mkCallArg evars_sty_t a)) |
| 913 |
| "Hints" -> Unknown (Hints (mkCallArg hints_sty_t a)) |
| 914 |
| "Status" -> Unknown (Status (mkCallArg status_sty_t a)) |
| 915 |
| "Search" -> Unknown (Search (mkCallArg search_sty_t a)) |
| 916 |
| "GetOptions" -> Unknown (GetOptions (mkCallArg get_options_sty_t a)) |
| 917 |
| "SetOptions" -> Unknown (SetOptions (mkCallArg set_options_sty_t a)) |
| 918 |
| "MkCases" -> Unknown (MkCases (mkCallArg mkcases_sty_t a)) |
| 919 |
| "Quit" -> Unknown (Quit (mkCallArg quit_sty_t a)) |
| 920 |
| "Wait" -> Unknown (Wait (mkCallArg wait_sty_t a)) |
| 921 |
| "About" -> Unknown (About (mkCallArg about_sty_t a)) |
| 922 |
| "Init" -> Unknown (Init (mkCallArg init_sty_t a)) |
| 923 |
| "Interp" -> Unknown (Interp (mkCallArg interp_sty_t a)) |
| 924 |
| "StopWorker" -> Unknown (StopWorker (mkCallArg stop_worker_sty_t a)) |
| 925 |
| "PrintAst" -> Unknown (PrintAst (mkCallArg print_ast_sty_t a)) |
| 926 |
| "Annotate" -> Unknown (Annotate (mkCallArg annotate_sty_t a)) |
| 927 |
| "PDiff" -> Unknown (PDiff (mkCallArg proof_diff_sty_t a)) |
| 928 |
| "Db_cmd" -> Unknown (Db_cmd (mkCallArg db_cmd_sty_t a)) |
| 929 |
| "Db_upd_bpts"-> Unknown (Db_upd_bpts(mkCallArg db_upd_bpts_sty_t a)) |
| 930 |
| "Db_continue"-> Unknown (Db_continue(mkCallArg db_continue_sty_t a)) |
| 931 |
| "Db_stack" -> Unknown (Db_stack (mkCallArg db_stack_sty_t a)) |
| 932 |
| "Db_vars" -> Unknown (Db_vars (mkCallArg db_vars_sty_t a)) |
| 933 |
| "Db_configd" -> Unknown (Db_configd (mkCallArg db_configd_sty_t a)) |
| 934 |
| "Subgoals" -> Unknown (Subgoals (mkCallArg subgoals_sty_t a)) |
| 935 |
| x -> raise (Marshal_error("call",PCData x))) |
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
let pr_value_gen pr = function |
| 940 |
| Good v -> "GOOD " ^ pr v |
| 941 |
| Fail (id,None,str) -> "FAIL "^Stateid.to_string id^" ["^ Pp.string_of_ppcmds str ^ "]" |
| 942 |
| Fail (id,Some loc,str) -> |
| 943 |
Printf.sprintf "FAIL %s (%d, %d)[%s]" (Stateid.to_string id) loc.bp loc.ep (Pp.string_of_ppcmds str) |
| 944 |
let pr_value v = pr_value_gen (fun _ -> "FIXME") v |
| 945 |
let pr_full_value : type a. a call -> a value -> string = fun call value -> match call with |
| 946 |
| Add _ -> pr_value_gen (print add_rty_t ) value |
| 947 |
| Edit_at _ -> pr_value_gen (print edit_at_rty_t ) value |
| 948 |
| Query _ -> pr_value_gen (print query_rty_t ) value |
| 949 |
| Goal _ -> pr_value_gen (print goals_rty_t ) value |
| 950 |
| Evars _ -> pr_value_gen (print evars_rty_t ) value |
| 951 |
| Hints _ -> pr_value_gen (print hints_rty_t ) value |
| 952 |
| Status _ -> pr_value_gen (print status_rty_t ) value |
| 953 |
| Search _ -> pr_value_gen (print search_rty_t ) value |
| 954 |
| GetOptions _ -> pr_value_gen (print get_options_rty_t) value |
| 955 |
| SetOptions _ -> pr_value_gen (print set_options_rty_t) value |
| 956 |
| MkCases _ -> pr_value_gen (print mkcases_rty_t ) value |
| 957 |
| Quit _ -> pr_value_gen (print quit_rty_t ) value |
| 958 |
| Wait _ -> pr_value_gen (print wait_rty_t ) value |
| 959 |
| About _ -> pr_value_gen (print about_rty_t ) value |
| 960 |
| Init _ -> pr_value_gen (print init_rty_t ) value |
| 961 |
| Interp _ -> pr_value_gen (print interp_rty_t ) value |
| 962 |
| StopWorker _ -> pr_value_gen (print stop_worker_rty_t) value |
| 963 |
| PrintAst _ -> pr_value_gen (print print_ast_rty_t ) value |
| 964 |
| Annotate _ -> pr_value_gen (print annotate_rty_t ) value |
| 965 |
| PDiff _ -> pr_value_gen (print proof_diff_rty_t ) value |
| 966 |
| Db_cmd _ -> pr_value_gen (print db_cmd_rty_t ) value |
| 967 |
| Db_upd_bpts _-> pr_value_gen (print db_upd_bpts_rty_t) value |
| 968 |
| Db_continue _-> pr_value_gen (print db_continue_rty_t) value |
| 969 |
| Db_stack _ -> pr_value_gen (print db_stack_rty_t ) value |
| 970 |
| Db_vars _ -> pr_value_gen (print db_vars_rty_t ) value |
| 971 |
| Db_configd _ -> pr_value_gen (print db_configd_rty_t ) value |
| 972 |
| Subgoals _ -> pr_value_gen (print subgoals_rty_t ) value |
| 973 |
let pr_call : type a. a call -> string = fun call -> |
| 974 |
let return what x = str_of_call call ^ " " ^ print what x in |
| 975 |
match call with |
| 976 |
| Add x -> return add_sty_t x |
| 977 |
| Edit_at x -> return edit_at_sty_t x |
| 978 |
| Query x -> return query_sty_t x |
| 979 |
| Goal x -> return goals_sty_t x |
| 980 |
| Evars x -> return evars_sty_t x |
| 981 |
| Hints x -> return hints_sty_t x |
| 982 |
| Status x -> return status_sty_t x |
| 983 |
| Search x -> return search_sty_t x |
| 984 |
| GetOptions x -> return get_options_sty_t x |
| 985 |
| SetOptions x -> return set_options_sty_t x |
| 986 |
| MkCases x -> return mkcases_sty_t x |
| 987 |
| Quit x -> return quit_sty_t x |
| 988 |
| Wait x -> return wait_sty_t x |
| 989 |
| About x -> return about_sty_t x |
| 990 |
| Init x -> return init_sty_t x |
| 991 |
| Interp x -> return interp_sty_t x |
| 992 |
| StopWorker x -> return stop_worker_sty_t x |
| 993 |
| PrintAst x -> return print_ast_sty_t x |
| 994 |
| Annotate x -> return annotate_sty_t x |
| 995 |
| PDiff x -> return proof_diff_sty_t x |
| 996 |
| Db_cmd x -> return db_cmd_sty_t x |
| 997 |
| Db_upd_bpts x-> return db_upd_bpts_sty_t x |
| 998 |
| Db_continue x-> return db_continue_sty_t x |
| 999 |
| Db_stack x -> return db_stack_sty_t x |
| 1000 |
| Db_vars x -> return db_vars_sty_t x |
| 1001 |
| Db_configd x -> return db_configd_sty_t x |
| 1002 |
| Subgoals x -> return subgoals_sty_t x |
| 1003 |
|
| 1004 |
let document to_string_fmt = |
| 1005 |
Printf.printf "=== Available calls ===\n\n"; |
| 1006 |
Array.iter (fun (cname, csty, crty) -> |
| 1007 |
Printf.printf "%12s : %s\n %14s %s\n" |
| 1008 |
("\""^cname^"\"") (print_type csty) "->" (print_type crty)) |
| 1009 |
calls; |
| 1010 |
Printf.printf "\n=== Calls XML encoding ===\n\n"; |
| 1011 |
Printf.printf "A call \"C\" carrying input a is encoded as:\n\n%s\n\n" |
| 1012 |
(to_string_fmt (constructor "call" "C" [PCData "a"])); |
| 1013 |
Printf.printf "A response carrying output b can either be:\n\n%s\n\n" |
| 1014 |
(to_string_fmt (of_value (fun _ -> PCData "b") (Good ()))); |
| 1015 |
Printf.printf "or:\n\n%s\n\n" |
| 1016 |
(to_string_fmt (of_value (fun _ -> PCData "b") |
| 1017 |
(Fail |
| 1018 |
(Stateid.initial, |
| 1019 |
Some (Loc.{fname=ToplevelInput; line_nb=4; bol_pos=0; line_nb_last=6; bol_pos_last=10; bp=15; ep=34}), |
| 1020 |
Pp.str "error message")))); |
| 1021 |
document_type_encoding to_string_fmt |
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
open Feedback |
| 1027 |
|
| 1028 |
let of_message_level = function |
| 1029 |
| Debug -> |
| 1030 |
Serialize.constructor "message_level" "debug" [] |
| 1031 |
| Info -> Serialize.constructor "message_level" "info" [] |
| 1032 |
| Notice -> Serialize.constructor "message_level" "notice" [] |
| 1033 |
| Warning -> Serialize.constructor "message_level" "warning" [] |
| 1034 |
| Error -> Serialize.constructor "message_level" "error" [] |
| 1035 |
let to_message_level = |
| 1036 |
Serialize.do_match "message_level" (fun s args -> match s with |
| 1037 |
| "debug" -> empty args; Debug |
| 1038 |
| "info" -> empty args; Info |
| 1039 |
| "notice" -> empty args; Notice |
| 1040 |
| "warning" -> empty args; Warning |
| 1041 |
| "error" -> empty args; Error |
| 1042 |
| x -> raise Serialize.(Marshal_error("error level",PCData x))) |
| 1043 |
|
| 1044 |
let of_message lvl loc msg = |
| 1045 |
let lvl = of_message_level lvl in |
| 1046 |
let xloc = of_option of_loc loc in |
| 1047 |
let content = of_pp msg in |
| 1048 |
Xml_datatype.Element ("message", [], [lvl; xloc; content]) |
| 1049 |
|
| 1050 |
let to_message xml = match xml with |
| 1051 |
| Xml_datatype.Element ("message", [], [lvl; xloc; content]) -> |
| 1052 |
Message(to_message_level lvl, to_option to_loc xloc, [], to_pp content) |
| 1053 |
| x -> raise (Marshal_error("message",x)) |
| 1054 |
|
| 1055 |
let to_feedback_content = do_match "feedback_content" (fun s a -> match s,a with |
| 1056 |
| "addedaxiom", _ -> AddedAxiom |
| 1057 |
| "processed", _ -> Processed |
| 1058 |
| "processingin", [where] -> ProcessingIn (to_string where) |
| 1059 |
| "incomplete", _ -> Incomplete |
| 1060 |
| "complete", _ -> Complete |
| 1061 |
| "globref", [loc; filepath; modpath; ident; ty] -> |
| 1062 |
GlobRef(to_loc loc, to_string filepath, |
| 1063 |
to_string modpath, to_string ident, to_string ty) |
| 1064 |
| "globdef", [loc; ident; secpath; ty] -> |
| 1065 |
GlobDef(to_loc loc, to_string ident, to_string secpath, to_string ty) |
| 1066 |
| "inprogress", [n] -> InProgress (to_int n) |
| 1067 |
| "workerstatus", [ns] -> |
| 1068 |
let n, s = to_pair to_string to_string ns in |
| 1069 |
WorkerStatus(n,s) |
| 1070 |
| "custom", [loc;name;x]-> Custom (to_option to_loc loc, to_string name, x) |
| 1071 |
| "filedependency", [from; dep] -> |
| 1072 |
FileDependency (to_option to_string from, to_string dep) |
| 1073 |
| "fileloaded", [dirpath; filename] -> |
| 1074 |
FileLoaded (to_string dirpath, to_string filename) |
| 1075 |
| "message", [x] -> to_message x |
| 1076 |
| x,l -> raise (Marshal_error("feedback_content",PCData (x ^ " with attributes " ^ string_of_int (List.length l))))) |
| 1077 |
|
| 1078 |
let of_feedback_content = function |
| 1079 |
| AddedAxiom -> constructor "feedback_content" "addedaxiom" [] |
| 1080 |
| Processed -> constructor "feedback_content" "processed" [] |
| 1081 |
| ProcessingIn where -> |
| 1082 |
constructor "feedback_content" "processingin" [of_string where] |
| 1083 |
| Incomplete -> constructor "feedback_content" "incomplete" [] |
| 1084 |
| Complete -> constructor "feedback_content" "complete" [] |
| 1085 |
| GlobRef(loc, filepath, modpath, ident, ty) -> |
| 1086 |
constructor "feedback_content" "globref" [ |
| 1087 |
of_loc loc; |
| 1088 |
of_string filepath; |
| 1089 |
of_string modpath; |
| 1090 |
of_string ident; |
| 1091 |
of_string ty ] |
| 1092 |
| GlobDef(loc, ident, secpath, ty) -> |
| 1093 |
constructor "feedback_content" "globdef" [ |
| 1094 |
of_loc loc; |
| 1095 |
of_string ident; |
| 1096 |
of_string secpath; |
| 1097 |
of_string ty ] |
| 1098 |
| InProgress n -> constructor "feedback_content" "inprogress" [of_int n] |
| 1099 |
| WorkerStatus(n,s) -> |
| 1100 |
constructor "feedback_content" "workerstatus" |
| 1101 |
[of_pair of_string of_string (n,s)] |
| 1102 |
| Custom (loc, name, x) -> |
| 1103 |
constructor "feedback_content" "custom" [of_option of_loc loc; of_string name; x] |
| 1104 |
| FileDependency (from, depends_on) -> |
| 1105 |
constructor "feedback_content" "filedependency" [ |
| 1106 |
of_option of_string from; |
| 1107 |
of_string depends_on] |
| 1108 |
| FileLoaded (dirpath, filename) -> |
| 1109 |
constructor "feedback_content" "fileloaded" [ |
| 1110 |
of_string dirpath; |
| 1111 |
of_string filename ] |
| 1112 |
| Message (l,loc,_,m) -> constructor "feedback_content" "message" [ of_message l loc m ] |
| 1113 |
|
| 1114 |
let of_edit_or_state_id id = ["object","state"], of_stateid id |
| 1115 |
|
| 1116 |
let of_feedback msg = |
| 1117 |
let content = of_feedback_content msg.contents in |
| 1118 |
let obj, id = of_edit_or_state_id msg.span_id in |
| 1119 |
let route = string_of_int msg.route in |
| 1120 |
Element ("feedback", obj @ ["route",route], [id;content]) |
| 1121 |
|
| 1122 |
let of_feedback msg_fmt = |
| 1123 |
msg_format := msg_fmt; of_feedback |
| 1124 |
|
| 1125 |
let to_feedback xml = match xml with |
| 1126 |
| Element ("feedback", ["object","state";"route",route], [id;content]) -> { |
| 1127 |
doc_id = 0; |
| 1128 |
span_id = to_stateid id; |
| 1129 |
route = int_of_string route; |
| 1130 |
contents = to_feedback_content content } |
| 1131 |
| x -> raise (Marshal_error("feedback",x)) |
| 1132 |
|
| 1133 |
let of_ltac_debug_answer ~tag msg = |
| 1134 |
let wrap s = Element ("ltac_debug", [], s) in |
| 1135 |
wrap [PCData tag; of_pp msg] |
| 1136 |
|
| 1137 |
let to_ltac_debug_answer xml = |
| 1138 |
match xml with |
| 1139 |
| Element ("ltac_debug", [], [PCData tag; pp]) -> |
| 1140 |
let msg = to_pp pp in |
| 1141 |
tag, msg |
| 1142 |
| x -> raise (Marshal_error("ltac_debug_answer",x)) |
| 1143 |
|
| 1144 |
type msg_type = Feedback | LtacDebugInfo | Other |
| 1145 |
|
| 1146 |
let msg_kind = function |
| 1147 |
| Element ("feedback", _, _) -> Feedback |
| 1148 |
| Element ("ltac_debug", _, _) -> LtacDebugInfo |
| 1149 |
| _ -> Other |
| 1150 |
|
| 1151 |
let of_vars vars = of_value (of_list (of_pair of_string of_pp)) (Good vars) |
| 1152 |
let of_stack frames = of_value (of_list (of_pair of_string (of_option |
| 1153 |
(of_pair of_string (of_list of_int))))) (Good frames) |
| 1154 |
|
| 1155 |
|