74 val get_cert: theory -> ((thm * bool) list -> (thm * bool) list) -> string -> cert |
74 val get_cert: theory -> ((thm * bool) list -> (thm * bool) list) -> string -> cert |
75 val get_case_scheme: theory -> string -> (int * (int * string list)) option |
75 val get_case_scheme: theory -> string -> (int * (int * string list)) option |
76 val get_case_cong: theory -> string -> thm option |
76 val get_case_cong: theory -> string -> thm option |
77 val undefineds: theory -> string list |
77 val undefineds: theory -> string list |
78 val print_codesetup: theory -> unit |
78 val print_codesetup: theory -> unit |
79 |
|
80 (*infrastructure*) |
|
81 val set_code_target_attr: (string -> thm -> theory -> theory) -> theory -> theory |
|
82 end; |
79 end; |
83 |
80 |
84 signature CODE_DATA_ARGS = |
81 signature CODE_DATA_ARGS = |
85 sig |
82 sig |
86 type T |
83 type T |
1262 (map_types Logic.varifyT_global (mk_proj tyco vs ty abs rep), tyco)) |
1259 (map_types Logic.varifyT_global (mk_proj tyco vs ty abs rep), tyco)) |
1263 |> Abstype_Interpretation.data (tyco, serial ()) |
1260 |> Abstype_Interpretation.data (tyco, serial ()) |
1264 end; |
1261 end; |
1265 |
1262 |
1266 |
1263 |
1267 (** infrastructure **) |
|
1268 |
|
1269 (* cf. src/HOL/Tools/recfun_codegen.ML *) |
|
1270 |
|
1271 structure Code_Target_Attr = Theory_Data |
|
1272 ( |
|
1273 type T = (string -> thm -> theory -> theory) option; |
|
1274 val empty = NONE; |
|
1275 val extend = I; |
|
1276 val merge = merge_options; |
|
1277 ); |
|
1278 |
|
1279 fun set_code_target_attr f = Code_Target_Attr.map (K (SOME f)); |
|
1280 |
|
1281 fun code_target_attr prefix thm thy = |
|
1282 let |
|
1283 val attr = the_default ((K o K) I) (Code_Target_Attr.get thy); |
|
1284 in thy |> add_warning_eqn thm |> attr prefix thm end; |
|
1285 |
|
1286 |
|
1287 (* setup *) |
1264 (* setup *) |
1288 |
1265 |
1289 val _ = Context.>> (Context.map_theory |
1266 val _ = Context.>> (Context.map_theory |
1290 (let |
1267 (let |
1291 fun mk_attribute f = Thm.declaration_attribute (fn thm => Context.mapping (f thm) I); |
1268 fun mk_attribute f = Thm.declaration_attribute (fn thm => Context.mapping (f thm) I); |
1292 val code_attribute_parser = |
1269 val code_attribute_parser = |
1293 Args.del |-- Scan.succeed (mk_attribute del_eqn) |
1270 Args.del |-- Scan.succeed (mk_attribute del_eqn) |
1294 || Args.$$$ "nbe" |-- Scan.succeed (mk_attribute add_nbe_eqn) |
1271 || Args.$$$ "nbe" |-- Scan.succeed (mk_attribute add_nbe_eqn) |
1295 || Args.$$$ "abstype" |-- Scan.succeed (mk_attribute add_abstype) |
1272 || Args.$$$ "abstype" |-- Scan.succeed (mk_attribute add_abstype) |
1296 || Args.$$$ "abstract" |-- Scan.succeed (mk_attribute add_abs_eqn) |
1273 || Args.$$$ "abstract" |-- Scan.succeed (mk_attribute add_abs_eqn) |
1297 || (Args.$$$ "target" |-- Args.colon |-- Args.name >> |
|
1298 (mk_attribute o code_target_attr)) |
|
1299 || Scan.succeed (mk_attribute add_warning_eqn); |
1274 || Scan.succeed (mk_attribute add_warning_eqn); |
1300 in |
1275 in |
1301 Datatype_Interpretation.init |
1276 Datatype_Interpretation.init |
1302 #> Attrib.setup (Binding.name "code") (Scan.lift code_attribute_parser) |
1277 #> Attrib.setup (Binding.name "code") (Scan.lift code_attribute_parser) |
1303 "declare theorems for code generation" |
1278 "declare theorems for code generation" |