Debian Codegraph @

tests/test_API_module.v

raw
1 From elpi Require Import elpi.
2
3 Elpi Command modules.
4
5 (* module *)
6
7 Elpi Query lp:{{ coq.locate-module "Datatypes" MP, coq.env.module MP L }}.
8
9 Module X.
10 Unset Auto Template Polymorphism.
11 Inductive i := .
12 Definition d := i.
13 Module Y.
14 Inductive i := .
15 Definition d := i.
16 End Y.
17 End X.
18
19 Elpi Query lp:{{
20 coq.locate-module "X" MP,
21 coq.env.module MP L,
22 std.assert! (L = [
23 gref (indt Xi), gref (const _), gref (const _), gref (const _), gref (const _),
24 gref (const _),
25 submodule _ [
26 gref (indt XYi), gref (const XYr), gref (const _), gref (const _), gref (const _),
27 gref (const _)]
28 ]) "bad module",
29 coq.say {coq.gref->string (indt Xi)},
30 rex_match "\\(Top.\\|.*test_API_module\\)\\.X\\.i$" {coq.gref->string (indt Xi)},
31 rex_match "\\(Top.\\|.*test_API_module\\)\\.X\\.Y\\.i$" {coq.gref->string (indt XYi)},
32 (coq.gref->path (indt XYi) ["test_API_module", "X", "Y" ] ;
33 coq.gref->path (indt XYi) ["elpi", "tests", "test_API_module", "X", "Y" ] ;
34 coq.gref->path (indt XYi) ["Top", "test_API_module", "X", "Y" ]),
35 coq.say {coq.gref->path (indt XYi)},
36 coq.say {coq.gref->path (const XYr)},
37 (coq.gref->path (const XYr) ["test_API_module", "X", "Y" ] ;
38 coq.gref->path (const XYr) ["elpi", "tests", "test_API_module", "X", "Y" ] ;
39 coq.gref->path (const XYr) ["Top", "test_API_module", "X", "Y" ] )
40 }}.
41
42 Module Y.
43 Inductive i := with j := Kj.
44 End Y.
45
46 Elpi Query lp:{{
47 coq.locate-module "Y" MP,
48 coq.env.module MP [gref (indt I), gref (indt J), |_],
49 coq.gref->path (indt I) P,
50 coq.gref->id (indt J) ID
51 }}.
52
53 Elpi Query lp:{{
54 std.do! [
55 coq.env.begin-module-type "TA",
56 coq.env.end-module-type Mp_ta,
57 coq.env.begin-module "A" (some Mp_ta),
58 coq.env.begin-module "B" none,
59 coq.env.end-module _,
60 coq.env.end-module _,
61 ]
62 }} lp:{{
63 std.do! [
64 coq.env.begin-module-type "TA",
65 coq.env.add-axiom "z" {{nat}} _,
66 coq.env.add-axiom "i" {{Type}} _,
67 coq.env.end-module-type MP_TA,
68 coq.env.begin-module "A" _,
69 coq.env.add-const "x" {{3}} _ _ _,
70 coq.env.begin-module "B" _,
71 coq.env.add-const "y" {{3}} _ _ GRy,
72 coq.env.end-module _,
73 coq.env.add-const "z" (global (const GRy)) _ _ _,
74 coq.env.add-indt (inductive "i1" _ (arity {{Type}}) i\ []) I,
75 coq.env.add-const "i" (global (indt I)) _ _ _, % silly limitation in Coq
76 coq.env.end-module MP,
77 coq.env.module MP L
78 %coq.env.module-type MP_TA [TAz,TAi] % name is broken wrt =, don't use it!
79 ]
80 }}.
81 Print A.
82 Check A.z.
83 Check A.i.
84 Print A.i.
85 Fail Check A.i1_ind.
86
87 Elpi Query lp:{{
88 coq.locate-module-type "TA" MP_TA,
89 std.do! [
90 coq.env.begin-module-type "TF",
91 coq.env.end-module-type TF,
92 coq.env.begin-module-functor "F" (some TF) [pr "a" MP_TA, pr "b" MP_TA],
93 coq.locate-module "a" A,
94 coq.env.import-module A,
95 coq.env.end-module _,
96 ]
97 }} lp:{{
98 std.do! [
99 coq.env.begin-module-type "TF",
100 coq.env.add-axiom "w" {{nat}} _,
101 coq.env.end-module-type MP_TF,
102 coq.locate-module-type "TA" MP_TA,
103 coq.env.begin-module-functor "F" _ _,
104 coq.env.import-module {coq.locate-module "a"},
105 coq.env.add-const "w" (global {coq.locate "z"}) _ _ _,
106 coq.env.end-module _
107 ]
108 }}.
109 Print F.
110 Module B := F A A.
111 Print B.
112 Print B.w.
113
114 Elpi Query lp:{{
115 coq.locate-module-type "TA" MP_TA,
116 std.do! [
117 coq.env.begin-module-type-functor "TB" [pr "A" MP_TA],
118 coq.env.end-module-type _,
119 ]
120 }} lp:{{
121 std.do! [
122 coq.env.begin-module-type-functor "TB" _,
123 coq.env.end-module-type _
124 ]
125 }}.
126 Print TB.
127
128 Elpi Query lp:{{ std.do! [
129 coq.locate-module "A" A,
130 coq.env.begin-module "IA" none,
131 coq.env.include-module A _,
132 coq.env.end-module _,
133 ]
134 }} lp:{{
135 coq.env.begin-module "IA" _,
136 coq.env.include-module {coq.locate-module "A"} _,
137 coq.env.end-module _.
138 }}.
139
140 Print IA.
141
142 Module Tmp.
143 Elpi Query
144 lp:{{
145 std.do! [coq.env.import-module { coq.locate-module "IA" }]
146 }} lp:{{
147 coq.env.import-module { coq.locate-module "IA" }
148 }}.
149 Check i.
150 End Tmp.
151
152 Elpi Query lp:{{
153 std.do! [
154 coq.env.begin-module-type "ITA",
155 coq.env.include-module-type {coq.locate-module-type "TA"} (coq.inline.at 2),
156 coq.env.end-module-type _,
157 ]
158 }} lp:{{
159 coq.env.begin-module-type "ITA",
160 coq.env.include-module-type {coq.locate-module-type "TA"} _,
161 coq.env.end-module-type _.
162 }}.
163
164 Print ITA.
165
166
167 Module R.
168 Module S.
169 Definition x := 3.
170 End S.
171 Module Type P1.
172 Parameter x : nat.
173 End P1.
174 Module Type P2.
175 Parameter y : nat.
176 End P2.
177 Module F(A : P1)(B : P2).
178 Definition z := A.x + B.y.
179 End F.
180 Module Type FT(A : P2)(B : P1).
181 Definition z := A.y + B.x.
182 End FT.
183 Definition a := 1.
184 End R.
185
186 Elpi Query lp:{{
187 coq.locate-module "R" R,
188 coq.locate-module "R.S" S,
189 coq.locate-module-type "R.P1" P1,
190 coq.locate-module-type "R.P2" P2,
191 coq.locate-module "R.F" F,
192 coq.locate-module-type "R.FT" FT,
193 coq.env.module R L,
194 std.assert! (L = [
195 submodule S [gref (const _)],
196 module-type P1,
197 module-type P2,
198 module-functor F [P1,P2],
199 module-type-functor FT [P2,P1],
200 gref (const _)
201 ]) "bad module"
202 }}.