| 1 |
Require Import Ltac2.Ltac2. |
| 2 |
Require Import Ltac2.Printf. |
| 3 |
Require Import Crypto.Language.APINotations. |
| 4 |
|
| 5 |
Export Language.Pre. |
| 6 |
Export Language.Language. |
| 7 |
Export Language.IdentifiersBasicGENERATED. |
| 8 |
|
| 9 |
Module Compilers. |
| 10 |
Import IdentifiersBasicGENERATED.Compilers. |
| 11 |
Import Language.Wf.Compilers. |
| 12 |
Include Language.APINotations.Compilers. |
| 13 |
|
| 14 |
(** This is the module that defines the top-level constants which |
| 15 |
are used by clients of the language once it has been specialized |
| 16 |
to the identifiers and types we are using. To see what things |
| 17 |
are under the hood, you can write things like |
| 18 |
|
| 19 |
<< |
| 20 |
Unset Printing Notations. |
| 21 |
Compute API.Expr. (* to figure out what goes into an expression *) |
| 22 |
Compute API.type. (* to figure out what goes into a type *) |
| 23 |
>> |
| 24 |
|
| 25 |
You can then print out the things resulting from [Compute] to |
| 26 |
see the constructors of the various inductive types. |
| 27 |
*) |
| 28 |
Module Import API. |
| 29 |
Export Coercions. |
| 30 |
|
| 31 |
(** [type] is the type of reified type-codes for expressions *) |
| 32 |
#[global] Notation type := (type base.type). |
| 33 |
(** [Expr : type -> Type] is the type family of specialized PHOAS expressions *) |
| 34 |
#[global] Notation Expr := (@expr.Expr base.type ident). |
| 35 |
(** [expr : forall {var : type -> Type}, type -> Type] is the [var]-specific PHOAS expression type *) |
| 36 |
Notation expr := (@expr base.type ident). |
| 37 |
|
| 38 |
(** [interp_type : type -> Type] is the type code denotation function *) |
| 39 |
Notation interp_type := (@type.interp base.type base.interp). |
| 40 |
(** [Interp : forall {t}, Expr t -> interp_type t] is the [Expr] denotation function *) |
| 41 |
Notation Interp := (@expr.Interp base.type ident base.interp (@ident_interp)). |
| 42 |
(** [interp : forall {t}, @expr interp_type t -> interp_type t] is the [expr] denotation function *) |
| 43 |
Notation interp := (@expr.interp base.type ident base.interp (@ident_interp)). |
| 44 |
|
| 45 |
Ltac2 reify_type (ty : constr) : constr := type.reify reify_base_type 'base.type ty. |
| 46 |
Ltac reify_type ty := |
| 47 |
let f := ltac2:(ty |
| 48 |
|- let get_to_constr name x |
| 49 |
:= match Ltac1.to_constr x with |
| 50 |
| Some x => x |
| 51 |
| None => Control.zero (Not_a_constr "API.reify_type" name x) |
| 52 |
end in |
| 53 |
let v := reify_type (get_to_constr "ty" ty) in |
| 54 |
Control.refine (fun () => v)) in |
| 55 |
constr:(ltac:(f ty)). |
| 56 |
|
| 57 |
(* Avoid COQBUG(https://github.com/coq/coq/issues/16425) |
| 58 |
Notation reify_type t := (ltac2:(let rt := reify_type (Constr.pretype t) in exact $rt)) (only parsing). |
| 59 |
*) |
| 60 |
Notation reify_type t := (ltac:(let rt := reify_type t in exact rt)) (only parsing). |
| 61 |
Notation reify_type_of e := (reify_type ((fun t (_ : t) => t) _ e)) (only parsing). |
| 62 |
|
| 63 |
Ltac2 reify (var : constr) (term : constr) : constr := Compilers.reify var term. |
| 64 |
Ltac2 _Reify (term : constr) : constr := Compilers._Reify term. |
| 65 |
Ltac2 _Reify_rhs () : unit := Compilers._Reify_rhs (). |
| 66 |
Ltac reify var term := Compilers.reify var term. |
| 67 |
Ltac Reify term := Compilers.Reify term. |
| 68 |
Ltac Reify_rhs _ := Compilers.Reify_rhs (). |
| 69 |
|
| 70 |
Notation wf := (@expr.wf base.type ident). |
| 71 |
Notation Wf := (@expr.Wf base.type ident). |
| 72 |
End API. |
| 73 |
|
| 74 |
Module GallinaReify. |
| 75 |
Export Language.Compilers.GallinaReify. |
| 76 |
Module base. |
| 77 |
Export Language.Compilers.GallinaReify.base. |
| 78 |
(** [Reify] does Ltac type inference to get the type *) |
| 79 |
Notation Reify v |
| 80 |
:= (@Reify_as Compilers.base base_interp ident buildIdent (base.reify_type_of v) (fun _ => v)) (only parsing). |
| 81 |
End base. |
| 82 |
|
| 83 |
(** [Reify] does Ltac type inference to get the type *) |
| 84 |
Notation Reify v |
| 85 |
:= (@Reify_as Compilers.base base_interp ident buildIdent (reify_type_of v) (fun _ => v)) (only parsing). |
| 86 |
End GallinaReify. |
| 87 |
End Compilers. |