src/Pure/Isar/code.ML
changeset 31125 80218ee73167
parent 31091 8316d22f10f5
child 31152 e79d1ff2abc5
equal deleted inserted replaced
31124:58bc773c60e2 31125:80218ee73167
    13   val add_default_eqn_attribute: attribute
    13   val add_default_eqn_attribute: attribute
    14   val add_default_eqn_attrib: Attrib.src
    14   val add_default_eqn_attrib: Attrib.src
    15   val del_eqn: thm -> theory -> theory
    15   val del_eqn: thm -> theory -> theory
    16   val del_eqns: string -> theory -> theory
    16   val del_eqns: string -> theory -> theory
    17   val add_eqnl: string * (thm * bool) list lazy -> theory -> theory
    17   val add_eqnl: string * (thm * bool) list lazy -> theory -> theory
    18   val map_pre: (simpset -> simpset) -> theory -> theory
       
    19   val map_post: (simpset -> simpset) -> theory -> theory
       
    20   val add_inline: thm -> theory -> theory
       
    21   val add_functrans: string * (theory -> (thm * bool) list -> (thm * bool) list option) -> theory -> theory
       
    22   val del_functrans: string -> theory -> theory
       
    23   val simple_functrans: (theory -> thm list -> thm list option)
       
    24     -> theory -> (thm * bool) list -> (thm * bool) list option
       
    25   val add_datatype: (string * typ) list -> theory -> theory
    18   val add_datatype: (string * typ) list -> theory -> theory
    26   val add_datatype_cmd: string list -> theory -> theory
    19   val add_datatype_cmd: string list -> theory -> theory
    27   val type_interpretation:
    20   val type_interpretation:
    28     (string * ((string * sort) list * (string * typ list) list)
    21     (string * ((string * sort) list * (string * typ list) list)
    29       -> theory -> theory) -> theory -> theory
    22       -> theory -> theory) -> theory -> theory
    30   val add_case: thm -> theory -> theory
    23   val add_case: thm -> theory -> theory
    31   val add_undefined: string -> theory -> theory
    24   val add_undefined: string -> theory -> theory
    32   val purge_data: theory -> theory
    25   val purge_data: theory -> theory
    33 
    26 
    34   val these_eqns: theory -> string -> (thm * bool) list
    27   val these_eqns: theory -> string -> (thm * bool) list
    35   val these_raw_eqns: theory -> string -> (thm * bool) list
       
    36   val get_datatype: theory -> string -> ((string * sort) list * (string * typ list) list)
    28   val get_datatype: theory -> string -> ((string * sort) list * (string * typ list) list)
    37   val get_datatype_of_constr: theory -> string -> string option
    29   val get_datatype_of_constr: theory -> string -> string option
    38   val get_case_scheme: theory -> string -> (int * (int * string list)) option
    30   val get_case_scheme: theory -> string -> (int * (int * string list)) option
    39   val is_undefined: theory -> string -> bool
    31   val is_undefined: theory -> string -> bool
    40   val default_typscheme: theory -> string -> (string * sort) list * typ
    32   val default_typscheme: theory -> string -> (string * sort) list * typ
    41 
    33   val assert_eqn: theory -> thm * bool -> thm * bool
    42   val preprocess_conv: theory -> cterm -> thm
    34   val assert_eqns_const: theory -> string
    43   val preprocess_term: theory -> term -> term
    35     -> (thm * bool) list -> (thm * bool) list
    44   val postprocess_conv: theory -> cterm -> thm
       
    45   val postprocess_term: theory -> term -> term
       
    46 
    36 
    47   val add_attribute: string * attribute parser -> theory -> theory
    37   val add_attribute: string * attribute parser -> theory -> theory
    48 
    38 
    49   val print_codesetup: theory -> unit
    39   val print_codesetup: theory -> unit
    50 end;
    40 end;
   157   cases: (int * (int * string list)) Symtab.table * unit Symtab.table
   147   cases: (int * (int * string list)) Symtab.table * unit Symtab.table
   158 };
   148 };
   159 
   149 
   160 fun mk_spec ((concluded_history, eqns), (dtyps, cases)) =
   150 fun mk_spec ((concluded_history, eqns), (dtyps, cases)) =
   161   Spec { concluded_history = concluded_history, eqns = eqns, dtyps = dtyps, cases = cases };
   151   Spec { concluded_history = concluded_history, eqns = eqns, dtyps = dtyps, cases = cases };
       
   152 val empty_spec =
       
   153   mk_spec ((false, Symtab.empty), (Symtab.empty, (Symtab.empty, Symtab.empty)));
   162 fun map_spec f (Spec { concluded_history = concluded_history, eqns = eqns,
   154 fun map_spec f (Spec { concluded_history = concluded_history, eqns = eqns,
   163   dtyps = dtyps, cases = cases }) =
   155   dtyps = dtyps, cases = cases }) =
   164   mk_spec (f ((concluded_history, eqns), (dtyps, cases)));
   156   mk_spec (f ((concluded_history, eqns), (dtyps, cases)));
   165 fun merge_spec (Spec { concluded_history = _, eqns = eqns1, dtyps = dtyps1, cases = (cases1, undefs1) },
   157 fun merge_spec (Spec { concluded_history = _, eqns = eqns1, dtyps = dtyps1, cases = (cases1, undefs1) },
   166   Spec { concluded_history = _, eqns = eqns2, dtyps = dtyps2, cases = (cases2, undefs2) }) =
   158   Spec { concluded_history = _, eqns = eqns2, dtyps = dtyps2, cases = (cases2, undefs2) }) =
   167   let
   159   let
   168     fun merge_eqns ((_, history1), (_, history2)) =
   160     fun merge_eqns ((_, history1), (_, history2)) =
   169       let
   161       let
   170         val raw_history = AList.merge (op =) (K true) (history1, history2)
   162         val raw_history = AList.merge (op = : serial * serial -> bool)
       
   163           (K true) (history1, history2)
   171         val filtered_history = filter_out (fst o snd) raw_history
   164         val filtered_history = filter_out (fst o snd) raw_history
   172         val history = if null filtered_history
   165         val history = if null filtered_history
   173           then raw_history else filtered_history;
   166           then raw_history else filtered_history;
   174       in ((false, (snd o hd) history), history) end;
   167       in ((false, (snd o hd) history), history) end;
   175     val eqns = Symtab.join (K merge_eqns) (eqns1, eqns2);
   168     val eqns = Symtab.join (K merge_eqns) (eqns1, eqns2);
   177     val cases = (Symtab.merge (K true) (cases1, cases2),
   170     val cases = (Symtab.merge (K true) (cases1, cases2),
   178       Symtab.merge (K true) (undefs1, undefs2));
   171       Symtab.merge (K true) (undefs1, undefs2));
   179   in mk_spec ((false, eqns), (dtyps, cases)) end;
   172   in mk_spec ((false, eqns), (dtyps, cases)) end;
   180 
   173 
   181 
   174 
   182 (* pre- and postprocessor *)
       
   183 
       
   184 datatype thmproc = Thmproc of {
       
   185   pre: simpset,
       
   186   post: simpset,
       
   187   functrans: (string * (serial * (theory -> (thm * bool) list -> (thm * bool) list option))) list
       
   188 };
       
   189 
       
   190 fun mk_thmproc ((pre, post), functrans) =
       
   191   Thmproc { pre = pre, post = post, functrans = functrans };
       
   192 fun map_thmproc f (Thmproc { pre, post, functrans }) =
       
   193   mk_thmproc (f ((pre, post), functrans));
       
   194 fun merge_thmproc (Thmproc { pre = pre1, post = post1, functrans = functrans1 },
       
   195   Thmproc { pre = pre2, post = post2, functrans = functrans2 }) =
       
   196     let
       
   197       val pre = Simplifier.merge_ss (pre1, pre2);
       
   198       val post = Simplifier.merge_ss (post1, post2);
       
   199       val functrans = AList.merge (op =) (eq_fst (op =)) (functrans1, functrans2);
       
   200     in mk_thmproc ((pre, post), functrans) end;
       
   201 
       
   202 datatype exec = Exec of {
       
   203   thmproc: thmproc,
       
   204   spec: spec
       
   205 };
       
   206 
       
   207 
       
   208 (* code setup data *)
   175 (* code setup data *)
   209 
   176 
   210 fun mk_exec (thmproc, spec) =
   177 fun the_spec (Spec x) = x;
   211   Exec { thmproc = thmproc, spec = spec };
       
   212 fun map_exec f (Exec { thmproc = thmproc, spec = spec }) =
       
   213   mk_exec (f (thmproc, spec));
       
   214 fun merge_exec (Exec { thmproc = thmproc1, spec = spec1 },
       
   215   Exec { thmproc = thmproc2, spec = spec2 }) =
       
   216   let
       
   217     val thmproc = merge_thmproc (thmproc1, thmproc2);
       
   218     val spec = merge_spec (spec1, spec2);
       
   219   in mk_exec (thmproc, spec) end;
       
   220 val empty_exec = mk_exec (mk_thmproc ((Simplifier.empty_ss, Simplifier.empty_ss), []),
       
   221   mk_spec ((false, Symtab.empty), (Symtab.empty, (Symtab.empty, Symtab.empty))));
       
   222 
       
   223 fun the_thmproc (Exec { thmproc = Thmproc x, ...}) = x;
       
   224 fun the_spec (Exec { spec = Spec x, ...}) = x;
       
   225 val the_eqns = #eqns o the_spec;
   178 val the_eqns = #eqns o the_spec;
   226 val the_dtyps = #dtyps o the_spec;
   179 val the_dtyps = #dtyps o the_spec;
   227 val the_cases = #cases o the_spec;
   180 val the_cases = #cases o the_spec;
   228 val map_thmproc = map_exec o apfst o map_thmproc;
   181 val map_concluded_history = map_spec o apfst o apfst;
   229 val map_concluded_history = map_exec o apsnd o map_spec o apfst o apfst;
   182 val map_eqns = map_spec o apfst o apsnd;
   230 val map_eqns = map_exec o apsnd o map_spec o apfst o apsnd;
   183 val map_dtyps = map_spec o apsnd o apfst;
   231 val map_dtyps = map_exec o apsnd o map_spec o apsnd o apfst;
   184 val map_cases = map_spec o apsnd o apsnd;
   232 val map_cases = map_exec o apsnd o map_spec o apsnd o apsnd;
       
   233 
   185 
   234 
   186 
   235 (* data slots dependent on executable content *)
   187 (* data slots dependent on executable content *)
   236 
   188 
   237 (*private copy avoids potential conflict of table exceptions*)
   189 (*private copy avoids potential conflict of table exceptions*)
   275 local
   227 local
   276 
   228 
   277 type data = Object.T Datatab.table;
   229 type data = Object.T Datatab.table;
   278 val empty_data = Datatab.empty : data;
   230 val empty_data = Datatab.empty : data;
   279 
   231 
   280 structure CodeData = TheoryDataFun
   232 structure Code_Data = TheoryDataFun
   281 (
   233 (
   282   type T = exec * data ref;
   234   type T = spec * data ref;
   283   val empty = (empty_exec, ref empty_data);
   235   val empty = (empty_spec, ref empty_data);
   284   fun copy (exec, data) = (exec, ref (! data));
   236   fun copy (spec, data) = (spec, ref (! data));
   285   val extend = copy;
   237   val extend = copy;
   286   fun merge pp ((exec1, data1), (exec2, data2)) =
   238   fun merge pp ((spec1, data1), (spec2, data2)) =
   287     (merge_exec (exec1, exec2), ref empty_data);
   239     (merge_spec (spec1, spec2), ref empty_data);
   288 );
   240 );
   289 
   241 
   290 fun thy_data f thy = f ((snd o CodeData.get) thy);
   242 fun thy_data f thy = f ((snd o Code_Data.get) thy);
   291 
   243 
   292 fun get_ensure_init kind data_ref =
   244 fun get_ensure_init kind data_ref =
   293   case Datatab.lookup (! data_ref) kind
   245   case Datatab.lookup (! data_ref) kind
   294    of SOME x => x
   246    of SOME x => x
   295     | NONE => let val y = invoke_init kind
   247     | NONE => let val y = invoke_init kind
   297 
   249 
   298 in
   250 in
   299 
   251 
   300 (* access to executable content *)
   252 (* access to executable content *)
   301 
   253 
   302 val the_exec = fst o CodeData.get;
   254 val the_exec = fst o Code_Data.get;
   303 
   255 
   304 fun complete_class_params thy cs =
   256 fun complete_class_params thy cs =
   305   fold (fn c => case AxClass.inst_of_param thy c
   257   fold (fn c => case AxClass.inst_of_param thy c
   306    of NONE => insert (op =) c
   258    of NONE => insert (op =) c
   307     | SOME (c', _) => insert (op =) c' #> insert (op =) c) cs [];
   259     | SOME (c', _) => insert (op =) c' #> insert (op =) c) cs [];
   308 
   260 
   309 fun map_exec_purge touched f thy =
   261 fun map_exec_purge touched f thy =
   310   CodeData.map (fn (exec, data) => (f exec, ref (case touched
   262   Code_Data.map (fn (exec, data) => (f exec, ref (case touched
   311    of SOME cs => invoke_purge_all thy (complete_class_params thy cs) (! data)
   263    of SOME cs => invoke_purge_all thy (complete_class_params thy cs) (! data)
   312     | NONE => empty_data))) thy;
   264     | NONE => empty_data))) thy;
   313 
   265 
   314 val purge_data = (CodeData.map o apsnd) (K (ref empty_data));
   266 val purge_data = (Code_Data.map o apsnd) (K (ref empty_data));
   315 
   267 
   316 
   268 
   317 (* tackling equation history *)
   269 (* tackling equation history *)
   318 
   270 
   319 fun get_eqns thy c =
   271 fun get_eqns thy c =
   321   |> Option.map (Lazy.force o snd o snd o fst)
   273   |> Option.map (Lazy.force o snd o snd o fst)
   322   |> these;
   274   |> these;
   323 
   275 
   324 fun continue_history thy = if (#concluded_history o the_spec o the_exec) thy
   276 fun continue_history thy = if (#concluded_history o the_spec o the_exec) thy
   325   then thy
   277   then thy
   326     |> (CodeData.map o apfst o map_concluded_history) (K false)
   278     |> (Code_Data.map o apfst o map_concluded_history) (K false)
   327     |> SOME
   279     |> SOME
   328   else NONE;
   280   else NONE;
   329 
   281 
   330 fun conclude_history thy = if (#concluded_history o the_spec o the_exec) thy
   282 fun conclude_history thy = if (#concluded_history o the_spec o the_exec) thy
   331   then NONE
   283   then NONE
   332   else thy
   284   else thy
   333     |> (CodeData.map o apfst)
   285     |> (Code_Data.map o apfst)
   334         ((map_eqns o Symtab.map) (fn ((changed, current), history) =>
   286         ((map_eqns o Symtab.map) (fn ((changed, current), history) =>
   335           ((false, current),
   287           ((false, current),
   336             if changed then (serial (), current) :: history else history))
   288             if changed then (serial (), current) :: history else history))
   337         #> map_concluded_history (K true))
   289         #> map_concluded_history (K true))
   338     |> SOME;
   290     |> SOME;
   339 
   291 
   340 val _ = Context.>> (Context.map_theory (CodeData.init
   292 val _ = Context.>> (Context.map_theory (Code_Data.init
   341   #> Theory.at_begin continue_history
   293   #> Theory.at_begin continue_history
   342   #> Theory.at_end conclude_history));
   294   #> Theory.at_end conclude_history));
   343 
   295 
   344 
   296 
   345 (* access to data dependent on abstract executable content *)
   297 (* access to data dependent on abstract executable content *)
   363         val (x, data') = f (dest data);
   315         val (x, data') = f (dest data);
   364       in (x, (change data_ref (Datatab.update (kind, mk data')); data')) end;
   316       in (x, (change data_ref (Datatab.update (kind, mk data')); data')) end;
   365   in thy_data chnge end;
   317   in thy_data chnge end;
   366 
   318 
   367 end; (*local*)
   319 end; (*local*)
   368 
       
   369 
       
   370 (* print executable content *)
       
   371 
   320 
   372 fun print_codesetup thy =
   321 fun print_codesetup thy =
   373   let
   322   let
   374     val ctxt = ProofContext.init thy;
   323     val ctxt = ProofContext.init thy;
   375     val exec = the_exec thy;
   324     val exec = the_exec thy;
   388                      (Pretty.block o Pretty.breaks)
   337                      (Pretty.block o Pretty.breaks)
   389                         (Pretty.str (Code_Unit.string_of_const thy c)
   338                         (Pretty.str (Code_Unit.string_of_const thy c)
   390                           :: Pretty.str "of"
   339                           :: Pretty.str "of"
   391                           :: map (Pretty.quote o Syntax.pretty_typ_global thy) tys)) cos)
   340                           :: map (Pretty.quote o Syntax.pretty_typ_global thy) tys)) cos)
   392           );
   341           );
   393     val pre = (#pre o the_thmproc) exec;
       
   394     val post = (#post o the_thmproc) exec;
       
   395     val functrans = (map fst o #functrans o the_thmproc) exec;
       
   396     val eqns = the_eqns exec
   342     val eqns = the_eqns exec
   397       |> Symtab.dest
   343       |> Symtab.dest
   398       |> (map o apfst) (Code_Unit.string_of_const thy)
   344       |> (map o apfst) (Code_Unit.string_of_const thy)
   399       |> (map o apsnd) (snd o fst)
   345       |> (map o apsnd) (snd o fst)
   400       |> sort (string_ord o pairself fst);
   346       |> sort (string_ord o pairself fst);
   407     (Pretty.writeln o Pretty.chunks) [
   353     (Pretty.writeln o Pretty.chunks) [
   408       Pretty.block (
   354       Pretty.block (
   409         Pretty.str "code equations:"
   355         Pretty.str "code equations:"
   410         :: Pretty.fbrk
   356         :: Pretty.fbrk
   411         :: (Pretty.fbreaks o map pretty_eqn) eqns
   357         :: (Pretty.fbreaks o map pretty_eqn) eqns
   412       ),
       
   413       Pretty.block [
       
   414         Pretty.str "preprocessing simpset:",
       
   415         Pretty.fbrk,
       
   416         Simplifier.pretty_ss ctxt pre
       
   417       ],
       
   418       Pretty.block [
       
   419         Pretty.str "postprocessing simpset:",
       
   420         Pretty.fbrk,
       
   421         Simplifier.pretty_ss ctxt post
       
   422       ],
       
   423       Pretty.block (
       
   424         Pretty.str "function transformers:"
       
   425         :: Pretty.fbrk
       
   426         :: (Pretty.fbreaks o map Pretty.str) functrans
       
   427       ),
   358       ),
   428       Pretty.block (
   359       Pretty.block (
   429         Pretty.str "datatypes:"
   360         Pretty.str "datatypes:"
   430         :: Pretty.fbrk
   361         :: Pretty.fbrk
   431         :: (Pretty.fbreaks o map pretty_dtyp) dtyps
   362         :: (Pretty.fbreaks o map pretty_dtyp) dtyps
   459       in map (Thm.instantiate (instT, [])) thms' end;
   390       in map (Thm.instantiate (instT, [])) thms' end;
   460 
   391 
   461 
   392 
   462 (** interfaces and attributes **)
   393 (** interfaces and attributes **)
   463 
   394 
   464 fun delete_force msg key xs =
       
   465   if AList.defined (op =) xs key then AList.delete (op =) key xs
       
   466   else error ("No such " ^ msg ^ ": " ^ quote key);
       
   467 
       
   468 fun get_datatype thy tyco =
   395 fun get_datatype thy tyco =
   469   case these (Symtab.lookup ((the_dtyps o the_exec) thy) tyco)
   396   case these (Symtab.lookup ((the_dtyps o the_exec) thy) tyco)
   470    of (_, spec) :: _ => spec
   397    of (_, spec) :: _ => spec
   471     | [] => Sign.arity_number thy tyco
   398     | [] => Sign.arity_number thy tyco
   472         |> Name.invents Name.context Name.aT
   399         |> Name.invents Name.context Name.aT
   566   in (map_exec_purge (SOME [c]) o map_cases o apfst) (Symtab.update (c, entry)) thy end;
   493   in (map_exec_purge (SOME [c]) o map_cases o apfst) (Symtab.update (c, entry)) thy end;
   567 
   494 
   568 fun add_undefined c thy =
   495 fun add_undefined c thy =
   569   (map_exec_purge (SOME [c]) o map_cases o apsnd) (Symtab.update (c, ())) thy;
   496   (map_exec_purge (SOME [c]) o map_cases o apsnd) (Symtab.update (c, ())) thy;
   570 
   497 
   571 val map_pre = map_exec_purge NONE o map_thmproc o apfst o apfst;
       
   572 val map_post = map_exec_purge NONE o map_thmproc o apfst o apsnd;
       
   573 
       
   574 val add_inline = map_pre o MetaSimplifier.add_simp;
       
   575 val del_inline = map_pre o MetaSimplifier.del_simp;
       
   576 val add_post = map_post o MetaSimplifier.add_simp;
       
   577 val del_post = map_post o MetaSimplifier.del_simp;
       
   578   
       
   579 fun add_functrans (name, f) =
       
   580   (map_exec_purge NONE o map_thmproc o apsnd)
       
   581     (AList.update (op =) (name, (serial (), f)));
       
   582 
       
   583 fun del_functrans name =
       
   584   (map_exec_purge NONE o map_thmproc o apsnd)
       
   585     (delete_force "function transformer" name);
       
   586 
       
   587 fun simple_functrans f thy eqns = case f thy (map fst eqns)
       
   588  of SOME thms' => SOME (map (rpair (forall snd eqns)) thms')
       
   589   | NONE => NONE;
       
   590 
       
   591 val _ = Context.>> (Context.map_theory
   498 val _ = Context.>> (Context.map_theory
   592   (let
   499   (let
   593     fun mk_attribute f = Thm.declaration_attribute (fn thm => Context.mapping (f thm) I);
   500     fun mk_attribute f = Thm.declaration_attribute (fn thm => Context.mapping (f thm) I);
   594     fun add_simple_attribute (name, f) =
   501     fun add_simple_attribute (name, f) =
   595       add_attribute (name, Scan.succeed (mk_attribute f));
   502       add_attribute (name, Scan.succeed (mk_attribute f));
   598         || Scan.succeed (mk_attribute add))
   505         || Scan.succeed (mk_attribute add))
   599   in
   506   in
   600     TypeInterpretation.init
   507     TypeInterpretation.init
   601     #> add_del_attribute ("", (add_eqn, del_eqn))
   508     #> add_del_attribute ("", (add_eqn, del_eqn))
   602     #> add_simple_attribute ("nbe", add_nbe_eqn)
   509     #> add_simple_attribute ("nbe", add_nbe_eqn)
   603     #> add_del_attribute ("inline", (add_inline, del_inline))
       
   604     #> add_del_attribute ("post", (add_post, del_post))
       
   605   end));
   510   end));
   606 
   511 
   607 
   512 fun these_eqns thy c =
   608 (** post- and preprocessing **)
       
   609 
       
   610 local
       
   611 
       
   612 fun apply_functrans thy c _ [] = []
       
   613   | apply_functrans thy c [] eqns = eqns
       
   614   | apply_functrans thy c functrans eqns = eqns
       
   615       |> perhaps (perhaps_loop (perhaps_apply functrans))
       
   616       |> assert_eqns_const thy c;
       
   617 
       
   618 fun rhs_conv conv thm = Thm.transitive thm ((conv o Thm.rhs_of) thm);
       
   619 
       
   620 fun term_of_conv thy f =
       
   621   Thm.cterm_of thy
       
   622   #> f
       
   623   #> Thm.prop_of
       
   624   #> Logic.dest_equals
       
   625   #> snd;
       
   626 
       
   627 fun preprocess thy c eqns =
       
   628   let
       
   629     val pre = (Simplifier.theory_context thy o #pre o the_thmproc o the_exec) thy;
       
   630     val functrans = (map (fn (_, (_, f)) => f thy) o #functrans
       
   631       o the_thmproc o the_exec) thy;
       
   632   in
       
   633     eqns
       
   634     |> apply_functrans thy c functrans
       
   635     |> (map o apfst) (Code_Unit.rewrite_eqn pre)
       
   636     |> (map o apfst) (AxClass.unoverload thy)
       
   637     |> map (assert_eqn thy)
       
   638     |> burrow_fst (common_typ_eqns thy)
       
   639   end;
       
   640 
       
   641 in
       
   642 
       
   643 fun preprocess_conv thy ct =
       
   644   let
       
   645     val pre = (Simplifier.theory_context thy o #pre o the_thmproc o the_exec) thy;
       
   646   in
       
   647     ct
       
   648     |> Simplifier.rewrite pre
       
   649     |> rhs_conv (AxClass.unoverload_conv thy)
       
   650   end;
       
   651 
       
   652 fun preprocess_term thy = term_of_conv thy (preprocess_conv thy);
       
   653 
       
   654 fun postprocess_conv thy ct =
       
   655   let
       
   656     val post = (Simplifier.theory_context thy o #post o the_thmproc o the_exec) thy;
       
   657   in
       
   658     ct
       
   659     |> AxClass.overload_conv thy
       
   660     |> rhs_conv (Simplifier.rewrite post)
       
   661   end;
       
   662 
       
   663 fun postprocess_term thy = term_of_conv thy (postprocess_conv thy);
       
   664 
       
   665 fun these_raw_eqns thy c =
       
   666   get_eqns thy c
   513   get_eqns thy c
   667   |> (map o apfst) (Thm.transfer thy)
   514   |> (map o apfst) (Thm.transfer thy)
   668   |> burrow_fst (common_typ_eqns thy);
   515   |> burrow_fst (common_typ_eqns thy);
   669 
       
   670 fun these_eqns thy c =
       
   671   get_eqns thy c
       
   672   |> (map o apfst) (Thm.transfer thy)
       
   673   |> preprocess thy c;
       
   674 
   516 
   675 fun default_typscheme thy c =
   517 fun default_typscheme thy c =
   676   let
   518   let
   677     fun the_const_typscheme c = (curry (Code_Unit.typscheme thy) c o snd o dest_Const
   519     fun the_const_typscheme c = (curry (Code_Unit.typscheme thy) c o snd o dest_Const
   678       o TermSubst.zero_var_indexes o curry Const "" o Sign.the_const_type thy) c;
   520       o TermSubst.zero_var_indexes o curry Const "" o Sign.the_const_type thy) c;
   683         then strip_sorts (the_const_typscheme c)
   525         then strip_sorts (the_const_typscheme c)
   684         else case get_eqns thy c
   526         else case get_eqns thy c
   685          of (thm, _) :: _ => (Code_Unit.typscheme_eqn thy o Drule.zero_var_indexes) thm
   527          of (thm, _) :: _ => (Code_Unit.typscheme_eqn thy o Drule.zero_var_indexes) thm
   686           | [] => strip_sorts (the_const_typscheme c) end;
   528           | [] => strip_sorts (the_const_typscheme c) end;
   687 
   529 
   688 end; (*local*)
       
   689 
       
   690 end; (*struct*)
   530 end; (*struct*)
   691 
   531 
   692 
   532 
   693 (** type-safe interfaces for data depedent on executable content **)
   533 (** type-safe interfaces for data depedent on executable content **)
   694 
   534