1519 (* attributes *) |
1519 (* attributes *) |
1520 |
1520 |
1521 fun code_attribute f = Thm.declaration_attribute |
1521 fun code_attribute f = Thm.declaration_attribute |
1522 (fn thm => Context.mapping (f thm) I); |
1522 (fn thm => Context.mapping (f thm) I); |
1523 |
1523 |
1524 fun code_const_attribute f cs = |
1524 fun code_thm_attribute g f = |
1525 code_attribute (K (fold (fn c => fn thy => f (read_const thy c) thy) cs)); |
1525 g |-- Scan.succeed (code_attribute f); |
|
1526 |
|
1527 fun code_const_attribute g f = |
|
1528 g -- Args.colon |-- Scan.repeat1 Parse.term |
|
1529 >> (fn ts => code_attribute (K (fold (fn t => fn thy => f (read_const thy t) thy) ts))); |
1526 |
1530 |
1527 val _ = Theory.setup |
1531 val _ = Theory.setup |
1528 (let |
1532 (let |
1529 val code_attribute_parser = |
1533 val code_attribute_parser = |
1530 Args.$$$ "equation" |-- Scan.succeed (code_attribute |
1534 code_thm_attribute (Args.$$$ "equation") |
1531 (fn thm => generic_add_eqn Liberal (thm, true))) |
1535 (fn thm => generic_add_eqn Liberal (thm, true)) |
1532 || Args.$$$ "nbe" |-- Scan.succeed (code_attribute |
1536 || code_thm_attribute (Args.$$$ "nbe") |
1533 (fn thm => generic_add_eqn Liberal (thm, false))) |
1537 (fn thm => generic_add_eqn Liberal (thm, false)) |
1534 || Args.$$$ "abstract" |-- Scan.succeed (code_attribute |
1538 || code_thm_attribute (Args.$$$ "abstract") |
1535 (generic_declare_abstract_eqn Liberal)) |
1539 (generic_declare_abstract_eqn Liberal) |
1536 || Args.$$$ "abstype" |-- Scan.succeed (code_attribute |
1540 || code_thm_attribute (Args.$$$ "abstype") |
1537 (generic_declare_abstype Liberal)) |
1541 (generic_declare_abstype Liberal) |
1538 || Args.del |-- Scan.succeed (code_attribute del_eqn_global) |
1542 || code_thm_attribute Args.del |
1539 || Args.$$$ "abort" -- Args.colon |-- (Scan.repeat1 Parse.term |
1543 del_eqn_global |
1540 >> code_const_attribute declare_aborting_global) |
1544 || code_const_attribute (Args.$$$ "abort") |
1541 || Args.$$$ "drop" -- Args.colon |-- (Scan.repeat1 Parse.term |
1545 declare_aborting_global |
1542 >> code_const_attribute declare_unimplemented_global) |
1546 || code_const_attribute (Args.$$$ "drop") |
|
1547 declare_unimplemented_global |
1543 || Scan.succeed (code_attribute |
1548 || Scan.succeed (code_attribute |
1544 add_maybe_abs_eqn_liberal); |
1549 add_maybe_abs_eqn_liberal); |
1545 in |
1550 in |
1546 Attrib.setup \<^binding>\<open>code\<close> (Scan.lift code_attribute_parser) |
1551 Attrib.setup \<^binding>\<open>code\<close> (Scan.lift code_attribute_parser) |
1547 "declare theorems for code generation" |
1552 "declare theorems for code generation" |