Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions lib/gallinaGen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,23 @@ let inductiveBody_ iname iparams ?rtype iconstructors =
rtype, (* type I guess *)
Vernacexpr.Constructors iconstructors), [])

let definition_expr_ dbinders ?rtype dbody =
let definition_expr_ dname dbinders ?rtype dbody =
let dname = lident_ dname in
let open Vernacexpr in
DefineBody (dbinders, None, dbody, rtype)
{ fname=dname; univs=None; binders=dbinders; body_def=DefineBody (None, dbody, rtype); notations=[] }

let theorem_expr_ dname dbinders rtype =
let dname = lident_ dname in
let open Vernacexpr in
{ fname=dname; univs=None; binders=dbinders; body_def=ProveBody rtype; notations=[] }

type fixpoint_expr = Vernacexpr.fixpoint_expr
let fixpointBody_ name binders rtype body struc =
let open Vernacexpr in
let feg = { fname=lident_ name;
univs=None;
binders;
rtype;
body_def=Some body;
body_def=DefineBody (None, body, Some rtype);
notations=[] } in
let rec_order = Some (CAst.make (Constrexpr.CStructRec (lident_ struc))) in
rec_order, feg
Expand Down
3 changes: 2 additions & 1 deletion lib/gallinaGen.mli
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ type inductive_body = Vernacexpr.inductive_expr * Vernacexpr.notation_declaratio
val constructor_ : identifier -> constr_expr -> Vernacexpr.constructor_expr
val inductiveBody_ : identifier -> binder_expr list -> ?rtype:constr_expr -> constructor_expr list -> inductive_body

val definition_expr_ : binder_expr list -> ?rtype:constr_expr -> constr_expr -> Vernacexpr.definition_expr
val definition_expr_ : identifier -> binder_expr list -> ?rtype:constr_expr -> constr_expr -> Vernacexpr.definition_expr
val theorem_expr_ : identifier -> binder_expr list -> constr_expr -> Vernacexpr.definition_expr

type fixpoint_expr = Vernacexpr.fixpoint_expr
val fixpointBody_ : identifier -> binder_expr list -> constr_expr -> constr_expr -> identifier -> fixpoint_expr
Expand Down
18 changes: 5 additions & 13 deletions lib/vernacGen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@ let pr_vernac_units vunits = Pp.seq (List.map pr_vernac_unit vunits)


let definition_ dname dbinders ?rtype dbody =
let dname = name_decl_ dname in
let dexpr = definition_expr_ dbinders ?rtype dbody in
unit_of_vernacs [ VernacSynPure (VernacDefinition ((NoDischarge, Decls.Definition), dname, dexpr)) ]
let dexpr = definition_expr_ dname dbinders ?rtype dbody in
unit_of_vernacs [ VernacSynPure (VernacDefinition ((NoDischarge, Decls.(IsDefinitionKind Definition)), [None, dexpr])) ]

let lemma_ ?(opaque=true) lname lbinders ltype lbody =
let pexpr = (ident_decl_ lname, (lbinders, ltype)) in
let lbegin = VernacSynPure (VernacStartTheoremProof (Decls.Lemma, [pexpr])) in
let pexpr = theorem_expr_ lname lbinders ltype in
let lbegin = VernacSynPure (VernacDefinition ((NoDischarge,Decls.(IsTheoremKind Decls.Lemma)), [None, pexpr])) in
let lbody = VernacSynPure (VernacExactProof lbody) in
let lend = VernacSynPure (VernacEndProof (Proved ((if opaque then Opaque else Transparent), None))) in
unit_of_vernacs [ lbegin; lbody; lend ]
Expand All @@ -50,14 +49,7 @@ let fixpoint_ ~is_rec fexprs =
match fexprs with
| [] -> failwith "fixpoint called without fixpoint bodies"
| fexprs_nempty ->
if is_rec
then unit_of_vernacs [ VernacSynPure (VernacFixpoint (NoDischarge, List.split fexprs)) ]
(* if the fixpoint is declared non-recursive we try to turn it into a definition *)
else match fexprs_nempty with
| [_, { fname={ v=fname; _ }; binders; rtype; body_def=Some body; _}] ->
definition_ (Names.Id.to_string fname) binders ~rtype body
| [fexpr] -> failwith "Malformed fixpoint body"
| _ -> failwith "A non recursive fixpoint degenerates to a definition so it should only have one body"
unit_of_vernacs [ VernacSynPure (VernacDefinition ((NoDischarge, Decls.(IsDefinitionKind Fixpoint)), fexprs)) ]

let inductive_ inductiveBodies =
unit_of_vernacs [ VernacSynPure (VernacInductive (Inductive_kw, inductiveBodies)) ]
Expand Down
Loading