src/HOL/Tools/code_evaluation.ML
changeset 56245 84fc7dfa3cd4
parent 55757 9fc71814b8c1
child 56925 601edd9a6859
equal deleted inserted replaced
56244:3298b7a2795a 56245:84fc7dfa3cd4
   191 fun certify_eval ctxt value conv ct =
   191 fun certify_eval ctxt value conv ct =
   192   let
   192   let
   193     val cert = Thm.cterm_of (Proof_Context.theory_of ctxt);
   193     val cert = Thm.cterm_of (Proof_Context.theory_of ctxt);
   194     val t = Thm.term_of ct;
   194     val t = Thm.term_of ct;
   195     val T = fastype_of t;
   195     val T = fastype_of t;
   196     val mk_eq = Thm.mk_binop (cert (Const ("==", T --> T --> propT)));
   196     val mk_eq = Thm.mk_binop (cert (Const (@{const_name Pure.eq}, T --> T --> propT)));
   197   in case value ctxt t
   197   in case value ctxt t
   198    of NONE => Thm.reflexive ct
   198    of NONE => Thm.reflexive ct
   199     | SOME t' => conv ctxt (mk_eq ct (cert t')) RS @{thm eq_eq_TrueD}
   199     | SOME t' => conv ctxt (mk_eq ct (cert t')) RS @{thm eq_eq_TrueD}
   200         handle THM _ =>
   200         handle THM _ =>
   201           error ("Failed to certify evaluation result of " ^ Syntax.string_of_term ctxt t)
   201           error ("Failed to certify evaluation result of " ^ Syntax.string_of_term ctxt t)
   204 fun dynamic_conv ctxt = certify_eval ctxt dynamic_value
   204 fun dynamic_conv ctxt = certify_eval ctxt dynamic_value
   205   Code_Runtime.dynamic_holds_conv;
   205   Code_Runtime.dynamic_holds_conv;
   206 
   206 
   207 fun static_conv ctxt consts Ts =
   207 fun static_conv ctxt consts Ts =
   208   let
   208   let
   209     val eqs = "==" :: @{const_name HOL.eq} ::
   209     val eqs = @{const_name Pure.eq} :: @{const_name HOL.eq} ::
   210       map (fn T => Axclass.unoverload_const (Proof_Context.theory_of ctxt)
   210       map (fn T => Axclass.unoverload_const (Proof_Context.theory_of ctxt)
   211         (@{const_name HOL.equal}, T)) Ts; (*assumes particular code equations for "==" etc.*)
   211         (@{const_name HOL.equal}, T)) Ts; (*assumes particular code equations for Pure.eq etc.*)
   212     val value = static_value ctxt consts Ts;
   212     val value = static_value ctxt consts Ts;
   213     val holds = Code_Runtime.static_holds_conv ctxt (union (op =) eqs consts);
   213     val holds = Code_Runtime.static_holds_conv ctxt (union (op =) eqs consts);
   214   in
   214   in
   215     fn ctxt' => certify_eval ctxt' value holds
   215     fn ctxt' => certify_eval ctxt' value holds
   216   end;
   216   end;