src/HOL/Tools/code_evaluation.ML
changeset 39567 5ee997fbe5cc
parent 39565 f4f87c6e2fad
child 40726 16dcfedc4eb7
equal deleted inserted replaced
39566:87a5704673f0 39567:5ee997fbe5cc
    10   val dynamic_value_strict: theory -> term -> term
    10   val dynamic_value_strict: theory -> term -> term
    11   val dynamic_value_exn: theory -> term -> term Exn.result
    11   val dynamic_value_exn: theory -> term -> term Exn.result
    12   val static_value: theory -> string list -> typ list -> term -> term option
    12   val static_value: theory -> string list -> typ list -> term -> term option
    13   val static_value_strict: theory -> string list -> typ list -> term -> term
    13   val static_value_strict: theory -> string list -> typ list -> term -> term
    14   val static_value_exn: theory -> string list -> typ list -> term -> term Exn.result
    14   val static_value_exn: theory -> string list -> typ list -> term -> term Exn.result
       
    15   val dynamic_eval_conv: conv
       
    16   val static_eval_conv: theory -> string list -> typ list -> conv
    15   val put_term: (unit -> term) -> Proof.context -> Proof.context
    17   val put_term: (unit -> term) -> Proof.context -> Proof.context
    16   val tracing: string -> 'a -> 'a
    18   val tracing: string -> 'a -> 'a
    17   val setup: theory -> theory
    19   val setup: theory -> theory
    18 end;
    20 end;
    19 
    21 
   178 
   180 
   179 val static_value = gen_static_value Code_Runtime.static_value;
   181 val static_value = gen_static_value Code_Runtime.static_value;
   180 val static_value_strict = gen_static_value Code_Runtime.static_value_strict;
   182 val static_value_strict = gen_static_value Code_Runtime.static_value_strict;
   181 val static_value_exn = gen_static_value Code_Runtime.static_value_exn;
   183 val static_value_exn = gen_static_value Code_Runtime.static_value_exn;
   182 
   184 
       
   185 fun certify_eval thy value conv ct =
       
   186   let
       
   187     val t = Thm.term_of ct;
       
   188     val T = fastype_of t;
       
   189     val mk_eq = Thm.mk_binop (Thm.cterm_of thy (Const ("==", T --> T --> propT)));
       
   190   in case value t
       
   191    of NONE => Thm.reflexive ct
       
   192     | SOME t' => conv (mk_eq ct (Thm.cterm_of thy t')) RS @{thm eq_eq_TrueD}
       
   193         handle THM _ =>
       
   194           error ("Failed to certify evaluation result of " ^ Syntax.string_of_term_global thy t)
       
   195   end;
       
   196 
       
   197 val dynamic_eval_conv = Conv.tap_thy
       
   198   (fn thy => certify_eval thy (dynamic_value thy) Code_Runtime.dynamic_holds_conv);
       
   199 
       
   200 fun static_eval_conv thy consts Ts =
       
   201   let
       
   202     val eqs = "==" :: @{const_name HOL.eq} ::
       
   203       map (fn T => AxClass.unoverload_const thy (@{const_name HOL.equal}, T)) Ts;
       
   204         (*assumes particular code equations for "==" etc.*)
       
   205   in
       
   206     certify_eval thy (static_value thy consts Ts)
       
   207       (Code_Runtime.static_holds_conv thy (union (op =) eqs consts))
       
   208   end;
       
   209 
   183 
   210 
   184 (** diagnostic **)
   211 (** diagnostic **)
   185 
   212 
   186 fun tracing s x = (Output.tracing s; x);
   213 fun tracing s x = (Output.tracing s; x);
   187 
   214