1 (* Copyright (C) 2000, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
26 (* $Id: cicPp.ml 7413 2007-05-29 15:30:53Z tassi $ *)
29 let apply_subst subst t = assert (subst=[]); t;;
31 type typformerreference = NReference.reference
32 type reference = NReference.reference
36 | KArrow of kind * kind
37 | KSkip of kind (* dropped abstraction *)
43 | TConst of typformerreference
46 | Forall of string * kind * typ
53 | Lambda of string * (* typ **) term
55 | LetIn of string * (* typ **) term * term
56 | Match of reference * term * term list
57 | TLambda of (* string **) term
58 | Inst of (*typ_former **) term
61 NCic.Const (NReference.reference_of_spec (NUri.uri_of_string "cic:/matita/basics/types/unit.ind") (NReference.Ind (true,0,0)));;
63 (* None = dropped abstraction *)
64 type typ_context = (string * kind) option list
65 type term_context = (string * [`OfKind of kind | `OfType of typ]) option list
67 type typ_former_decl = typ_context * kind
68 type typ_former_def = typ_former_decl * typ
70 type term_former_decl = term_context * typ
71 type term_former_def = term_former_decl * term
74 TypeDeclaration of typ_former_decl
75 | TypeDefinition of typ_former_def
76 | TermDeclaration of term_former_decl
77 | TermDefinition of term_former_def
78 | LetRec of (string * typ * term) list
79 (* inductive and records missing *)
81 type obj = NUri.uri * obj_kind
85 let rec classify_not_term status no_dep_prods context t =
86 match NCicReduction.whd status ~subst:[] context t with
90 | NCic.Type [`CProp,_] -> `PropKind
91 | NCic.Type [`Type,_] ->
92 if no_dep_prods then `Kind
94 raise NotInFOmega (* ?? *)
95 | NCic.Type _ -> assert false)
96 | NCic.Prod (b,s,t) ->
97 (*CSC: using invariant on "_" *)
98 classify_not_term status (no_dep_prods && b.[0] = '_')
99 ((b,NCic.Decl s)::context) t
103 | NCic.Const (NReference.Ref (_,NReference.CoFix _))
104 | NCic.Appl [] -> assert false (* NOT POSSIBLE *)
106 | NCic.Const (NReference.Ref (_,NReference.Fix _)) ->
107 (* be aware: we can be the head of an application *)
108 assert false (* TODO *)
109 | NCic.Meta _ -> assert false (* TODO *)
110 | NCic.Appl (he::_) -> classify_not_term status no_dep_prods context he
112 let rec find_sort typ =
113 match NCicReduction.whd status ~subst:[] context (NCicSubstitution.lift status n typ) with
114 NCic.Sort NCic.Prop -> `Proposition
115 | NCic.Sort (NCic.Type [`CProp,_]) -> `Proposition
116 | NCic.Sort (NCic.Type [`Type,_]) ->
117 (*CSC: we could be more precise distinguishing the user provided
118 minimal elements of the hierarchies and classify these
121 | NCic.Sort (NCic.Type _) -> assert false (* ALGEBRAIC *)
122 | NCic.Prod (_,_,t) ->
123 (* we skipped arguments of applications, so here we need to skip
126 | _ -> assert false (* NOT A SORT *)
128 (match List.nth context (n-1) with
129 _,NCic.Decl typ -> find_sort typ
130 | _,NCic.Def _ -> assert false (* IMPOSSIBLE *))
131 | NCic.Const (NReference.Ref (_,NReference.Decl) as ref) ->
132 let _,_,ty,_,_ = NCicEnvironment.get_checked_decl status ref in
133 (match classify_not_term status true [] ty with
135 | `Type -> assert false (* IMPOSSIBLE *)
137 | `KindOrType -> `Type
138 | `PropKind -> `Proposition)
139 | NCic.Const (NReference.Ref (_,NReference.Ind _) as ref) ->
140 let _,_,ityl,_,i = NCicEnvironment.get_checked_indtys status ref in
141 let _,_,arity,_ = List.nth ityl i in
142 (match classify_not_term status true [] arity with
145 | `KindOrType -> assert false (* IMPOSSIBLE *)
147 | `PropKind -> `Proposition)
148 | NCic.Const (NReference.Ref (_,NReference.Con _))
149 | NCic.Const (NReference.Ref (_,NReference.Def _)) ->
150 assert false (* IMPOSSIBLE *)
153 type not_term = [`Kind | `KindOrType | `PropKind | `Proposition | `Type];;
155 let classify status ~metasenv context t =
156 match NCicTypeChecker.typeof status ~metasenv ~subst:[] context t with
158 (classify_not_term status true context t : not_term :> [> not_term])
160 let ty = fix_sorts ty in
162 (match classify_not_term status true context ty with
163 | `Proposition -> `Proof
165 | `KindOrType -> `TypeFormerOrTerm
166 | `Kind -> `TypeFormer
167 | `PropKind -> `PropFormer)
171 let rec kind_of status ~metasenv context k =
172 match NCicReduction.whd status ~subst:[] context k with
173 | NCic.Sort NCic.Type _ -> Type
174 | NCic.Sort _ -> assert false (* NOT A KIND *)
175 | NCic.Prod (b,s,t) ->
176 (* CSC: non-invariant assumed here about "_" *)
177 (match classify status ~metasenv context s with
179 | `KindOrType -> (* KindOrType OK?? *)
180 KArrow (kind_of status ~metasenv context s,
181 kind_of ~metasenv status ((b,NCic.Decl s)::context) t)
185 KSkip (kind_of status ~metasenv ((b,NCic.Decl s)::context) t)
186 | `Term _ -> assert false (* IMPOSSIBLE *))
188 | NCic.LetIn _ -> assert false (* IMPOSSIBLE *)
191 | NCic.Const _ -> assert false (* NOT A KIND *)
192 | NCic.Appl _ -> assert false (* TODO: when head is a match/let rec;
193 otherwise NOT A KIND *)
195 | NCic.Match (_,_,_,_) -> assert false (* TODO *)
198 let rec skip_args status ~metasenv context =
201 | [],_ -> assert false (* IMPOSSIBLE *)
202 | None::tl1,_::tl2 -> skip_args status ~metasenv context (tl1,tl2)
204 match classify status ~metasenv context arg with
207 | `Term `TypeFormer ->
208 Some arg::skip_args status ~metasenv context (tl1,tl2)
211 | `PropKind -> None::skip_args status ~metasenv context (tl1,tl2)
212 | `Term _ -> assert false (* IMPOSSIBLE *)
215 module ReferenceMap = Map.Make(struct type t = NReference.reference let compare = NReference.compare end)
217 type db = (typ_context * typ option) ReferenceMap.t
219 class type g_status =
221 method extraction_db: db
224 class virtual status =
227 val extraction_db = ReferenceMap.empty
228 method extraction_db = extraction_db
229 method set_extraction_db v = {< extraction_db = v >}
230 method set_extraction_status
231 : 'status. #g_status as 'status -> 'self
232 = fun o -> {< extraction_db = o#extraction_db >}
235 let rec split_kind_prods context =
237 | KArrow (so,ta)-> split_kind_prods (Some ("_",so)::context) ta
238 | KSkip ta -> split_kind_prods (None::context) ta
239 | Type -> context,Type
242 let rec split_typ_prods context =
244 | Arrow (so,ta)-> split_typ_prods (Some ("_",`OfType so)::context) ta
245 | Forall (name,so,ta)-> split_typ_prods (Some (name,`OfKind so)::context) ta
246 | Skip ta -> split_typ_prods (None::context) ta
247 | _ as t -> context,t
250 let rec glue_ctx_typ ctx typ =
253 | Some (_,`OfType so)::ctx -> glue_ctx_typ ctx (Arrow (so,typ))
254 | Some (name,`OfKind so)::ctx -> glue_ctx_typ ctx (Forall (name,so,typ))
255 | None::ctx -> glue_ctx_typ ctx (Skip typ)
258 let rec split_typ_lambdas status n ~metasenv context typ =
259 if n = 0 then context,typ
261 match NCicReduction.whd status ~delta:max_int ~subst:[] context typ with
262 | NCic.Lambda (name,s,t) ->
263 split_typ_lambdas status (n-1) ~metasenv ((name,NCic.Decl s)::context) t
265 (* eta-expansion required *)
266 let ty = NCicTypeChecker.typeof status ~metasenv ~subst:[] context t in
267 match NCicReduction.whd status ~delta:max_int ~subst:[] context ty with
268 | NCic.Prod (name,typ,_) ->
269 split_typ_lambdas status (n-1) ~metasenv
270 ((name,NCic.Decl typ)::context)
271 (NCicUntrusted.mk_appl t [NCic.Rel 1])
272 | _ -> assert false (* IMPOSSIBLE *)
276 let context_of_typformer status ~metasenv context =
278 NCic.Const (NReference.Ref (_,NReference.Ind _) as ref)
279 | NCic.Const (NReference.Ref (_,NReference.Def _) as ref)
280 | NCic.Const (NReference.Ref (_,NReference.Decl) as ref)
281 | NCic.Const (NReference.Ref (_,NReference.Fix _) as ref) ->
282 (try fst (ReferenceMap.find ref status#extraction_db)
284 Not_found -> assert false (* IMPOSSIBLE *))
285 | NCic.Match _ -> assert false (* TODO ???? *)
288 match List.nth context (n-1) with
289 _,NCic.Decl typ -> typ
290 | _,NCic.Def _ -> assert false (* IMPOSSIBLE *) in
291 let typ_ctx = snd (HExtlib.split_nth n context) in
292 let typ = kind_of status ~metasenv typ_ctx typ in
293 fst (split_kind_prods [] typ)
294 | NCic.Meta _ -> assert false (* TODO *)
295 | NCic.Const (NReference.Ref (_,NReference.Con _))
296 | NCic.Const (NReference.Ref (_,NReference.CoFix _))
297 | NCic.Sort _ | NCic.Implicit _ | NCic.Lambda _ | NCic.LetIn _
298 | NCic.Appl _ | NCic.Prod _ ->
299 assert false (* IMPOSSIBLE *)
301 let rec typ_of status ~metasenv context k =
302 match NCicReduction.whd status ~delta:max_int ~subst:[] context k with
303 | NCic.Prod (b,s,t) ->
304 (* CSC: non-invariant assumed here about "_" *)
305 (match classify status ~metasenv context s with
307 Forall (b, kind_of status ~metasenv context s,
308 typ_of ~metasenv status ((b,NCic.Decl s)::context) t)
310 | `KindOrType -> (* ??? *)
311 Arrow (typ_of status ~metasenv context s,
312 typ_of status ~metasenv ((b,NCic.Decl s)::context) t)
315 Skip (typ_of status ~metasenv ((b,NCic.Decl s)::context) t)
316 | `Term _ -> assert false (* IMPOSSIBLE *))
319 | NCic.LetIn _ -> assert false (* IMPOSSIBLE *)
320 | NCic.Lambda _ -> assert false (* NOT A TYPE *)
321 | NCic.Rel n -> Var n
322 | NCic.Const ref -> TConst ref
323 | NCic.Appl (he::args) ->
324 let he_context = context_of_typformer status ~metasenv context he in
325 TAppl (typ_of status ~metasenv context he ::
327 (function None -> Unit | Some ty -> typ_of status ~metasenv context ty)
328 (skip_args status ~metasenv context (List.rev he_context,args)))
329 | NCic.Appl _ -> assert false (* TODO: when head is a match/let rec;
330 otherwise NOT A TYPE *)
332 | NCic.Match (_,_,_,_) -> assert false (* TODO *)
335 let rec fomega_subst k t1 =
339 else if n < k then Var n
342 | TConst ref -> TConst ref
344 | Arrow (ty1,ty2) -> Arrow (fomega_subst k t1 ty1, fomega_subst (k+1) t1 ty2)
345 | Skip t -> Skip (fomega_subst (k+1) t1 t)
346 | Forall (n,kind,t) -> Forall (n,kind,fomega_subst (k+1) t1 t)
347 | TAppl args -> TAppl (List.map (fomega_subst k t1) args)
349 let fomega_lookup status ref = snd (ReferenceMap.find ref status#extraction_db)
351 let rec fomega_whd status ty =
354 (match fomega_lookup status r with
356 | Some ty -> fomega_whd status ty)
357 | TAppl (TConst r::args) ->
358 (match fomega_lookup status r with
360 | Some ty -> fomega_whd status (List.fold_right (fomega_subst 1) args ty))
363 let rec term_of status ~metasenv context =
367 | NCic.Prod _ -> assert false (* IMPOSSIBLE *)
368 | NCic.Lambda (b,ty,bo) ->
369 (* CSC: non-invariant assumed here about "_" *)
370 (match classify status ~metasenv context ty with
372 TLambda (term_of status ~metasenv ((b,NCic.Decl ty)::context) bo)
373 | `KindOrType (* ??? *)
375 Lambda (b, term_of status ~metasenv ((b,NCic.Decl ty)::context) bo)
379 term_of status ~metasenv ((b,NCic.Decl ty)::context) bo
380 | `Term _ -> assert false (* IMPOSSIBLE *))
381 | NCic.LetIn (b,ty,t,bo) ->
382 (match classify status ~metasenv context t with
383 | `Term `TypeFormerOrTerm (* ???? *)
385 LetIn (b,term_of status ~metasenv context t,
386 term_of status ~metasenv ((b,NCic.Def (t,ty))::context) bo)
395 (* not in programming languages, we expand it *)
396 term_of status ~metasenv context
397 (NCicSubstitution.subst status ~avoid_beta_redexes:true t bo))
398 | NCic.Rel n -> Rel n
399 | NCic.Const ref -> Const ref
400 | NCic.Appl (he::args) ->
401 eat_args status metasenv
402 (term_of status ~metasenv context he) context
403 (typ_of status ~metasenv context
404 (NCicTypeChecker.typeof status ~metasenv ~subst:[] context he))
407 let he_context = context_of_typformer status ~metasenv context he in
408 let process_args he =
411 | `Inst tl -> Inst (process_args he tl)
412 | `Appl (arg,tl) -> process_args (Appl (he,... arg)) tl
414 Appl (typ_of status ~metasenv context he ::
415 process_args (typ_of status ~metasenv context he)
416 (skip_term_args status ~metasenv context (List.rev he_context,args))
418 | NCic.Appl _ -> assert false (* TODO: when head is a match/let rec;
419 otherwise NOT A TYPE *)
420 | NCic.Meta _ -> assert false (* TODO *)
421 | NCic.Match (ref,_,t,pl) ->
422 Match (ref,term_of status ~metasenv context t,
423 List.map (term_of status ~metasenv context) pl)
424 and eat_args status metasenv acc context tyhe =
430 Appl args -> Appl (args@[x])
433 match fomega_whd status tyhe with
438 | _ -> term_of status ~metasenv context arg in
439 eat_args status metasenv (mk_appl acc arg) context t tl
441 eat_args status metasenv (Inst acc)
442 context (fomega_subst 1 (typ_of status ~metasenv context arg) t) tl
444 eat_args status metasenv acc context t tl
445 | Top -> assert false (*TODO: HOW??*)
446 | Unit | Var _ | TConst _ | TAppl _ -> assert false (* NOT A PRODUCT *)
449 let obj_of status (uri,height,metasenv,subst,obj_kind) =
450 let obj_kind = apply_subst subst obj_kind in
453 | NCic.Constant (_,_,None,ty,_) ->
454 (match classify status ~metasenv [] ty with
456 let ty = kind_of status ~metasenv [] ty in
457 let ctx,_ as res = split_kind_prods [] ty in
458 let ref = NReference.reference_of_spec uri NReference.Decl in
459 status#set_extraction_db
460 (ReferenceMap.add ref (ctx,None) status#extraction_db),
461 Some (uri, TypeDeclaration res)
463 | `Proposition -> status, None
465 | `KindOrType (*???*) ->
466 let ty = typ_of status ~metasenv [] ty in
468 Some (uri, TermDeclaration (split_typ_prods [] ty))
469 | `Term _ -> assert false (* IMPOSSIBLE *))
470 | NCic.Constant (_,_,Some bo,ty,_) ->
471 (match classify status ~metasenv [] ty with
473 let ty = kind_of status ~metasenv [] ty in
474 let ctx0,res = split_kind_prods [] ty in
476 split_typ_lambdas status ~metasenv (List.length ctx0) [] bo in
477 (match classify status ~metasenv ctx bo with
479 | `KindOrType -> (* ?? no kind formers in System F_omega *)
483 HExtlib.map_option (fun (_,k) ->
484 (*CSC: BUG here, clashes*)
485 String.uncapitalize (fst n),k) p1)
489 NReference.reference_of_spec uri (NReference.Def height) in
490 let bo = typ_of status ~metasenv ctx bo in
491 status#set_extraction_db
492 (ReferenceMap.add ref (nicectx,Some bo)
493 status#extraction_db),
494 Some (uri,TypeDefinition((nicectx,res),bo))
495 | `Kind -> status, None
497 | `Proposition -> status, None
498 | `Term _ -> assert false (* IMPOSSIBLE *))
500 | `Proposition -> status, None
501 | `KindOrType (* ??? *)
503 (* CSC: TO BE FINISHED, REF NON REGISTERED *)
504 let ty = typ_of status ~metasenv [] ty in
506 Some (uri, TermDefinition (split_typ_prods [] ty,
507 term_of status ~metasenv [] bo))
508 | `Term _ -> assert false (* IMPOSSIBLE *))
511 prerr_endline "-- NOT IN F_omega";
514 (************************ HASKELL *************************)
516 (*CSC: code to be changed soon when we implement constructors and
517 we fix the code for term application *)
518 let classify_reference status ref =
519 if ReferenceMap.mem ref status#extraction_db then
524 let capitalize classification name =
525 match classification with
527 | `TypeName -> String.capitalize name
528 | `FunctionName -> String.uncapitalize name
530 let pp_ref status ref =
531 capitalize (classify_reference status ref)
532 (NCicPp.r2s status false ref)
534 let name_of_uri classification uri =
535 capitalize classification (NUri.name_of_uri uri)
537 (* cons avoid duplicates *)
538 let rec (@::) name l =
539 if name <> "" (* propositional things *) && name.[0] = '_' then
540 let name = String.sub name 1 (String.length name - 1) in
541 let name = if name = "" then "a" else name in
543 else if List.mem name l then (name ^ "'") @:: l
550 | KArrow (k1,k2) -> "(" ^ pp_kind k1 ^ ") -> " ^ pp_kind k2
551 | KSkip k -> pp_kind k
553 let rec pp_typ status ctx =
555 Var n -> List.nth ctx (n-1)
557 | Top -> assert false (* ??? *)
558 | TConst ref -> pp_ref status ref
559 | Arrow (t1,t2) -> "(" ^ pp_typ status ctx t1 ^ ") -> " ^ pp_typ status ("_"::ctx) t2
560 | Skip t -> pp_typ status ("_"::ctx) t
561 | Forall (name,_,t) ->
562 (*CSC: BUG HERE: avoid clashes due to uncapitalisation*)
563 let name = String.uncapitalize name in
564 "(forall " ^ name ^ ". " ^ pp_typ status (name@::ctx) t ^")"
565 | TAppl tl -> "(" ^ String.concat " " (List.map (pp_typ status ctx) tl) ^ ")"
567 let rec pp_term status ctx =
569 Rel n -> List.nth ctx (n-1)
571 | Const ref -> pp_ref status ref
572 | Lambda (name,t) -> "(\\" ^ name ^ " -> " ^ pp_term status (name@::ctx) t ^ ")"
573 | Appl tl -> "(" ^ String.concat " " (List.map (pp_term status ctx) tl) ^ ")"
574 | LetIn (name,s,t) ->
575 "(let " ^ name ^ " = " ^ pp_term status ctx s ^ " in " ^ pp_term status (name@::ctx) t ^
577 | Match _ -> assert false (* TODO of reference * term * term list *)
578 | TLambda t -> pp_term status ctx t
579 | Inst t -> pp_term status ctx t
582 type term_context = (string * [`OfKind of kind | `OfType of typ]) option list
584 type term_former_def = term_context * term * typ
585 type term_former_decl = term_context * typ
588 let pp_obj status (uri,obj_kind) =
590 String.concat " " (List.rev
591 (List.fold_right (fun (x,_) l -> x@::l)
592 (HExtlib.filter_map (fun x -> x) ctx) [])) in
593 let namectx_of_ctx ctx =
594 List.fold_right (@::)
595 (List.map (function None -> "" | Some (x,_) -> x) ctx) [] in
597 TypeDeclaration (ctx,_) ->
598 (* data?? unsure semantics: inductive type without constructor, but
599 not matchable apparently *)
600 "data " ^ name_of_uri `TypeName uri ^ " " ^ pp_ctx ctx
601 | TypeDefinition ((ctx,_),ty) ->
602 let namectx = namectx_of_ctx ctx in
603 "type " ^ name_of_uri `TypeName uri ^ " " ^ pp_ctx ctx ^ " = " ^
604 pp_typ status namectx ty
605 | TermDeclaration (ctx,ty) ->
606 (* Implemented with undefined, the best we can do *)
607 let name = name_of_uri `FunctionName uri in
608 name ^ " :: " ^ pp_typ status [] (glue_ctx_typ ctx ty) ^ "\n" ^
609 name ^ " = undefined"
610 | TermDefinition ((ctx,ty),bo) ->
611 let name = name_of_uri `FunctionName uri in
612 let namectx = namectx_of_ctx ctx in
613 name ^ " :: " ^ pp_typ status ["a";"b";"c"] (glue_ctx_typ ctx ty) ^ "\n" ^
614 name ^ " = " ^ pp_term status namectx bo
615 | LetRec _ -> assert false (* TODO
616 (* inductive and records missing *)*)
618 let haskell_of_obj status obj =
619 let status, obj = obj_of status obj in
622 None -> "-- ERASED\n"
623 | Some obj -> pp_obj status obj ^ "\n"
626 let rec typ_of context =
632 (match get_nth context n with
633 Some (C.Name s,_) -> ppid s
634 | Some (C.Anonymous,_) -> "__" ^ string_of_int n
635 | None -> "_hidden_" ^ string_of_int n
638 NotEnoughElements -> string_of_int (List.length context - n)
643 "?" ^ (string_of_int n) ^ "[" ^
648 | Some t -> pp ~in_type:false t context) l1) ^
652 let _,context,_ = CicUtil.lookup_meta n metasenv in
653 "?" ^ (string_of_int n) ^ "[" ^
661 | Some _, Some t -> pp ~in_type:false t context
665 CicUtil.Meta_not_found _
666 | Invalid_argument _ ->
667 "???" ^ (string_of_int n) ^ "[" ^
669 (List.rev_map (function None -> "_" | Some t ->
670 pp ~in_type:false t context) l1) ^
678 (*| C.Type u -> ("Type" ^ CicUniv.string_of_universe u)*)
679 | C.CProp _ -> "CProp"
681 | C.Implicit (Some `Hole) -> "%"
682 | C.Implicit _ -> "?"
684 (match b, is_term s with
685 _, true -> typ_of (None::context) t
686 | "_",_ -> Arrow (typ_of context s) (typ_of (Some b::context) t)
687 | _,_ -> Forall (b,typ_of (Some b::context) t)
688 | C.Lambda (b,s,t) ->
689 (match analyze_type context s with
691 | `Statement -> pp ~in_type t ((Some (b,Cic.Decl s))::context)
692 | `Optimize -> prerr_endline "XXX lambda";assert false
694 "(function " ^ ppname b ^ " -> " ^
695 pp ~in_type t ((Some (b,Cic.Decl s))::context) ^ ")")
696 | C.LetIn (b,s,ty,t) ->
697 (match analyze_term context s with
699 | `Proof -> pp ~in_type t ((Some (b,Cic.Def (s,ty)))::context)
702 "(let " ^ ppname b ^ (*" : " ^ pp ~in_type:true ty context ^*)
703 " = " ^ pp ~in_type:false s context ^ " in " ^
704 pp ~in_type t ((Some (b,Cic.Def (s,ty)))::context) ^ ")")
705 | C.Appl (he::tl) when in_type ->
706 let hes = pp ~in_type he context in
707 let stl = String.concat "," (clean_args_for_ty context tl) in
708 (if stl = "" then "" else "(" ^ stl ^ ") ") ^ hes
709 | C.Appl (C.MutInd _ as he::tl) ->
710 let hes = pp ~in_type he context in
711 let stl = String.concat "," (clean_args_for_ty context tl) in
712 (if stl = "" then "" else "(" ^ stl ^ ") ") ^ hes
713 | C.Appl (C.MutConstruct (uri,n,_,_) as he::tl) ->
715 match fst(CicEnvironment.get_obj CicUniv.oblivion_ugraph uri) with
716 C.InductiveDefinition (_,_,nparams,_) -> nparams
717 | _ -> assert false in
718 let hes = pp ~in_type he context in
719 let stl = String.concat "," (clean_args_for_constr nparams context tl) in
720 "(" ^ hes ^ (if stl = "" then "" else "(" ^ stl ^ ")") ^ ")"
722 "(" ^ String.concat " " (clean_args context li) ^ ")"
723 | C.Const (uri,exp_named_subst) ->
724 qualified_name_of_uri status current_module_uri uri ^
725 pp_exp_named_subst exp_named_subst context
726 | C.MutInd (uri,n,exp_named_subst) ->
728 match fst(CicEnvironment.get_obj CicUniv.oblivion_ugraph uri) with
729 C.InductiveDefinition (dl,_,_,_) ->
730 let (name,_,_,_) = get_nth dl (n+1) in
731 qualified_name_of_uri status current_module_uri
732 (UriManager.uri_of_string
733 (UriManager.buri_of_uri uri ^ "/" ^ name ^ ".con")) ^
734 pp_exp_named_subst exp_named_subst context
735 | _ -> raise CicExportationInternalError
737 Sys.Break as exn -> raise exn
738 | _ -> UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (n + 1)
740 | C.MutConstruct (uri,n1,n2,exp_named_subst) ->
742 match fst(CicEnvironment.get_obj CicUniv.oblivion_ugraph uri) with
743 C.InductiveDefinition (dl,_,_,_) ->
744 let _,_,_,cons = get_nth dl (n1+1) in
745 let id,_ = get_nth cons n2 in
746 qualified_name_of_uri status current_module_uri ~capitalize:true
747 (UriManager.uri_of_string
748 (UriManager.buri_of_uri uri ^ "/" ^ id ^ ".con")) ^
749 pp_exp_named_subst exp_named_subst context
750 | _ -> raise CicExportationInternalError
752 Sys.Break as exn -> raise exn
754 UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (n1 + 1) ^ "/" ^
757 | C.MutCase (uri,n1,ty,te,patterns) ->
759 "unit (* TOO POLYMORPHIC TYPE *)"
761 let rec needs_obj_magic ty =
762 match CicReduction.whd context ty with
763 | Cic.Lambda (_,_,(Cic.Lambda(_,_,_) as t)) -> needs_obj_magic t
764 | Cic.Lambda (_,_,t) -> not (DoubleTypeInference.does_not_occur 1 t)
765 | _ -> false (* it can be a Rel, e.g. in *_rec *)
767 let needs_obj_magic = needs_obj_magic ty in
768 (match analyze_term context te with
769 `Type -> assert false
772 [] -> "assert false" (* empty type elimination *)
774 pp ~in_type:false he context (* singleton elimination *)
778 if patterns = [] then "assert false"
780 (let connames_and_argsno, go_up, go_pu, go_down, go_nwod =
781 (match fst(CicEnvironment.get_obj CicUniv.oblivion_ugraph uri) with
782 C.InductiveDefinition (dl,_,paramsno,_) ->
783 let (_,_,_,cons) = get_nth dl (n1+1) in
787 (* this is just an approximation since we do not have
789 let rec count_prods toskip =
791 C.Prod (_,_,bo) when toskip > 0 ->
792 count_prods (toskip - 1) bo
793 | C.Prod (_,_,bo) -> 1 + count_prods 0 bo
796 qualified_name_of_uri status current_module_uri
798 (UriManager.uri_of_string
799 (UriManager.buri_of_uri uri ^ "/" ^ id ^ ".con")),
800 count_prods paramsno ty
803 if not (is_mcu_type uri) then rc, "","","",""
804 else rc, !current_go_up, "))", "( .< (", " ) >.)"
805 | _ -> raise CicExportationInternalError
808 let connames_and_argsno_and_patterns =
812 | (x,no)::tlx,y::tly -> (x,no,y)::(combine (tlx,tly))
813 | _,_ -> assert false
815 combine (connames_and_argsno,patterns)
818 "\n(match " ^ pp ~in_type:false te context ^ " with \n " ^
819 (String.concat "\n | "
822 let rec aux argsno context =
824 Cic.Lambda (name,ty,bo) when argsno > 0 ->
827 Cic.Anonymous -> Cic.Anonymous
828 | Cic.Name n -> Cic.Name (ppid n) in
830 aux (argsno - 1) (Some (name,Cic.Decl ty)::context)
833 (match analyze_type context ty with
834 | `Optimize -> prerr_endline "XXX contructor with l2 arg"; assert false
836 | `Sort _ -> args,res
840 | C.Name s -> s)::args,res)
841 | t when argsno = 0 -> [],pp ~in_type:false t context
843 ["{" ^ string_of_int argsno ^ " args missing}"],
844 pp ~in_type:false t context
847 if argsno = 0 then x,pp ~in_type:false y context
849 let args,body = aux argsno context y in
850 let sargs = String.concat "," args in
851 x ^ (if sargs = "" then "" else "(" ^ sargs^ ")"),
854 pattern ^ " -> " ^ go_down ^
855 (if needs_obj_magic then
856 "Obj.magic (" ^ body ^ ")"
859 ) connames_and_argsno_and_patterns)) ^
861 | C.Fix (no, funs) ->
864 (fun (types,len) (n,_,ty,_) ->
865 (Some (C.Name n,(C.Decl (CicSubstitution.lift len ty)))::types,
871 (fun (name,ind,ty,bo) i -> name ^ " = \n" ^
872 pp ~in_type:false bo (names@context) ^ i)
875 (match get_nth names (no + 1) with
876 Some (Cic.Name n,_) -> n
878 | C.CoFix (no,funs) ->
881 (fun (types,len) (n,ty,_) ->
882 (Some (C.Name n,(C.Decl (CicSubstitution.lift len ty)))::types,
888 (fun (name,ty,bo) i -> "\n" ^ name ^
889 " : " ^ pp ~in_type:true ty context ^ " := \n" ^
890 pp ~in_type:false bo (names@context) ^ i)
896 exception CicExportationInternalError;;
897 exception NotEnoughElements;;
902 UriManager.eq (UriManager.uri_of_string
903 "cic:/matita/freescale/opcode/mcu_type.ind") u
906 (* Utility functions *)
908 let analyze_term context t =
909 match fst(CicTypeChecker.type_of_aux' [] context t CicUniv.oblivion_ugraph)with
910 | Cic.Sort _ -> `Type
911 | Cic.MutInd (u,0,_) when is_mcu_type u -> `Optimize
914 fst (CicTypeChecker.type_of_aux' [] context ty CicUniv.oblivion_ugraph)
916 | Cic.Sort Cic.Prop -> `Proof
920 let analyze_type context t =
923 Cic.Sort s -> `Sort s
924 | Cic.MutInd (u,0,_) when is_mcu_type u -> `Optimize
925 | Cic.Prod (_,_,t) -> aux t
926 | _ -> `SomethingElse
929 `Sort _ | `Optimize as res -> res
932 fst(CicTypeChecker.type_of_aux' [] context t CicUniv.oblivion_ugraph)
934 Cic.Sort Cic.Prop -> `Statement
948 let n = String.uncapitalize n in
949 if List.mem n reserved then n ^ "_" else n
955 | Cic.Anonymous -> "_"
958 (* get_nth l n returns the nth element of the list l if it exists or *)
959 (* raises NotEnoughElements if l has less than n elements *)
960 let rec get_nth l n =
963 | (n, he::tail) when n > 1 -> get_nth tail (n-1)
964 | (_,_) -> raise NotEnoughElements
967 let qualified_name_of_uri status current_module_uri ?(capitalize=false) uri =
970 String.capitalize (UriManager.name_of_uri status uri)
972 ppid (UriManager.name_of_uri status uri) in
974 let suri = UriManager.buri_of_uri uri in
975 let s = String.sub suri 5 (String.length suri - 5) in
976 let s = Pcre.replace ~pat:"/" ~templ:"_" s in
977 String.uncapitalize s in
978 if current_module_uri = UriManager.buri_of_uri uri then
981 String.capitalize filename ^ "." ^ name
984 let current_go_up = ref "(.!(";;
987 current_go_up := "(.~(";
989 current_go_up := "(.!(";
992 current_go_up := "(.!(";
996 let pp current_module_uri ?metasenv ~in_type =
997 let rec pp ~in_type t context =
998 let module C = Cic in
1003 (match get_nth context n with
1004 Some (C.Name s,_) -> ppid s
1005 | Some (C.Anonymous,_) -> "__" ^ string_of_int n
1006 | None -> "_hidden_" ^ string_of_int n
1009 NotEnoughElements -> string_of_int (List.length context - n)
1011 | C.Var (uri,exp_named_subst) ->
1012 qualified_name_of_uri status current_module_uri uri ^
1013 pp_exp_named_subst exp_named_subst context
1015 (match metasenv with
1017 "?" ^ (string_of_int n) ^ "[" ^
1022 | Some t -> pp ~in_type:false t context) l1) ^
1026 let _,context,_ = CicUtil.lookup_meta n metasenv in
1027 "?" ^ (string_of_int n) ^ "[" ^
1035 | Some _, Some t -> pp ~in_type:false t context
1039 CicUtil.Meta_not_found _
1040 | Invalid_argument _ ->
1041 "???" ^ (string_of_int n) ^ "[" ^
1043 (List.rev_map (function None -> "_" | Some t ->
1044 pp ~in_type:false t context) l1) ^
1051 | C.Type _ -> "Type"
1052 (*| C.Type u -> ("Type" ^ CicUniv.string_of_universe u)*)
1053 | C.CProp _ -> "CProp"
1055 | C.Implicit (Some `Hole) -> "%"
1056 | C.Implicit _ -> "?"
1060 let n = "'" ^ String.uncapitalize n in
1061 "(" ^ pp ~in_type:true s context ^ " -> " ^
1062 pp ~in_type:true t ((Some (Cic.Name n,Cic.Decl s))::context) ^ ")"
1064 "(" ^ pp ~in_type:true s context ^ " -> " ^
1065 pp ~in_type:true t ((Some (b,Cic.Decl s))::context) ^ ")")
1066 | C.Cast (v,t) -> pp ~in_type v context
1067 | C.Lambda (b,s,t) ->
1068 (match analyze_type context s with
1070 | `Statement -> pp ~in_type t ((Some (b,Cic.Decl s))::context)
1071 | `Optimize -> prerr_endline "XXX lambda";assert false
1073 "(function " ^ ppname b ^ " -> " ^
1074 pp ~in_type t ((Some (b,Cic.Decl s))::context) ^ ")")
1075 | C.LetIn (b,s,ty,t) ->
1076 (match analyze_term context s with
1078 | `Proof -> pp ~in_type t ((Some (b,Cic.Def (s,ty)))::context)
1081 "(let " ^ ppname b ^ (*" : " ^ pp ~in_type:true ty context ^*)
1082 " = " ^ pp ~in_type:false s context ^ " in " ^
1083 pp ~in_type t ((Some (b,Cic.Def (s,ty)))::context) ^ ")")
1084 | C.Appl (he::tl) when in_type ->
1085 let hes = pp ~in_type he context in
1086 let stl = String.concat "," (clean_args_for_ty context tl) in
1087 (if stl = "" then "" else "(" ^ stl ^ ") ") ^ hes
1088 | C.Appl (C.MutInd _ as he::tl) ->
1089 let hes = pp ~in_type he context in
1090 let stl = String.concat "," (clean_args_for_ty context tl) in
1091 (if stl = "" then "" else "(" ^ stl ^ ") ") ^ hes
1092 | C.Appl (C.MutConstruct (uri,n,_,_) as he::tl) ->
1094 match fst(CicEnvironment.get_obj CicUniv.oblivion_ugraph uri) with
1095 C.InductiveDefinition (_,_,nparams,_) -> nparams
1096 | _ -> assert false in
1097 let hes = pp ~in_type he context in
1098 let stl = String.concat "," (clean_args_for_constr nparams context tl) in
1099 "(" ^ hes ^ (if stl = "" then "" else "(" ^ stl ^ ")") ^ ")"
1101 "(" ^ String.concat " " (clean_args context li) ^ ")"
1102 | C.Const (uri,exp_named_subst) ->
1103 qualified_name_of_uri status current_module_uri uri ^
1104 pp_exp_named_subst exp_named_subst context
1105 | C.MutInd (uri,n,exp_named_subst) ->
1107 match fst(CicEnvironment.get_obj CicUniv.oblivion_ugraph uri) with
1108 C.InductiveDefinition (dl,_,_,_) ->
1109 let (name,_,_,_) = get_nth dl (n+1) in
1110 qualified_name_of_uri status current_module_uri
1111 (UriManager.uri_of_string
1112 (UriManager.buri_of_uri uri ^ "/" ^ name ^ ".con")) ^
1113 pp_exp_named_subst exp_named_subst context
1114 | _ -> raise CicExportationInternalError
1116 Sys.Break as exn -> raise exn
1117 | _ -> UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (n + 1)
1119 | C.MutConstruct (uri,n1,n2,exp_named_subst) ->
1121 match fst(CicEnvironment.get_obj CicUniv.oblivion_ugraph uri) with
1122 C.InductiveDefinition (dl,_,_,_) ->
1123 let _,_,_,cons = get_nth dl (n1+1) in
1124 let id,_ = get_nth cons n2 in
1125 qualified_name_of_uri status current_module_uri ~capitalize:true
1126 (UriManager.uri_of_string
1127 (UriManager.buri_of_uri uri ^ "/" ^ id ^ ".con")) ^
1128 pp_exp_named_subst exp_named_subst context
1129 | _ -> raise CicExportationInternalError
1131 Sys.Break as exn -> raise exn
1133 UriManager.string_of_uri uri ^ "#1/" ^ string_of_int (n1 + 1) ^ "/" ^
1136 | C.MutCase (uri,n1,ty,te,patterns) ->
1138 "unit (* TOO POLYMORPHIC TYPE *)"
1140 let rec needs_obj_magic ty =
1141 match CicReduction.whd context ty with
1142 | Cic.Lambda (_,_,(Cic.Lambda(_,_,_) as t)) -> needs_obj_magic t
1143 | Cic.Lambda (_,_,t) -> not (DoubleTypeInference.does_not_occur 1 t)
1144 | _ -> false (* it can be a Rel, e.g. in *_rec *)
1146 let needs_obj_magic = needs_obj_magic ty in
1147 (match analyze_term context te with
1148 `Type -> assert false
1150 (match patterns with
1151 [] -> "assert false" (* empty type elimination *)
1153 pp ~in_type:false he context (* singleton elimination *)
1154 | _ -> assert false)
1157 if patterns = [] then "assert false"
1159 (let connames_and_argsno, go_up, go_pu, go_down, go_nwod =
1160 (match fst(CicEnvironment.get_obj CicUniv.oblivion_ugraph uri) with
1161 C.InductiveDefinition (dl,_,paramsno,_) ->
1162 let (_,_,_,cons) = get_nth dl (n1+1) in
1166 (* this is just an approximation since we do not have
1168 let rec count_prods toskip =
1170 C.Prod (_,_,bo) when toskip > 0 ->
1171 count_prods (toskip - 1) bo
1172 | C.Prod (_,_,bo) -> 1 + count_prods 0 bo
1175 qualified_name_of_uri status current_module_uri
1177 (UriManager.uri_of_string
1178 (UriManager.buri_of_uri uri ^ "/" ^ id ^ ".con")),
1179 count_prods paramsno ty
1182 if not (is_mcu_type uri) then rc, "","","",""
1183 else rc, !current_go_up, "))", "( .< (", " ) >.)"
1184 | _ -> raise CicExportationInternalError
1187 let connames_and_argsno_and_patterns =
1191 | (x,no)::tlx,y::tly -> (x,no,y)::(combine (tlx,tly))
1192 | _,_ -> assert false
1194 combine (connames_and_argsno,patterns)
1197 "\n(match " ^ pp ~in_type:false te context ^ " with \n " ^
1198 (String.concat "\n | "
1200 (fun (x,argsno,y) ->
1201 let rec aux argsno context =
1203 Cic.Lambda (name,ty,bo) when argsno > 0 ->
1206 Cic.Anonymous -> Cic.Anonymous
1207 | Cic.Name n -> Cic.Name (ppid n) in
1209 aux (argsno - 1) (Some (name,Cic.Decl ty)::context)
1212 (match analyze_type context ty with
1213 | `Optimize -> prerr_endline "XXX contructor with l2 arg"; assert false
1215 | `Sort _ -> args,res
1219 | C.Name s -> s)::args,res)
1220 | t when argsno = 0 -> [],pp ~in_type:false t context
1222 ["{" ^ string_of_int argsno ^ " args missing}"],
1223 pp ~in_type:false t context
1226 if argsno = 0 then x,pp ~in_type:false y context
1228 let args,body = aux argsno context y in
1229 let sargs = String.concat "," args in
1230 x ^ (if sargs = "" then "" else "(" ^ sargs^ ")"),
1233 pattern ^ " -> " ^ go_down ^
1234 (if needs_obj_magic then
1235 "Obj.magic (" ^ body ^ ")"
1238 ) connames_and_argsno_and_patterns)) ^
1240 | C.Fix (no, funs) ->
1243 (fun (types,len) (n,_,ty,_) ->
1244 (Some (C.Name n,(C.Decl (CicSubstitution.lift len ty)))::types,
1250 (fun (name,ind,ty,bo) i -> name ^ " = \n" ^
1251 pp ~in_type:false bo (names@context) ^ i)
1254 (match get_nth names (no + 1) with
1255 Some (Cic.Name n,_) -> n
1256 | _ -> assert false)
1257 | C.CoFix (no,funs) ->
1260 (fun (types,len) (n,ty,_) ->
1261 (Some (C.Name n,(C.Decl (CicSubstitution.lift len ty)))::types,
1267 (fun (name,ty,bo) i -> "\n" ^ name ^
1268 " : " ^ pp ~in_type:true ty context ^ " := \n" ^
1269 pp ~in_type:false bo (names@context) ^ i)
1272 and pp_exp_named_subst exp_named_subst context =
1273 if exp_named_subst = [] then "" else
1275 String.concat " ; " (
1277 (function (uri,t) -> UriManager.name_of_uri status uri ^ " \\Assign " ^ pp ~in_type:false t context)
1280 and clean_args_for_constr nparams context =
1281 let nparams = ref nparams in
1285 match analyze_term context t with
1286 `Term when !nparams < 0 -> Some (pp ~in_type:false t context)
1291 and clean_args context =
1293 | [] | [_] -> assert false
1294 | he::arg1::tl as l ->
1295 let head_arg1, rest =
1296 match analyze_term context arg1 with
1298 !current_go_up :: pp ~in_type:false he context ::
1299 pp ~in_type:false arg1 context :: ["))"], tl
1305 match analyze_term context t with
1306 | `Term -> Some (pp ~in_type:false t context)
1308 prerr_endline "XXX function taking twice (or not as first) a l2 term"; assert false
1310 | `Proof -> None) rest
1311 and clean_args_for_ty context =
1314 match analyze_term context t with
1315 `Type -> Some (pp ~in_type:true t context)
1323 let ppty current_module_uri =
1324 (* nparams is the number of left arguments
1325 left arguments should either become parameters or be skipped altogether *)
1326 let rec args nparams context =
1331 Cic.Anonymous -> Cic.Anonymous
1332 | Cic.Name n -> Cic.Name (String.uncapitalize n)
1334 (match analyze_type context s with
1338 args (nparams - 1) ((Some (n,Cic.Decl s))::context) t
1339 | `Type when nparams > 0 ->
1340 args (nparams - 1) ((Some (n,Cic.Decl s))::context) t
1343 args (nparams - 1) ((Some (n,Cic.Decl s))::context) t in
1344 abstr,pp ~in_type:true current_module_uri s context::args
1345 | `Sort _ when nparams <= 0 ->
1346 let n = Cic.Name "unit (* EXISTENTIAL TYPE *)" in
1347 args (nparams - 1) ((Some (n,Cic.Decl s))::context) t
1351 Cic.Anonymous -> Cic.Anonymous
1352 | Cic.Name name -> Cic.Name ("'" ^ name) in
1354 args (nparams - 1) ((Some (n,Cic.Decl s))::context) t
1357 Cic.Anonymous -> abstr
1358 | Cic.Name name -> name::abstr),
1365 exception DoNotExtract;;
1367 let pp_abstracted_ty current_module_uri =
1368 let rec args context =
1370 Cic.Lambda (n,s,t) ->
1373 Cic.Anonymous -> Cic.Anonymous
1374 | Cic.Name n -> Cic.Name (String.uncapitalize n)
1376 (match analyze_type context s with
1381 args ((Some (n,Cic.Decl s))::context) t
1385 Cic.Anonymous -> Cic.Anonymous
1386 | Cic.Name name -> Cic.Name ("'" ^ name) in
1388 args ((Some (n,Cic.Decl s))::context) t
1391 Cic.Anonymous -> abstr
1392 | Cic.Name name -> name::abstr),
1395 match analyze_type context ty with
1397 prerr_endline "XXX abstracted l2 ty"; assert false
1399 | `Statement -> raise DoNotExtract
1401 (* BUG HERE: this can be a real System F type *)
1402 let head = pp ~in_type:true current_module_uri ty context in
1409 (* ppinductiveType (typename, inductive, arity, cons) *)
1410 (* pretty-prints a single inductive definition *)
1411 (* (typename, inductive, arity, cons) *)
1412 let ppinductiveType current_module_uri nparams (typename, inductive, arity, cons)
1414 match analyze_type [] arity with
1415 `Sort Cic.Prop -> ""
1418 | `Type -> assert false
1421 "type " ^ String.uncapitalize typename ^ " = unit (* empty type *)\n"
1425 (fun (id,ty) (_abstr,i) -> (* we should verify _abstr = abstr' *)
1426 let abstr',sargs = ppty current_module_uri nparams [] ty in
1427 let sargs = String.concat " * " sargs in
1429 String.capitalize id ^
1430 (if sargs = "" then "" else " of " ^ sargs) ^
1431 (if i = "" then "" else "\n | ") ^ i)
1435 let s = String.concat "," abstr in
1436 if s = "" then "" else "(" ^ s ^ ") "
1438 "type " ^ abstr ^ String.uncapitalize typename ^ " =\n" ^ scons ^ "\n")
1441 let ppobj current_module_uri obj =
1442 let module C = Cic in
1443 let module U = UriManager in
1444 let pp ~in_type = pp ~in_type current_module_uri in
1446 C.Constant (name, Some t1, t2, params, _) ->
1447 (match analyze_type [] t2 with
1453 | Cic.Lambda (Cic.Name arg, s, t) ->
1454 (match analyze_type [] s with
1457 "let " ^ ppid name ^ "__1 = function " ^ ppid arg
1459 at_level2 (pp ~in_type:false t) [Some (Cic.Name arg, Cic.Decl s)]
1461 ^ "let " ^ ppid name ^ "__2 = ref ([] : (unit list*unit list) list);;\n"
1462 ^ "let " ^ ppid name ^ " = function " ^ ppid arg
1463 ^ " -> (try ignore (List.assoc "^ppid arg^" (Obj.magic !"^ppid name
1464 ^"__2)) with Not_found -> "^ppid name^"__2 := (Obj.magic ("
1465 ^ ppid arg^",.! ("^ppid name^"__1 "^ppid arg^")))::!"
1466 ^ppid name^"__2); .< List.assoc "^ppid arg^" (Obj.magic (!"
1467 ^ppid name^"__2)) >.\n;;\n"
1468 ^" let xxx = prerr_endline \""^ppid name^"\"; .!("^ppid
1469 name^" Matita_freescale_opcode.HCS08)"
1471 "let " ^ ppid name ^ " =\n" ^ pp ~in_type:false t1 [] ^ "\n")
1472 | _ -> "let " ^ ppid name ^ " =\n" ^ pp ~in_type:false t1 [] ^ "\n")
1474 match analyze_type [] t1 with
1475 `Sort Cic.Prop -> ""
1476 | `Optimize -> prerr_endline "XXX aliasing l2 type"; assert false
1479 let abstr,res = pp_abstracted_ty current_module_uri [] t1 in
1481 let s = String.concat "," abstr in
1482 if s = "" then "" else "(" ^ s ^ ") "
1484 "type " ^ abstr ^ ppid name ^ " = " ^ res ^ "\n"
1486 DoNotExtract -> ""))
1487 | C.Constant (name, None, ty, params, _) ->
1488 (match analyze_type [] ty with
1490 | `Optimize -> prerr_endline "XXX axiom l2"; assert false
1492 | `Sort _ -> "type " ^ ppid name ^ "\n"
1493 | `Type -> "let " ^ ppid name ^ " = assert false\n")
1494 | C.Variable (name, bo, ty, params, _) ->
1495 "Variable " ^ name ^
1496 "(" ^ String.concat ";" (List.map UriManager.string_of_uri params) ^
1498 pp ~in_type:true ty [] ^ "\n" ^
1499 (match bo with None -> "" | Some bo -> ":= " ^ pp ~in_type:false bo [])
1500 | C.CurrentProof (name, conjectures, value, ty, params, _) ->
1501 "Current Proof of " ^ name ^
1502 "(" ^ String.concat ";" (List.map UriManager.string_of_uri params) ^
1504 let separate s = if s = "" then "" else s ^ " ; " in
1506 (fun (n, context, t) i ->
1507 let conjectures',name_context =
1509 (fun context_entry (i,name_context) ->
1510 (match context_entry with
1511 Some (n,C.Decl at) ->
1514 pp ~in_type:true ~metasenv:conjectures
1515 at name_context ^ " ",
1516 context_entry::name_context
1517 | Some (n,C.Def (at,aty)) ->
1520 pp ~in_type:true ~metasenv:conjectures
1522 ":= " ^ pp ~in_type:false
1523 ~metasenv:conjectures at name_context ^ " ",
1524 context_entry::name_context
1526 (separate i) ^ "_ :? _ ", context_entry::name_context)
1529 conjectures' ^ " |- " ^ "?" ^ (string_of_int n) ^ ": " ^
1530 pp ~in_type:true ~metasenv:conjectures t name_context ^ "\n" ^ i
1532 "\n" ^ pp ~in_type:false ~metasenv:conjectures value [] ^ " : " ^
1533 pp ~in_type:true ~metasenv:conjectures ty []
1534 | C.InductiveDefinition (l, params, nparams, _) ->
1536 (fun x i -> ppinductiveType current_module_uri nparams x ^ i) l ""
1539 let ppobj current_module_uri obj =
1540 let res = ppobj current_module_uri obj in
1541 if res = "" then "" else res ^ ";;\n\n"