src/Pure/Isar/code.ML
changeset 48101 1b9796b7ab03
parent 48075 ec5e62b868eb
child 48902 44a6967240b7
equal deleted inserted replaced
48100:0122ba071e1a 48101:1b9796b7ab03
    63   val get_type: theory -> string
    63   val get_type: theory -> string
    64     -> ((string * sort) list * (string * ((string * sort) list * typ list)) list) * bool
    64     -> ((string * sort) list * (string * ((string * sort) list * typ list)) list) * bool
    65   val get_type_of_constr_or_abstr: theory -> string -> (string * bool) option
    65   val get_type_of_constr_or_abstr: theory -> string -> (string * bool) option
    66   val is_constr: theory -> string -> bool
    66   val is_constr: theory -> string -> bool
    67   val is_abstr: theory -> string -> bool
    67   val is_abstr: theory -> string -> bool
    68   val get_cert: theory -> ((thm * bool) list -> (thm * bool) list) -> string -> cert
    68   val get_cert: theory -> { functrans: ((thm * bool) list -> (thm * bool) list option) list,
       
    69     ss: simpset } -> string -> cert
    69   val get_case_scheme: theory -> string -> (int * (int * string option list)) option
    70   val get_case_scheme: theory -> string -> (int * (int * string option list)) option
    70   val get_case_cong: theory -> string -> thm option
    71   val get_case_cong: theory -> string -> thm option
    71   val undefineds: theory -> string list
    72   val undefineds: theory -> string list
    72   val print_codesetup: theory -> unit
    73   val print_codesetup: theory -> unit
    73 end;
    74 end;
   852 fun retrieve_raw thy c =
   853 fun retrieve_raw thy c =
   853   Symtab.lookup ((the_functions o the_exec) thy) c
   854   Symtab.lookup ((the_functions o the_exec) thy) c
   854   |> Option.map (snd o fst)
   855   |> Option.map (snd o fst)
   855   |> the_default empty_fun_spec
   856   |> the_default empty_fun_spec
   856 
   857 
   857 fun get_cert thy f c = case retrieve_raw thy c
   858 fun eqn_conv conv ct =
   858  of Default (_, eqns_lazy) => Lazy.force eqns_lazy
   859   let
   859       |> (map o apfst) (Thm.transfer thy)
   860     fun lhs_conv ct = if can Thm.dest_comb ct
   860       |> f
   861       then Conv.combination_conv lhs_conv conv ct
   861       |> (map o apfst) (AxClass.unoverload thy)
   862       else Conv.all_conv ct;
   862       |> cert_of_eqns thy c
   863   in Conv.combination_conv (Conv.arg_conv lhs_conv) conv ct end;
   863   | Eqns eqns => eqns
   864 
   864       |> (map o apfst) (Thm.transfer thy)
   865 fun rewrite_eqn thy conv ss =
   865       |> f
   866   let
   866       |> (map o apfst) (AxClass.unoverload thy)
   867     val ctxt = Proof_Context.init_global thy;
   867       |> cert_of_eqns thy c
   868     val rewrite = Conv.fconv_rule (conv (Simplifier.rewrite ss));
   868   | Proj (_, tyco) =>
   869   in singleton (Variable.trade (K (map rewrite)) ctxt) end;
   869       cert_of_proj thy c tyco
   870 
   870   | Abstr (abs_thm, tyco) => abs_thm
   871 fun cert_of_eqns_preprocess thy functrans ss c =
   871       |> Thm.transfer thy
   872   (map o apfst) (Thm.transfer thy)
   872       |> AxClass.unoverload thy
   873   #> perhaps (perhaps_loop (perhaps_apply functrans))
   873       |> cert_of_abs thy tyco c;
   874   #> (map o apfst) (rewrite_eqn thy eqn_conv ss) 
       
   875   #> (map o apfst) (AxClass.unoverload thy)
       
   876   #> cert_of_eqns thy c;
       
   877 
       
   878 fun get_cert thy { functrans, ss } c =
       
   879   case retrieve_raw thy c
       
   880    of Default (_, eqns_lazy) => Lazy.force eqns_lazy
       
   881         |> cert_of_eqns_preprocess thy functrans ss c
       
   882     | Eqns eqns => eqns
       
   883         |> cert_of_eqns_preprocess thy functrans ss c
       
   884     | Proj (_, tyco) =>
       
   885         cert_of_proj thy c tyco
       
   886     | Abstr (abs_thm, tyco) => abs_thm
       
   887         |> Thm.transfer thy
       
   888         |> rewrite_eqn thy Conv.arg_conv ss
       
   889         |> AxClass.unoverload thy
       
   890         |> cert_of_abs thy tyco c;
   874 
   891 
   875 
   892 
   876 (* cases *)
   893 (* cases *)
   877 
   894 
   878 fun case_certificate thm =
   895 fun case_certificate thm =