88 Term_Graph.get_node gr t |> |
88 Term_Graph.get_node gr t |> |
89 (fn ths => if null ths then NONE else SOME (fst (dest_Const t), ths))) |
89 (fn ths => if null ths then NONE else SOME (fst (dest_Const t), ths))) |
90 ts |
90 ts |
91 val _ = print_step options ("Preprocessing scc of " ^ |
91 val _ = print_step options ("Preprocessing scc of " ^ |
92 commas (map (Syntax.string_of_term_global thy) ts)) |
92 commas (map (Syntax.string_of_term_global thy) ts)) |
93 val (prednames, funnames) = List.partition (fn t => body_type (fastype_of t) = @{typ bool}) ts |
93 val (prednames, funnames) = List.partition (fn t => body_type (fastype_of t) = \<^typ>\<open>bool\<close>) ts |
94 (* untangle recursion by defining predicates for all functions *) |
94 (* untangle recursion by defining predicates for all functions *) |
95 val _ = print_step options |
95 val _ = print_step options |
96 ("Compiling functions (" ^ commas (map (Syntax.string_of_term_global thy) funnames) ^ |
96 ("Compiling functions (" ^ commas (map (Syntax.string_of_term_global thy) funnames) ^ |
97 ") to predicates...") |
97 ") to predicates...") |
98 val (fun_pred_specs, thy1) = |
98 val (fun_pred_specs, thy1) = |
226 val mode_and_opt_proposal = parse_mode_expr -- |
226 val mode_and_opt_proposal = parse_mode_expr -- |
227 Scan.optional (Args.$$$ "as" |-- Parse.name >> SOME) NONE |
227 Scan.optional (Args.$$$ "as" |-- Parse.name >> SOME) NONE |
228 |
228 |
229 |
229 |
230 val opt_modes = |
230 val opt_modes = |
231 Scan.optional (@{keyword "("} |-- Args.$$$ "modes" |-- @{keyword ":"} |-- |
231 Scan.optional (\<^keyword>\<open>(\<close> |-- Args.$$$ "modes" |-- \<^keyword>\<open>:\<close> |-- |
232 (((Parse.enum1 "and" (Parse.name --| @{keyword ":"} -- |
232 (((Parse.enum1 "and" (Parse.name --| \<^keyword>\<open>:\<close> -- |
233 (Parse.enum "," mode_and_opt_proposal))) >> Multiple_Preds) |
233 (Parse.enum "," mode_and_opt_proposal))) >> Multiple_Preds) |
234 || ((Parse.enum "," mode_and_opt_proposal) >> Single_Pred)) |
234 || ((Parse.enum "," mode_and_opt_proposal) >> Single_Pred)) |
235 --| @{keyword ")"}) (Multiple_Preds []) |
235 --| \<^keyword>\<open>)\<close>) (Multiple_Preds []) |
236 |
236 |
237 val opt_expected_modes = |
237 val opt_expected_modes = |
238 Scan.optional (@{keyword "("} |-- Args.$$$ "expected_modes" |-- @{keyword ":"} |-- |
238 Scan.optional (\<^keyword>\<open>(\<close> |-- Args.$$$ "expected_modes" |-- \<^keyword>\<open>:\<close> |-- |
239 Parse.enum "," parse_mode_expr --| @{keyword ")"} >> SOME) NONE |
239 Parse.enum "," parse_mode_expr --| \<^keyword>\<open>)\<close> >> SOME) NONE |
240 |
240 |
241 |
241 |
242 (* Parser for options *) |
242 (* Parser for options *) |
243 |
243 |
244 val scan_options = |
244 val scan_options = |
245 let |
245 let |
246 val scan_bool_option = foldl1 (op ||) (map Args.$$$ bool_options) |
246 val scan_bool_option = foldl1 (op ||) (map Args.$$$ bool_options) |
247 val scan_compilation = foldl1 (op ||) (map (fn (s, c) => Args.$$$ s >> K c) compilation_names) |
247 val scan_compilation = foldl1 (op ||) (map (fn (s, c) => Args.$$$ s >> K c) compilation_names) |
248 in |
248 in |
249 Scan.optional (@{keyword "["} |-- Scan.optional scan_compilation Pred |
249 Scan.optional (\<^keyword>\<open>[\<close> |-- Scan.optional scan_compilation Pred |
250 -- Parse.enum "," scan_bool_option --| @{keyword "]"}) |
250 -- Parse.enum "," scan_bool_option --| \<^keyword>\<open>]\<close>) |
251 (Pred, []) |
251 (Pred, []) |
252 end |
252 end |
253 |
253 |
254 val opt_print_modes = |
254 val opt_print_modes = |
255 Scan.optional (@{keyword "("} |-- Parse.!!! (Scan.repeat1 Parse.name --| @{keyword ")"})) [] |
255 Scan.optional (\<^keyword>\<open>(\<close> |-- Parse.!!! (Scan.repeat1 Parse.name --| \<^keyword>\<open>)\<close>)) [] |
256 |
256 |
257 val opt_mode = (Args.$$$ "_" >> K NONE) || (parse_mode_expr >> SOME) |
257 val opt_mode = (Args.$$$ "_" >> K NONE) || (parse_mode_expr >> SOME) |
258 |
258 |
259 val opt_param_modes = Scan.optional (@{keyword "["} |-- Args.$$$ "mode" |-- @{keyword ":"} |-- |
259 val opt_param_modes = Scan.optional (\<^keyword>\<open>[\<close> |-- Args.$$$ "mode" |-- \<^keyword>\<open>:\<close> |-- |
260 Parse.enum ", " opt_mode --| @{keyword "]"} >> SOME) NONE |
260 Parse.enum ", " opt_mode --| \<^keyword>\<open>]\<close> >> SOME) NONE |
261 |
261 |
262 val stats = Scan.optional (Args.$$$ "stats" >> K true) false |
262 val stats = Scan.optional (Args.$$$ "stats" >> K true) false |
263 |
263 |
264 val value_options = |
264 val value_options = |
265 let |
265 let |
270 (map (fn (s, c) => Args.$$$ s -- Parse.enum "," Parse.int >> (fn (_, ps) => (c, ps))) |
270 (map (fn (s, c) => Args.$$$ s -- Parse.enum "," Parse.int >> (fn (_, ps) => (c, ps))) |
271 compilation_names)) |
271 compilation_names)) |
272 (Pred, []) |
272 (Pred, []) |
273 in |
273 in |
274 Scan.optional |
274 Scan.optional |
275 (@{keyword "["} |-- (expected_values -- stats) -- scan_compilation --| @{keyword "]"}) |
275 (\<^keyword>\<open>[\<close> |-- (expected_values -- stats) -- scan_compilation --| \<^keyword>\<open>]\<close>) |
276 ((NONE, false), (Pred, [])) |
276 ((NONE, false), (Pred, [])) |
277 end |
277 end |
278 |
278 |
279 |
279 |
280 (* code_pred command and values command *) |
280 (* code_pred command and values command *) |
281 |
281 |
282 val _ = |
282 val _ = |
283 Outer_Syntax.local_theory_to_proof @{command_keyword code_pred} |
283 Outer_Syntax.local_theory_to_proof \<^command_keyword>\<open>code_pred\<close> |
284 "prove equations for predicate specified by intro/elim rules" |
284 "prove equations for predicate specified by intro/elim rules" |
285 (opt_expected_modes -- opt_modes -- scan_options -- Parse.term >> code_pred_cmd) |
285 (opt_expected_modes -- opt_modes -- scan_options -- Parse.term >> code_pred_cmd) |
286 |
286 |
287 val _ = |
287 val _ = |
288 Outer_Syntax.command @{command_keyword values} |
288 Outer_Syntax.command \<^command_keyword>\<open>values\<close> |
289 "enumerate and print comprehensions" |
289 "enumerate and print comprehensions" |
290 (opt_print_modes -- opt_param_modes -- value_options -- Scan.optional Parse.nat ~1 -- Parse.term |
290 (opt_print_modes -- opt_param_modes -- value_options -- Scan.optional Parse.nat ~1 -- Parse.term |
291 >> (fn ((((print_modes, param_modes), options), k), t) => Toplevel.keep |
291 >> (fn ((((print_modes, param_modes), options), k), t) => Toplevel.keep |
292 (Predicate_Compile_Core.values_cmd print_modes param_modes options k t))) |
292 (Predicate_Compile_Core.values_cmd print_modes param_modes options k t))) |
293 |
293 |