src/Tools/Code/code_preproc.ML
changeset 38669 9ff76d0f0610
parent 38291 62abd53f37fa
child 38670 3c7db0192db9
equal deleted inserted replaced
38668:e8236c4aff16 38669:9ff76d0f0610
    22   val cert: code_graph -> string -> Code.cert
    22   val cert: code_graph -> string -> Code.cert
    23   val sortargs: code_graph -> string -> sort list
    23   val sortargs: code_graph -> string -> sort list
    24   val all: code_graph -> string list
    24   val all: code_graph -> string list
    25   val pretty: theory -> code_graph -> Pretty.T
    25   val pretty: theory -> code_graph -> Pretty.T
    26   val obtain: theory -> string list -> term list -> code_algebra * code_graph
    26   val obtain: theory -> string list -> term list -> code_algebra * code_graph
    27   val eval_conv: theory
    27   val dynamic_eval_conv: theory
    28     -> (code_algebra -> code_graph -> (string * sort) list -> term -> cterm -> thm) -> cterm -> thm
    28     -> (code_algebra -> code_graph -> (string * sort) list -> term -> cterm -> thm) -> cterm -> thm
    29   val eval: theory -> ((term -> term) -> 'a -> 'a)
    29   val dynamic_eval_value: theory -> ((term -> term) -> 'a -> 'a)
    30     -> (code_algebra -> code_graph -> (string * sort) list -> term -> 'a) -> term -> 'a
    30     -> (code_algebra -> code_graph -> (string * sort) list -> term -> 'a) -> term -> 'a
    31   val pre_post_conv: theory -> (cterm -> thm) -> cterm -> thm
    31   val pre_post_conv: theory -> (cterm -> thm) -> cterm -> thm
    32 
    32 
    33   val setup: theory -> theory
    33   val setup: theory -> theory
    34 end
    34 end
    72 
    72 
    73 fun delete_force msg key xs =
    73 fun delete_force msg key xs =
    74   if AList.defined (op =) xs key then AList.delete (op =) key xs
    74   if AList.defined (op =) xs key then AList.delete (op =) key xs
    75   else error ("No such " ^ msg ^ ": " ^ quote key);
    75   else error ("No such " ^ msg ^ ": " ^ quote key);
    76 
    76 
    77 fun map_data f = Code.purge_data
    77 val map_data = Code_Preproc_Data.map o map_thmproc;
    78   #> (Code_Preproc_Data.map o map_thmproc) f;
       
    79 
    78 
    80 val map_pre_post = map_data o apfst;
    79 val map_pre_post = map_data o apfst;
    81 val map_pre = map_pre_post o apfst;
    80 val map_pre = map_pre_post o apfst;
    82 val map_post = map_pre_post o apsnd;
    81 val map_post = map_pre_post o apsnd;
    83 
    82 
   423 (** retrieval and evaluation interfaces **)
   422 (** retrieval and evaluation interfaces **)
   424 
   423 
   425 fun obtain thy cs ts = apsnd snd
   424 fun obtain thy cs ts = apsnd snd
   426   (Wellsorted.change_yield thy (extend_arities_eqngr thy cs ts));
   425   (Wellsorted.change_yield thy (extend_arities_eqngr thy cs ts));
   427 
   426 
   428 fun gen_eval thy cterm_of conclude_evaluation evaluator proto_ct =
   427 fun dynamic_eval thy cterm_of conclude_evaluation evaluator proto_ct =
   429   let
   428   let
   430     val pp = Syntax.pp_global thy;
   429     val pp = Syntax.pp_global thy;
   431     val ct = cterm_of proto_ct;
   430     val ct = cterm_of proto_ct;
   432     val _ = (Sign.no_frees pp o map_types (K dummyT) o Sign.no_vars pp)
   431     val _ = (Sign.no_frees pp o map_types (K dummyT) o Sign.no_vars pp)
   433       (Thm.term_of ct);
   432       (Thm.term_of ct);
   438     val consts = fold_aterms
   437     val consts = fold_aterms
   439       (fn Const (c, _) => insert (op =) c | _ => I) t' [];
   438       (fn Const (c, _) => insert (op =) c | _ => I) t' [];
   440     val (algebra', eqngr') = obtain thy consts [t'];
   439     val (algebra', eqngr') = obtain thy consts [t'];
   441   in conclude_evaluation (evaluator algebra' eqngr' vs t' ct') thm end;
   440   in conclude_evaluation (evaluator algebra' eqngr' vs t' ct') thm end;
   442 
   441 
   443 fun simple_evaluator evaluator algebra eqngr vs t ct =
   442 fun dynamic_eval_conv thy =
   444   evaluator algebra eqngr vs t;
       
   445 
       
   446 fun eval_conv thy =
       
   447   let
   443   let
   448     fun conclude_evaluation thm2 thm1 =
   444     fun conclude_evaluation thm2 thm1 =
   449       let
   445       let
   450         val thm3 = postprocess_conv thy (Thm.rhs_of thm2);
   446         val thm3 = postprocess_conv thy (Thm.rhs_of thm2);
   451       in
   447       in
   452         Thm.transitive thm1 (Thm.transitive thm2 thm3) handle THM _ =>
   448         Thm.transitive thm1 (Thm.transitive thm2 thm3) handle THM _ =>
   453           error ("could not construct evaluation proof:\n"
   449           error ("could not construct evaluation proof:\n"
   454           ^ (cat_lines o map (Display.string_of_thm_global thy)) [thm1, thm2, thm3])
   450           ^ (cat_lines o map (Display.string_of_thm_global thy)) [thm1, thm2, thm3])
   455       end;
   451       end;
   456   in gen_eval thy I conclude_evaluation end;
   452   in dynamic_eval thy I conclude_evaluation end;
   457 
   453 
   458 fun eval thy postproc evaluator = gen_eval thy (Thm.cterm_of thy)
   454 fun dynamic_eval_value thy postproc evaluator = dynamic_eval thy (Thm.cterm_of thy)
   459   (K o postproc (postprocess_term thy)) (simple_evaluator evaluator);
   455   (K o postproc (postprocess_term thy)) (K oooo evaluator);
   460 
   456 
   461 fun pre_post_conv thy conv = (preprocess_conv thy) then_conv conv then_conv (postprocess_conv thy);
   457 fun pre_post_conv thy conv = (preprocess_conv thy) then_conv conv then_conv (postprocess_conv thy);
   462 
   458 
   463 
   459 
   464 (** setup **)
   460 (** setup **)