src/Pure/Isar/code.ML
changeset 70494 41108e3e9ca5
parent 70358 a55cfc8566fd
child 72057 ce3f26b4e790
equal deleted inserted replaced
70493:a9053fa30909 70494:41108e3e9ca5
    87 
    87 
    88 structure Code : PRIVATE_CODE =
    88 structure Code : PRIVATE_CODE =
    89 struct
    89 struct
    90 
    90 
    91 (** auxiliary **)
    91 (** auxiliary **)
    92 
       
    93 (* close theorem for storage *)
       
    94 
       
    95 val close = Thm.trim_context o Thm.close_derivation;
       
    96 
       
    97 
    92 
    98 (* printing *)
    93 (* printing *)
    99 
    94 
   100 fun string_of_typ thy =
    95 fun string_of_typ thy =
   101   Syntax.string_of_typ (Config.put show_sorts true (Syntax.init_pretty_global thy));
    96   Syntax.string_of_typ (Config.put show_sorts true (Syntax.init_pretty_global thy));
  1010       cert
  1005       cert
  1011   | constrain_cert thy sorts (Abstract (abs_thm, tyco)) =
  1006   | constrain_cert thy sorts (Abstract (abs_thm, tyco)) =
  1012       Abstract (snd (constrain_thm thy (fst (typscheme_abs thy abs_thm)) sorts abs_thm), tyco);
  1007       Abstract (snd (constrain_thm thy (fst (typscheme_abs thy abs_thm)) sorts abs_thm), tyco);
  1013 
  1008 
  1014 fun conclude_cert (Nothing cert_thm) =
  1009 fun conclude_cert (Nothing cert_thm) =
  1015       Nothing (Thm.close_derivation cert_thm)
  1010       Nothing (Thm.close_derivation \<^here> cert_thm)
  1016   | conclude_cert (Equations (cert_thm, propers)) =
  1011   | conclude_cert (Equations (cert_thm, propers)) =
  1017       Equations (Thm.close_derivation cert_thm, propers)
  1012       Equations (Thm.close_derivation \<^here> cert_thm, propers)
  1018   | conclude_cert (cert as Projection _) =
  1013   | conclude_cert (cert as Projection _) =
  1019       cert
  1014       cert
  1020   | conclude_cert (Abstract (abs_thm, tyco)) =
  1015   | conclude_cert (Abstract (abs_thm, tyco)) =
  1021       Abstract (Thm.close_derivation abs_thm, tyco);
  1016       Abstract (Thm.close_derivation \<^here> abs_thm, tyco);
  1022 
  1017 
  1023 fun typscheme_of_cert thy (Nothing cert_thm) =
  1018 fun typscheme_of_cert thy (Nothing cert_thm) =
  1024       fst (get_head thy cert_thm)
  1019       fst (get_head thy cert_thm)
  1025   | typscheme_of_cert thy (Equations (cert_thm, _)) =
  1020   | typscheme_of_cert thy (Equations (cert_thm, _)) =
  1026       fst (get_head thy cert_thm)
  1021       fst (get_head thy cert_thm)
  1401     fun drop (thm', proper') = if (proper orelse not proper')
  1396     fun drop (thm', proper') = if (proper orelse not proper')
  1402       andalso matches_args (args_of thm') then
  1397       andalso matches_args (args_of thm') then
  1403         (if verbose then warning ("Code generator: dropping subsumed code equation\n" ^
  1398         (if verbose then warning ("Code generator: dropping subsumed code equation\n" ^
  1404             Thm.string_of_thm_global thy thm') else (); true)
  1399             Thm.string_of_thm_global thy thm') else (); true)
  1405       else false;
  1400       else false;
  1406   in (close thm, proper) :: filter_out drop eqns end;
  1401   in (thm |> Thm.close_derivation \<^here> |> Thm.trim_context, proper) :: filter_out drop eqns end;
  1407 
  1402 
  1408 fun add_eqn_for (c, eqn) thy =
  1403 fun add_eqn_for (c, eqn) thy =
  1409   thy |> modify_specs (modify_pending_eqns c (subsumptive_add thy true eqn));
  1404   thy |> modify_specs (modify_pending_eqns c (subsumptive_add thy true eqn));
  1410 
  1405 
  1411 fun add_eqns_for default (c, proto_eqns) thy =
  1406 fun add_eqns_for default (c, proto_eqns) thy =
  1417           |> fold_rev (subsumptive_add thy (not default)) proto_eqns;
  1412           |> fold_rev (subsumptive_add thy (not default)) proto_eqns;
  1418       in specs |> register_fun_spec c (Eqns (default, eqns)) end
  1413       in specs |> register_fun_spec c (Eqns (default, eqns)) end
  1419     else specs);
  1414     else specs);
  1420 
  1415 
  1421 fun add_abstract_for (c, (thm, tyco_abs as (tyco, _))) =
  1416 fun add_abstract_for (c, (thm, tyco_abs as (tyco, _))) =
  1422   modify_specs (register_fun_spec c (Abstr (Thm.close_derivation thm, tyco_abs))
  1417   modify_specs (register_fun_spec c (Abstr (Thm.close_derivation \<^here> thm, tyco_abs))
  1423     #> map_types (History.modify_entry tyco (add_abstract_function c)))
  1418     #> map_types (History.modify_entry tyco (add_abstract_function c)))
  1424 
  1419 
  1425 in
  1420 in
  1426 
  1421 
  1427 fun generic_declare_eqns default strictness raw_eqns thy =
  1422 fun generic_declare_eqns default strictness raw_eqns thy =