author | bulwahn |
Thu, 19 Nov 2009 08:25:47 +0100 | |
changeset 33752 | 9aa8e961f850 |
parent 33671 | 4b0f2599ed48 |
child 34948 | 2d5f2a9f7601 |
permissions | -rw-r--r-- |
33265 | 1 |
(* Title: HOL/Tools/Predicate_Compile/predicate_compile.ML |
2 |
Author: Lukas Bulwahn, TU Muenchen |
|
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
3 |
|
33623
4ec42d38224f
changed modes to expected_modes; added UNION to code_pred_inlining; fixed some examples; tuned
bulwahn
parents:
33620
diff
changeset
|
4 |
Entry point for the predicate compiler; definition of Toplevel commands code_pred and values |
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
5 |
*) |
33265 | 6 |
|
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
7 |
signature PREDICATE_COMPILE = |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
8 |
sig |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
9 |
val setup : theory -> theory |
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
10 |
val preprocess : Predicate_Compile_Aux.options -> string -> theory -> theory |
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
11 |
end; |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
12 |
|
33619
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
bulwahn
parents:
33481
diff
changeset
|
13 |
structure Predicate_Compile (*: PREDICATE_COMPILE*) = |
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
14 |
struct |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
15 |
|
33108
9d9afd478016
added test for higher-order function inductification; added debug messages
bulwahn
parents:
33107
diff
changeset
|
16 |
(* options *) |
33139
9c01ee6f8ee9
added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents:
33134
diff
changeset
|
17 |
val fail_safe_mode = true |
33108
9d9afd478016
added test for higher-order function inductification; added debug messages
bulwahn
parents:
33107
diff
changeset
|
18 |
|
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
19 |
open Predicate_Compile_Aux; |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
20 |
|
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
21 |
(* Some last processing *) |
33113 | 22 |
|
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
23 |
fun remove_pointless_clauses intro = |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
24 |
if Logic.strip_imp_prems (prop_of intro) = [@{prop "False"}] then |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
25 |
[] |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
26 |
else [intro] |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
27 |
|
33125 | 28 |
fun print_intross options thy msg intross = |
29 |
if show_intermediate_results options then |
|
33376
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
30 |
tracing (msg ^ |
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
31 |
(space_implode "\n" (map |
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
32 |
(fn (c, intros) => "Introduction rule(s) of " ^ c ^ ":\n" ^ |
5cb663aa48ee
predicate compiler creates code equations for predicates with full mode
bulwahn
parents:
33375
diff
changeset
|
33 |
commas (map (Display.string_of_thm_global thy) intros)) intross))) |
33125 | 34 |
else () |
35 |
||
33122
7d01480cc8e3
added first support for higher-order function translation
bulwahn
parents:
33121
diff
changeset
|
36 |
fun print_specs thy specs = |
7d01480cc8e3
added first support for higher-order function translation
bulwahn
parents:
33121
diff
changeset
|
37 |
map (fn (c, thms) => "Constant " ^ c ^ " has specification:\n" |
7d01480cc8e3
added first support for higher-order function translation
bulwahn
parents:
33121
diff
changeset
|
38 |
^ (space_implode "\n" (map (Display.string_of_thm_global thy) thms)) ^ "\n") specs |
7d01480cc8e3
added first support for higher-order function translation
bulwahn
parents:
33121
diff
changeset
|
39 |
|
33475
42fed8eac357
improved handling of overloaded constants; examples with numerals
bulwahn
parents:
33473
diff
changeset
|
40 |
fun overload_const thy s = the_default s (Option.map fst (AxClass.inst_of_param thy s)) |
33404 | 41 |
|
33146
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33142
diff
changeset
|
42 |
fun map_specs f specs = |
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33142
diff
changeset
|
43 |
map (fn (s, ths) => (s, f ths)) specs |
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33142
diff
changeset
|
44 |
|
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
45 |
fun process_specification options specs thy' = |
33121
9b10dc5da0e0
added to process higher-order arguments by adding new constants
bulwahn
parents:
33120
diff
changeset
|
46 |
let |
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
47 |
val _ = print_step options "Compiling predicates to flat introrules..." |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
48 |
val specs = map (apsnd (map |
33140
83951822bfd0
cleaning the signature of the predicate compiler core; renaming signature and structures to uniform long names
bulwahn
parents:
33139
diff
changeset
|
49 |
(fn th => if is_equationlike th then Predicate_Compile_Data.normalize_equation thy' th else th))) specs |
33121
9b10dc5da0e0
added to process higher-order arguments by adding new constants
bulwahn
parents:
33120
diff
changeset
|
50 |
val (intross1, thy'') = apfst flat (fold_map Predicate_Compile_Pred.preprocess specs thy') |
33125 | 51 |
val _ = print_intross options thy'' "Flattened introduction rules: " intross1 |
33129
3085da75ed54
changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents:
33127
diff
changeset
|
52 |
val _ = print_step options "Replacing functions in introrules..." |
33121
9b10dc5da0e0
added to process higher-order arguments by adding new constants
bulwahn
parents:
33120
diff
changeset
|
53 |
val intross2 = |
9b10dc5da0e0
added to process higher-order arguments by adding new constants
bulwahn
parents:
33120
diff
changeset
|
54 |
if fail_safe_mode then |
33146
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33142
diff
changeset
|
55 |
case try (map_specs (maps (Predicate_Compile_Fun.rewrite_intro thy''))) intross1 of |
33121
9b10dc5da0e0
added to process higher-order arguments by adding new constants
bulwahn
parents:
33120
diff
changeset
|
56 |
SOME intross => intross |
9b10dc5da0e0
added to process higher-order arguments by adding new constants
bulwahn
parents:
33120
diff
changeset
|
57 |
| NONE => let val _ = warning "Function replacement failed!" in intross1 end |
33146
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33142
diff
changeset
|
58 |
else map_specs (maps (Predicate_Compile_Fun.rewrite_intro thy'')) intross1 |
33125 | 59 |
val _ = print_intross options thy'' "Introduction rules with replaced functions: " intross2 |
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
60 |
val _ = print_step options "Introducing new constants for abstractions at higher-order argument positions..." |
33121
9b10dc5da0e0
added to process higher-order arguments by adding new constants
bulwahn
parents:
33120
diff
changeset
|
61 |
val (intross3, (new_defs, thy''')) = Predicate_Compile_Pred.flat_higher_order_arguments (intross2, thy'') |
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
62 |
val (new_intross, thy'''') = |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
63 |
if not (null new_defs) then |
33404 | 64 |
let |
65 |
val _ = print_step options "Recursively obtaining introduction rules for new definitions..." |
|
66 |
in process_specification options new_defs thy''' end |
|
67 |
else ([], thy''') |
|
33121
9b10dc5da0e0
added to process higher-order arguments by adding new constants
bulwahn
parents:
33120
diff
changeset
|
68 |
in |
9b10dc5da0e0
added to process higher-order arguments by adding new constants
bulwahn
parents:
33120
diff
changeset
|
69 |
(intross3 @ new_intross, thy'''') |
9b10dc5da0e0
added to process higher-order arguments by adding new constants
bulwahn
parents:
33120
diff
changeset
|
70 |
end |
9b10dc5da0e0
added to process higher-order arguments by adding new constants
bulwahn
parents:
33120
diff
changeset
|
71 |
|
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
72 |
fun preprocess_strong_conn_constnames options gr constnames thy = |
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
73 |
let |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
74 |
val get_specs = map (fn k => (k, Graph.get_node gr k)) |
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
75 |
val _ = print_step options ("Preprocessing scc of " ^ commas constnames) |
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
76 |
val (prednames, funnames) = List.partition (is_pred thy) constnames |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
77 |
(* untangle recursion by defining predicates for all functions *) |
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
78 |
val _ = print_step options |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
79 |
("Compiling functions (" ^ commas funnames ^ ") to predicates...") |
33122
7d01480cc8e3
added first support for higher-order function translation
bulwahn
parents:
33121
diff
changeset
|
80 |
val (fun_pred_specs, thy') = |
7d01480cc8e3
added first support for higher-order function translation
bulwahn
parents:
33121
diff
changeset
|
81 |
if not (null funnames) then Predicate_Compile_Fun.define_predicates |
7d01480cc8e3
added first support for higher-order function translation
bulwahn
parents:
33121
diff
changeset
|
82 |
(get_specs funnames) thy else ([], thy) |
7d01480cc8e3
added first support for higher-order function translation
bulwahn
parents:
33121
diff
changeset
|
83 |
val _ = print_specs thy' fun_pred_specs |
7d01480cc8e3
added first support for higher-order function translation
bulwahn
parents:
33121
diff
changeset
|
84 |
val specs = (get_specs prednames) @ fun_pred_specs |
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
85 |
val (intross3, thy''') = process_specification options specs thy' |
33125 | 86 |
val _ = print_intross options thy''' "Introduction rules with new constants: " intross3 |
33146
bf852ef586f2
now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents:
33142
diff
changeset
|
87 |
val intross4 = map_specs (maps remove_pointless_clauses) intross3 |
33125 | 88 |
val _ = print_intross options thy''' "After removing pointless clauses: " intross4 |
33475
42fed8eac357
improved handling of overloaded constants; examples with numerals
bulwahn
parents:
33473
diff
changeset
|
89 |
val intross5 = map (fn (s, ths) => (overload_const thy''' s, map (AxClass.overload thy''') ths)) intross4 |
42fed8eac357
improved handling of overloaded constants; examples with numerals
bulwahn
parents:
33473
diff
changeset
|
90 |
val intross6 = map_specs (map (expand_tuples thy''')) intross5 |
33125 | 91 |
val _ = print_intross options thy''' "introduction rules before registering: " intross6 |
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
92 |
val _ = print_step options "Registering introduction rules..." |
33121
9b10dc5da0e0
added to process higher-order arguments by adding new constants
bulwahn
parents:
33120
diff
changeset
|
93 |
val thy'''' = fold Predicate_Compile_Core.register_intros intross6 thy''' |
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
94 |
in |
33121
9b10dc5da0e0
added to process higher-order arguments by adding new constants
bulwahn
parents:
33120
diff
changeset
|
95 |
thy'''' |
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
96 |
end; |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
97 |
|
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
98 |
fun preprocess options const thy = |
32672
90f3ce5d27ae
added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents:
32669
diff
changeset
|
99 |
let |
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
100 |
val _ = print_step options "Fetching definitions from theory..." |
33404 | 101 |
val table = Predicate_Compile_Data.make_const_spec_table options thy |
33252
8bd2eb003b8f
print retrieved specification when printing intermediate results
bulwahn
parents:
33251
diff
changeset
|
102 |
val gr = Predicate_Compile_Data.obtain_specification_graph options thy table const |
32672
90f3ce5d27ae
added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents:
32669
diff
changeset
|
103 |
val gr = Graph.subgraph (member (op =) (Graph.all_succs gr [const])) gr |
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
104 |
in fold_rev (preprocess_strong_conn_constnames options gr) |
32672
90f3ce5d27ae
added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents:
32669
diff
changeset
|
105 |
(Graph.strong_conn gr) thy |
90f3ce5d27ae
added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents:
32669
diff
changeset
|
106 |
end |
90f3ce5d27ae
added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents:
32669
diff
changeset
|
107 |
|
33623
4ec42d38224f
changed modes to expected_modes; added UNION to code_pred_inlining; fixed some examples; tuned
bulwahn
parents:
33620
diff
changeset
|
108 |
fun extract_options (((expected_modes, proposed_modes), raw_options), const) = |
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
109 |
let |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
110 |
fun chk s = member (op =) raw_options s |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
111 |
in |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
112 |
Options { |
33623
4ec42d38224f
changed modes to expected_modes; added UNION to code_pred_inlining; fixed some examples; tuned
bulwahn
parents:
33620
diff
changeset
|
113 |
expected_modes = Option.map (pair const) expected_modes, |
33752
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
114 |
proposed_modes = Option.map (pair const o map fst) proposed_modes, |
33623
4ec42d38224f
changed modes to expected_modes; added UNION to code_pred_inlining; fixed some examples; tuned
bulwahn
parents:
33620
diff
changeset
|
115 |
proposed_names = |
33752
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
116 |
the_default [] (Option.map (map_filter |
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
117 |
(fn (m, NONE) => NONE | (m, SOME name) => SOME ((const, m), name))) proposed_modes), |
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
118 |
show_steps = chk "show_steps", |
33125 | 119 |
show_intermediate_results = chk "show_intermediate_results", |
33127 | 120 |
show_proof_trace = chk "show_proof_trace", |
33251 | 121 |
show_modes = chk "show_modes", |
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
122 |
show_mode_inference = chk "show_mode_inference", |
33139
9c01ee6f8ee9
added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents:
33134
diff
changeset
|
123 |
show_compilation = chk "show_compilation", |
9c01ee6f8ee9
added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents:
33134
diff
changeset
|
124 |
skip_proof = chk "skip_proof", |
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
125 |
inductify = chk "inductify", |
33375 | 126 |
random = chk "random", |
33473
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33404
diff
changeset
|
127 |
depth_limited = chk "depth_limited", |
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33404
diff
changeset
|
128 |
annotated = chk "annotated" |
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
129 |
} |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
130 |
end |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
131 |
|
33623
4ec42d38224f
changed modes to expected_modes; added UNION to code_pred_inlining; fixed some examples; tuned
bulwahn
parents:
33620
diff
changeset
|
132 |
fun code_pred_cmd (((expected_modes, proposed_modes), raw_options), raw_const) lthy = |
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
133 |
let |
33132
07efd452a698
moved argument expected_modes into options; improved mode check to only check mode of the named predicate
bulwahn
parents:
33131
diff
changeset
|
134 |
val thy = ProofContext.theory_of lthy |
07efd452a698
moved argument expected_modes into options; improved mode check to only check mode of the named predicate
bulwahn
parents:
33131
diff
changeset
|
135 |
val const = Code.read_const thy raw_const |
33623
4ec42d38224f
changed modes to expected_modes; added UNION to code_pred_inlining; fixed some examples; tuned
bulwahn
parents:
33620
diff
changeset
|
136 |
val options = extract_options (((expected_modes, proposed_modes), raw_options), const) |
33132
07efd452a698
moved argument expected_modes into options; improved mode check to only check mode of the named predicate
bulwahn
parents:
33131
diff
changeset
|
137 |
in |
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
138 |
if (is_inductify options) then |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
139 |
let |
33671 | 140 |
val lthy' = Local_Theory.theory (preprocess options const) lthy |
141 |
|> Local_Theory.checkpoint |
|
33623
4ec42d38224f
changed modes to expected_modes; added UNION to code_pred_inlining; fixed some examples; tuned
bulwahn
parents:
33620
diff
changeset
|
142 |
val const = |
4ec42d38224f
changed modes to expected_modes; added UNION to code_pred_inlining; fixed some examples; tuned
bulwahn
parents:
33620
diff
changeset
|
143 |
case Predicate_Compile_Fun.pred_of_function (ProofContext.theory_of lthy') const of |
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
144 |
SOME c => c |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
145 |
| NONE => const |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
146 |
val _ = print_step options "Starting Predicate Compile Core..." |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
147 |
in |
33132
07efd452a698
moved argument expected_modes into options; improved mode check to only check mode of the named predicate
bulwahn
parents:
33131
diff
changeset
|
148 |
Predicate_Compile_Core.code_pred options const lthy' |
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
149 |
end |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
150 |
else |
33132
07efd452a698
moved argument expected_modes into options; improved mode check to only check mode of the named predicate
bulwahn
parents:
33131
diff
changeset
|
151 |
Predicate_Compile_Core.code_pred_cmd options raw_const lthy |
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
152 |
end |
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
153 |
|
33630
68e058d061f5
removed unnecessary oracle in the predicate compiler
bulwahn
parents:
33625
diff
changeset
|
154 |
val setup = Predicate_Compile_Core.setup |
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
155 |
|
33251 | 156 |
val bool_options = ["show_steps", "show_intermediate_results", "show_proof_trace", "show_modes", |
33473
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33404
diff
changeset
|
157 |
"show_mode_inference", "show_compilation", "skip_proof", "inductify", "random", "depth_limited", |
3b275a0bf18c
adding tracing function for evaluated code; annotated compilation in the predicate compiler
bulwahn
parents:
33404
diff
changeset
|
158 |
"annotated"] |
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
159 |
|
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
160 |
local structure P = OuterParse |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
161 |
in |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
162 |
|
33478
b70fe083694d
moved values command from core to predicate compile
bulwahn
parents:
33475
diff
changeset
|
163 |
(* Parser for mode annotations *) |
33327 | 164 |
|
33625
eefee41ede3a
removed deprecated mode annotation parser; renamed accepted mode annotation parser to nicer naming
bulwahn
parents:
33623
diff
changeset
|
165 |
fun parse_mode_basic_expr xs = |
eefee41ede3a
removed deprecated mode annotation parser; renamed accepted mode annotation parser to nicer naming
bulwahn
parents:
33623
diff
changeset
|
166 |
(Args.$$$ "i" >> K Input || Args.$$$ "o" >> K Output || |
eefee41ede3a
removed deprecated mode annotation parser; renamed accepted mode annotation parser to nicer naming
bulwahn
parents:
33623
diff
changeset
|
167 |
Args.$$$ "bool" >> K Bool || Args.$$$ "(" |-- parse_mode_expr --| Args.$$$ ")") xs |
eefee41ede3a
removed deprecated mode annotation parser; renamed accepted mode annotation parser to nicer naming
bulwahn
parents:
33623
diff
changeset
|
168 |
and parse_mode_tuple_expr xs = |
eefee41ede3a
removed deprecated mode annotation parser; renamed accepted mode annotation parser to nicer naming
bulwahn
parents:
33623
diff
changeset
|
169 |
(parse_mode_basic_expr --| Args.$$$ "*" -- parse_mode_tuple_expr >> Pair || parse_mode_basic_expr) |
eefee41ede3a
removed deprecated mode annotation parser; renamed accepted mode annotation parser to nicer naming
bulwahn
parents:
33623
diff
changeset
|
170 |
xs |
eefee41ede3a
removed deprecated mode annotation parser; renamed accepted mode annotation parser to nicer naming
bulwahn
parents:
33623
diff
changeset
|
171 |
and parse_mode_expr xs = |
eefee41ede3a
removed deprecated mode annotation parser; renamed accepted mode annotation parser to nicer naming
bulwahn
parents:
33623
diff
changeset
|
172 |
(parse_mode_tuple_expr --| Args.$$$ "=>" -- parse_mode_expr >> Fun || parse_mode_tuple_expr) xs |
33619
d93a3cb55068
first steps towards a new mode datastructure; new syntax for mode annotations and new output of modes
bulwahn
parents:
33481
diff
changeset
|
173 |
|
33625
eefee41ede3a
removed deprecated mode annotation parser; renamed accepted mode annotation parser to nicer naming
bulwahn
parents:
33623
diff
changeset
|
174 |
val mode_and_opt_proposal = parse_mode_expr -- |
33620
b6bf2dc5aed7
added interface of user proposals for names of generated constants
bulwahn
parents:
33619
diff
changeset
|
175 |
Scan.optional (Args.$$$ "as" |-- P.xname >> SOME) NONE |
b6bf2dc5aed7
added interface of user proposals for names of generated constants
bulwahn
parents:
33619
diff
changeset
|
176 |
|
33114
4785ef554dcc
added further examples; added mode to code_pred command; tuned; some temporary things in Predicate_Compile_ex
bulwahn
parents:
33113
diff
changeset
|
177 |
val opt_modes = |
33623
4ec42d38224f
changed modes to expected_modes; added UNION to code_pred_inlining; fixed some examples; tuned
bulwahn
parents:
33620
diff
changeset
|
178 |
Scan.optional (P.$$$ "(" |-- Args.$$$ "modes" |-- P.$$$ ":" |-- |
33752
9aa8e961f850
adopting proposed_modes; adding a new dimension of complexity for nicer error messages; tuned
bulwahn
parents:
33671
diff
changeset
|
179 |
P.enum "," mode_and_opt_proposal --| P.$$$ ")" >> SOME) NONE |
33623
4ec42d38224f
changed modes to expected_modes; added UNION to code_pred_inlining; fixed some examples; tuned
bulwahn
parents:
33620
diff
changeset
|
180 |
|
4ec42d38224f
changed modes to expected_modes; added UNION to code_pred_inlining; fixed some examples; tuned
bulwahn
parents:
33620
diff
changeset
|
181 |
val opt_expected_modes = |
4ec42d38224f
changed modes to expected_modes; added UNION to code_pred_inlining; fixed some examples; tuned
bulwahn
parents:
33620
diff
changeset
|
182 |
Scan.optional (P.$$$ "(" |-- Args.$$$ "expected_modes" |-- P.$$$ ":" |-- |
33625
eefee41ede3a
removed deprecated mode annotation parser; renamed accepted mode annotation parser to nicer naming
bulwahn
parents:
33623
diff
changeset
|
183 |
P.enum "," parse_mode_expr --| P.$$$ ")" >> SOME) NONE |
33114
4785ef554dcc
added further examples; added mode to code_pred command; tuned; some temporary things in Predicate_Compile_ex
bulwahn
parents:
33113
diff
changeset
|
184 |
|
33478
b70fe083694d
moved values command from core to predicate compile
bulwahn
parents:
33475
diff
changeset
|
185 |
(* Parser for options *) |
b70fe083694d
moved values command from core to predicate compile
bulwahn
parents:
33475
diff
changeset
|
186 |
|
b70fe083694d
moved values command from core to predicate compile
bulwahn
parents:
33475
diff
changeset
|
187 |
val scan_options = |
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
188 |
let |
33478
b70fe083694d
moved values command from core to predicate compile
bulwahn
parents:
33475
diff
changeset
|
189 |
val scan_bool_option = foldl1 (op ||) (map Args.$$$ bool_options) |
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
190 |
in |
33478
b70fe083694d
moved values command from core to predicate compile
bulwahn
parents:
33475
diff
changeset
|
191 |
Scan.optional (P.$$$ "[" |-- P.enum1 "," scan_bool_option --| P.$$$ "]") [] |
33123
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
192 |
end |
3c7c4372f9ad
cleaned up debugging messages; added options to code_pred command
bulwahn
parents:
33122
diff
changeset
|
193 |
|
33478
b70fe083694d
moved values command from core to predicate compile
bulwahn
parents:
33475
diff
changeset
|
194 |
val opt_print_modes = Scan.optional (P.$$$ "(" |-- P.!!! (Scan.repeat1 P.xname --| P.$$$ ")")) []; |
b70fe083694d
moved values command from core to predicate compile
bulwahn
parents:
33475
diff
changeset
|
195 |
|
33625
eefee41ede3a
removed deprecated mode annotation parser; renamed accepted mode annotation parser to nicer naming
bulwahn
parents:
33623
diff
changeset
|
196 |
val opt_mode = (P.$$$ "_" >> K NONE) || (parse_mode_expr >> SOME) |
33479
428ddcc16e7b
added optional mode annotations for parameters in the values command
bulwahn
parents:
33478
diff
changeset
|
197 |
|
33481 | 198 |
val opt_param_modes = Scan.optional (P.$$$ "[" |-- Args.$$$ "mode" |-- P.$$$ ":" |-- |
33623
4ec42d38224f
changed modes to expected_modes; added UNION to code_pred_inlining; fixed some examples; tuned
bulwahn
parents:
33620
diff
changeset
|
199 |
P.enum ", " opt_mode --| P.$$$ "]" >> SOME) NONE |
33479
428ddcc16e7b
added optional mode annotations for parameters in the values command
bulwahn
parents:
33478
diff
changeset
|
200 |
|
33478
b70fe083694d
moved values command from core to predicate compile
bulwahn
parents:
33475
diff
changeset
|
201 |
val value_options = |
b70fe083694d
moved values command from core to predicate compile
bulwahn
parents:
33475
diff
changeset
|
202 |
let |
b70fe083694d
moved values command from core to predicate compile
bulwahn
parents:
33475
diff
changeset
|
203 |
val depth_limit = Scan.optional (Args.$$$ "depth_limit" |-- P.$$$ "=" |-- P.nat >> SOME) NONE |
b70fe083694d
moved values command from core to predicate compile
bulwahn
parents:
33475
diff
changeset
|
204 |
val random = Scan.optional (Args.$$$ "random" >> K true) false |
b70fe083694d
moved values command from core to predicate compile
bulwahn
parents:
33475
diff
changeset
|
205 |
val annotated = Scan.optional (Args.$$$ "annotated" >> K true) false |
b70fe083694d
moved values command from core to predicate compile
bulwahn
parents:
33475
diff
changeset
|
206 |
in |
b70fe083694d
moved values command from core to predicate compile
bulwahn
parents:
33475
diff
changeset
|
207 |
Scan.optional (P.$$$ "[" |-- depth_limit -- (random -- annotated) --| P.$$$ "]") |
b70fe083694d
moved values command from core to predicate compile
bulwahn
parents:
33475
diff
changeset
|
208 |
(NONE, (false, false)) |
b70fe083694d
moved values command from core to predicate compile
bulwahn
parents:
33475
diff
changeset
|
209 |
end |
b70fe083694d
moved values command from core to predicate compile
bulwahn
parents:
33475
diff
changeset
|
210 |
|
b70fe083694d
moved values command from core to predicate compile
bulwahn
parents:
33475
diff
changeset
|
211 |
(* code_pred command and values command *) |
b70fe083694d
moved values command from core to predicate compile
bulwahn
parents:
33475
diff
changeset
|
212 |
|
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
213 |
val _ = OuterSyntax.local_theory_to_proof "code_pred" |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
214 |
"prove equations for predicate specified by intro/elim rules" |
33623
4ec42d38224f
changed modes to expected_modes; added UNION to code_pred_inlining; fixed some examples; tuned
bulwahn
parents:
33620
diff
changeset
|
215 |
OuterKeyword.thy_goal |
4ec42d38224f
changed modes to expected_modes; added UNION to code_pred_inlining; fixed some examples; tuned
bulwahn
parents:
33620
diff
changeset
|
216 |
(opt_expected_modes -- opt_modes -- scan_options -- P.term_group >> code_pred_cmd) |
33478
b70fe083694d
moved values command from core to predicate compile
bulwahn
parents:
33475
diff
changeset
|
217 |
|
b70fe083694d
moved values command from core to predicate compile
bulwahn
parents:
33475
diff
changeset
|
218 |
val _ = OuterSyntax.improper_command "values" "enumerate and print comprehensions" OuterKeyword.diag |
33479
428ddcc16e7b
added optional mode annotations for parameters in the values command
bulwahn
parents:
33478
diff
changeset
|
219 |
(opt_print_modes -- opt_param_modes -- value_options -- Scan.optional P.nat ~1 -- P.term |
428ddcc16e7b
added optional mode annotations for parameters in the values command
bulwahn
parents:
33478
diff
changeset
|
220 |
>> (fn ((((print_modes, param_modes), options), k), t) => Toplevel.no_timing o Toplevel.keep |
428ddcc16e7b
added optional mode annotations for parameters in the values command
bulwahn
parents:
33478
diff
changeset
|
221 |
(Predicate_Compile_Core.values_cmd print_modes param_modes options k t))); |
32668
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
222 |
|
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
223 |
end |
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
224 |
|
b2de45007537
added first prototype of the extended predicate compiler
bulwahn
parents:
diff
changeset
|
225 |
end |