Debian Codegraph @

plugins/extraction/g_extraction.mlg

raw
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 {
12
13 open Procq.Prim
14
15 }
16
17 DECLARE PLUGIN "rocq-runtime.plugins.extraction"
18
19 {
20
21 (* ML names *)
22
23 open Stdarg
24 open Pp
25 open Names
26 open Table
27 open Extract_env
28
29 let pr_mlname s = spc () ++ qs s
30
31 }
32
33 VERNAC ARGUMENT EXTEND mlname
34 PRINTED BY { pr_mlname }
35 | [ preident(id) ] -> { id }
36 | [ string(s) ] -> { s }
37 END
38
39 {
40
41 let pr_int_or_id = function
42 | ArgInt i -> int i
43 | ArgId id -> Id.print id
44
45 }
46
47 VERNAC ARGUMENT EXTEND int_or_id
48 PRINTED BY { pr_int_or_id }
49 | [ preident(id) ] -> { ArgId (Id.of_string id) }
50 | [ integer(i) ] -> { ArgInt i }
51 END
52
53 {
54
55 let pr_language = function
56 | Ocaml -> str "OCaml"
57 | Haskell -> str "Haskell"
58 | Scheme -> str "Scheme"
59 | JSON -> str "JSON"
60
61 }
62
63 VERNAC ARGUMENT EXTEND language
64 PRINTED BY { pr_language }
65 | [ "OCaml" ] -> { Ocaml }
66 | [ "Haskell" ] -> { Haskell }
67 | [ "Scheme" ] -> { Scheme }
68 | [ "JSON" ] -> { JSON }
69 END
70
71 (* Extraction commands *)
72
73 VERNAC COMMAND EXTEND Extraction CLASSIFIED AS QUERY STATE opaque_access
74 (* Extraction in the Rocq toplevel *)
75 | [ "Extraction" global(x) ] -> { simple_extraction x }
76 | [ "Recursive" "Extraction" ne_global_list(l) ] -> { full_extraction None l }
77
78 (* Monolithic extraction to a file *)
79 | [ "Extraction" string(f) ne_global_list(l) ]
80 -> { full_extraction (Some f) l }
81
82 (* Extraction to a temporary file and OCaml compilation *)
83 | [ "Extraction" "TestCompile" ne_global_list(l) ]
84 -> { extract_and_compile l }
85 END
86
87 VERNAC COMMAND EXTEND SeparateExtraction CLASSIFIED AS QUERY STATE opaque_access
88 (* Same, with content split in several files *)
89 | [ "Separate" "Extraction" ne_global_list(l) ]
90 -> { separate_extraction l }
91 END
92
93 (* Modular extraction (one Rocq library = one ML module) *)
94 VERNAC COMMAND EXTEND ExtractionLibrary CLASSIFIED AS QUERY STATE opaque_access
95 | [ "Extraction" "Library" identref(m) ]
96 -> { extraction_library false m }
97 END
98
99 VERNAC COMMAND EXTEND RecursiveExtractionLibrary CLASSIFIED AS QUERY STATE opaque_access
100 | [ "Recursive" "Extraction" "Library" identref(m) ]
101 -> { extraction_library true m }
102 END
103
104 (* Target Language *)
105 VERNAC COMMAND EXTEND ExtractionLanguage CLASSIFIED AS SIDEFF
106 | [ "Extraction" "Language" language(l) ]
107 -> { extraction_language l }
108 END
109
110 VERNAC COMMAND EXTEND ExtractionInline CLASSIFIED AS SIDEFF
111 (* Custom inlining directives *)
112 | [ "Extraction" "Inline" ne_global_list(l) ]
113 -> { extraction_inline true l }
114 END
115
116 VERNAC COMMAND EXTEND ExtractionNoInline CLASSIFIED AS SIDEFF
117 | [ "Extraction" "NoInline" ne_global_list(l) ]
118 -> { extraction_inline false l }
119 END
120
121 VERNAC COMMAND EXTEND PrintExtractionInline CLASSIFIED AS QUERY
122 | [ "Print" "Extraction" "Inline" ]
123 -> {Feedback.msg_notice (print_extraction_inline ()) }
124 END
125
126 VERNAC COMMAND EXTEND ResetExtractionInline CLASSIFIED AS SIDEFF
127 | [ "Reset" "Extraction" "Inline" ]
128 -> { reset_extraction_inline () }
129 END
130
131 VERNAC COMMAND EXTEND ExtractionImplicit CLASSIFIED AS SIDEFF
132 (* Custom implicit arguments of some csts/inds/constructors *)
133 | [ "Extraction" "Implicit" global(r) "[" int_or_id_list(l) "]" ]
134 -> { extraction_implicit r l }
135 END
136
137 VERNAC COMMAND EXTEND ExtractionBlacklist CLASSIFIED AS SIDEFF
138 (* Force Extraction to not use some filenames *)
139 | [ "Extraction" "Blacklist" ne_preident_list(l) ]
140 -> { extraction_blacklist l }
141 END
142
143 VERNAC COMMAND EXTEND PrintExtractionBlacklist CLASSIFIED AS QUERY
144 | [ "Print" "Extraction" "Blacklist" ]
145 -> { Feedback.msg_notice (print_extraction_blacklist ()) }
146 END
147
148 VERNAC COMMAND EXTEND ResetExtractionBlacklist CLASSIFIED AS SIDEFF
149 | [ "Reset" "Extraction" "Blacklist" ]
150 -> { reset_extraction_blacklist () }
151 END
152
153 (* Commands for setting, printing and resetting callbacks extraction. *)
154
155 (* Defining a Rocq object as ML callback for FFI call target from C *)
156 VERNAC COMMAND EXTEND ExtractionCallback CLASSIFIED AS SIDEFF
157 | [ "Extract" "Callback" string_opt(o) global(x) ]
158 -> { extract_callback o x }
159 END
160
161 VERNAC COMMAND EXTEND PrintExtractionCallback CLASSIFIED AS QUERY
162 | [ "Print" "Extraction" "Callback" ]
163 -> {Feedback.msg_notice (print_extraction_callback ()) }
164 END
165
166 VERNAC COMMAND EXTEND ResetExtractionCallback CLASSIFIED AS SIDEFF
167 | [ "Reset" "Extraction" "Callback" ]
168 -> { reset_extraction_callback () }
169 END
170
171 (* Commands for printing and resetting foreigns extraction. *)
172 VERNAC COMMAND EXTEND PrintExtractionForeign CLASSIFIED AS QUERY
173 | [ "Print" "Extraction" "Foreign" ]
174 -> {Feedback.msg_notice (print_extraction_foreign ()) }
175 END
176
177 (*
178 VERNAC COMMAND EXTEND ResetExtractionForeign CLASSIFIED AS SIDEFF
179 | [ "Reset" "Extraction" "Foreign" ]
180 -> { reset_extraction_foreign () }
181 END
182 *)
183
184 (* Overriding of a Rocq object by an ML one *)
185 VERNAC COMMAND EXTEND ExtractionConstant CLASSIFIED AS SIDEFF
186 | [ "Extract" "Constant" global(x) string_list(idl) "=>" mlname(y) ]
187 -> { extract_constant_inline false x idl y }
188 END
189
190 (* Overriding of a Rocq object by an ML one that will be a FFI call to C *)
191 VERNAC COMMAND EXTEND ExtractionForeignConstant CLASSIFIED AS SIDEFF
192 | [ "Extract" "Foreign" "Constant" global(x) "=>" string(y) ]
193 -> { extract_constant_foreign x y }
194 END
195
196 VERNAC COMMAND EXTEND ExtractionInlinedConstant CLASSIFIED AS SIDEFF
197 | [ "Extract" "Inlined" "Constant" global(x) "=>" mlname(y) ]
198 -> { extract_constant_inline true x [] y }
199 END
200
201 VERNAC COMMAND EXTEND ExtractionInductive CLASSIFIED AS SIDEFF
202 | [ "Extract" "Inductive" global(x) "=>"
203 mlname(id) "[" mlname_list(idl) "]" string_opt(o) ]
204 -> { extract_inductive x id idl o }
205 END
206 (* Show the extraction of the current proof *)
207
208 VERNAC COMMAND EXTEND ShowExtraction CLASSIFIED AS QUERY STATE proof_query
209 | [ "Show" "Extraction" ]
210 -> { show_extraction }
211 END