| author | wenzelm | 
| Thu, 07 Apr 2016 21:39:03 +0200 | |
| changeset 62911 | 78e03d8bf1c4 | 
| parent 61674 | 072012fb4a10 | 
| child 62952 | 85c6c2a1952d | 
| permissions | -rw-r--r-- | 
| 39564 | 1 | (* Title: HOL/Tools/code_evaluation.ML | 
| 2 | Author: Florian Haftmann, TU Muenchen | |
| 3 | ||
| 4 | Evaluation and reconstruction of terms in ML. | |
| 5 | *) | |
| 6 | ||
| 7 | signature CODE_EVALUATION = | |
| 8 | sig | |
| 55757 | 9 | val dynamic_value: Proof.context -> term -> term option | 
| 10 | val dynamic_value_strict: Proof.context -> term -> term | |
| 11 | val dynamic_value_exn: Proof.context -> term -> term Exn.result | |
| 56973 
62da80041afd
syntactic means to prevent accidental mixup of static and dynamic context
 haftmann parents: 
56926diff
changeset | 12 |   val static_value: { ctxt: Proof.context, consts: string list, Ts: typ list }
 | 
| 
62da80041afd
syntactic means to prevent accidental mixup of static and dynamic context
 haftmann parents: 
56926diff
changeset | 13 | -> Proof.context -> term -> term option | 
| 
62da80041afd
syntactic means to prevent accidental mixup of static and dynamic context
 haftmann parents: 
56926diff
changeset | 14 |   val static_value_strict: { ctxt: Proof.context, consts: string list, Ts: typ list }
 | 
| 
62da80041afd
syntactic means to prevent accidental mixup of static and dynamic context
 haftmann parents: 
56926diff
changeset | 15 | -> Proof.context -> term -> term | 
| 
62da80041afd
syntactic means to prevent accidental mixup of static and dynamic context
 haftmann parents: 
56926diff
changeset | 16 |   val static_value_exn: { ctxt: Proof.context, consts: string list, Ts: typ list }
 | 
| 
62da80041afd
syntactic means to prevent accidental mixup of static and dynamic context
 haftmann parents: 
56926diff
changeset | 17 | -> Proof.context -> term -> term Exn.result | 
| 55757 | 18 | val dynamic_conv: Proof.context -> conv | 
| 56973 
62da80041afd
syntactic means to prevent accidental mixup of static and dynamic context
 haftmann parents: 
56926diff
changeset | 19 |   val static_conv: { ctxt: Proof.context, consts: string list, Ts: typ list }
 | 
| 
62da80041afd
syntactic means to prevent accidental mixup of static and dynamic context
 haftmann parents: 
56926diff
changeset | 20 | -> Proof.context -> conv | 
| 39564 | 21 | val put_term: (unit -> term) -> Proof.context -> Proof.context | 
| 22 | val tracing: string -> 'a -> 'a | |
| 23 | end; | |
| 24 | ||
| 25 | structure Code_Evaluation : CODE_EVALUATION = | |
| 26 | struct | |
| 27 | ||
| 28 | (** term_of instances **) | |
| 29 | ||
| 30 | (* formal definition *) | |
| 31 | ||
| 32 | fun add_term_of tyco raw_vs thy = | |
| 33 | let | |
| 34 |     val vs = map (fn (v, _) => (v, @{sort typerep})) raw_vs;
 | |
| 35 | val ty = Type (tyco, map TFree vs); | |
| 36 |     val lhs = Const (@{const_name term_of}, ty --> @{typ term})
 | |
| 37 |       $ Free ("x", ty);
 | |
| 38 |     val rhs = @{term "undefined :: term"};
 | |
| 39 | val eq = HOLogic.mk_Trueprop (HOLogic.mk_eq (lhs, rhs)); | |
| 40 | fun triv_name_of t = (fst o dest_Free o fst o strip_comb o fst | |
| 41 | o HOLogic.dest_eq o HOLogic.dest_Trueprop) t ^ "_triv"; | |
| 42 | in | |
| 43 | thy | |
| 44 |     |> Class.instantiation ([tyco], vs, @{sort term_of})
 | |
| 45 | |> `(fn lthy => Syntax.check_term lthy eq) | |
| 46 | |-> (fn eq => Specification.definition (NONE, ((Binding.name (triv_name_of eq), []), eq))) | |
| 47 | |> snd | |
| 59498 
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
 wenzelm parents: 
59323diff
changeset | 48 | |> Class.prove_instantiation_exit (fn ctxt => Class.intro_classes_tac ctxt []) | 
| 39564 | 49 | end; | 
| 50 | ||
| 61667 
4b53042d7a40
explicit computation of sort arguments for code equations makes less assumption about sort arguments of underlying type class instances
 haftmann parents: 
60801diff
changeset | 51 | fun ensure_term_of (tyco, (vs, _)) thy = | 
| 39564 | 52 | let | 
| 48272 | 53 |     val need_inst = not (Sorts.has_instance (Sign.classes_of thy) tyco @{sort term_of})
 | 
| 54 |       andalso Sorts.has_instance (Sign.classes_of thy) tyco @{sort typerep};
 | |
| 61667 
4b53042d7a40
explicit computation of sort arguments for code equations makes less assumption about sort arguments of underlying type class instances
 haftmann parents: 
60801diff
changeset | 55 | in if need_inst then add_term_of tyco vs thy else thy end; | 
| 
4b53042d7a40
explicit computation of sort arguments for code equations makes less assumption about sort arguments of underlying type class instances
 haftmann parents: 
60801diff
changeset | 56 | |
| 
4b53042d7a40
explicit computation of sort arguments for code equations makes less assumption about sort arguments of underlying type class instances
 haftmann parents: 
60801diff
changeset | 57 | fun for_term_of_instance tyco vs f thy = | 
| 
4b53042d7a40
explicit computation of sort arguments for code equations makes less assumption about sort arguments of underlying type class instances
 haftmann parents: 
60801diff
changeset | 58 | let | 
| 
4b53042d7a40
explicit computation of sort arguments for code equations makes less assumption about sort arguments of underlying type class instances
 haftmann parents: 
60801diff
changeset | 59 | val algebra = Sign.classes_of thy; | 
| 
4b53042d7a40
explicit computation of sort arguments for code equations makes less assumption about sort arguments of underlying type class instances
 haftmann parents: 
60801diff
changeset | 60 | in | 
| 
4b53042d7a40
explicit computation of sort arguments for code equations makes less assumption about sort arguments of underlying type class instances
 haftmann parents: 
60801diff
changeset | 61 |     case try (Sorts.mg_domain algebra tyco) @{sort term_of} of
 | 
| 
4b53042d7a40
explicit computation of sort arguments for code equations makes less assumption about sort arguments of underlying type class instances
 haftmann parents: 
60801diff
changeset | 62 | NONE => thy | 
| 
4b53042d7a40
explicit computation of sort arguments for code equations makes less assumption about sort arguments of underlying type class instances
 haftmann parents: 
60801diff
changeset | 63 | | SOME sorts => f tyco (map2 (fn (v, sort) => fn sort' => | 
| 
4b53042d7a40
explicit computation of sort arguments for code equations makes less assumption about sort arguments of underlying type class instances
 haftmann parents: 
60801diff
changeset | 64 | (v, Sorts.inter_sort algebra (sort, sort'))) vs sorts) thy | 
| 
4b53042d7a40
explicit computation of sort arguments for code equations makes less assumption about sort arguments of underlying type class instances
 haftmann parents: 
60801diff
changeset | 65 | end; | 
| 39564 | 66 | |
| 67 | ||
| 68 | (* code equations for datatypes *) | |
| 69 | ||
| 40726 
16dcfedc4eb7
keep type variable arguments of datatype constructors in bookkeeping
 haftmann parents: 
39567diff
changeset | 70 | fun mk_term_of_eq thy ty (c, (_, tys)) = | 
| 39564 | 71 | let | 
| 72 | val t = list_comb (Const (c, tys ---> ty), | |
| 43329 
84472e198515
tuned signature: Name.invent and Name.invent_names;
 wenzelm parents: 
42402diff
changeset | 73 | map Free (Name.invent_names Name.context "a" tys)); | 
| 39564 | 74 | val (arg, rhs) = | 
| 59621 
291934bac95e
Thm.cterm_of and Thm.ctyp_of operate on local context;
 wenzelm parents: 
59617diff
changeset | 75 | apply2 (Thm.global_cterm_of thy o Logic.unvarify_types_global o Logic.varify_global) | 
| 45344 
e209da839ff4
added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
 wenzelm parents: 
43329diff
changeset | 76 | (t, | 
| 
e209da839ff4
added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
 wenzelm parents: 
43329diff
changeset | 77 | map_aterms (fn t as Free (_, ty) => HOLogic.mk_term_of ty t | t => t) | 
| 
e209da839ff4
added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
 wenzelm parents: 
43329diff
changeset | 78 | (HOLogic.reflect_term t)); | 
| 59621 
291934bac95e
Thm.cterm_of and Thm.ctyp_of operate on local context;
 wenzelm parents: 
59617diff
changeset | 79 | val cty = Thm.global_ctyp_of thy ty; | 
| 39564 | 80 | in | 
| 81 |     @{thm term_of_anything}
 | |
| 60801 | 82 | |> Thm.instantiate' [SOME cty] [SOME arg, SOME rhs] | 
| 39564 | 83 | |> Thm.varifyT_global | 
| 84 | end; | |
| 85 | ||
| 61667 
4b53042d7a40
explicit computation of sort arguments for code equations makes less assumption about sort arguments of underlying type class instances
 haftmann parents: 
60801diff
changeset | 86 | fun add_term_of_code tyco vs raw_cs thy = | 
| 39564 | 87 | let | 
| 88 | val ty = Type (tyco, map TFree vs); | |
| 40726 
16dcfedc4eb7
keep type variable arguments of datatype constructors in bookkeeping
 haftmann parents: 
39567diff
changeset | 89 | val cs = (map o apsnd o apsnd o map o map_atyps) | 
| 39564 | 90 | (fn TFree (v, _) => TFree (v, (the o AList.lookup (op =) vs) v)) raw_cs; | 
| 51685 
385ef6706252
more standard module name Axclass (according to file name);
 wenzelm parents: 
48272diff
changeset | 91 |     val const = Axclass.param_of_inst thy (@{const_name term_of}, tyco);
 | 
| 39565 
f4f87c6e2fad
full palette of dynamic/static value(_strict/exn)
 haftmann parents: 
39564diff
changeset | 92 | val eqs = map (mk_term_of_eq thy ty) cs; | 
| 39564 | 93 | in | 
| 94 | thy | |
| 95 | |> Code.del_eqns const | |
| 96 | |> fold Code.add_eqn eqs | |
| 97 | end; | |
| 98 | ||
| 61667 
4b53042d7a40
explicit computation of sort arguments for code equations makes less assumption about sort arguments of underlying type class instances
 haftmann parents: 
60801diff
changeset | 99 | fun ensure_term_of_code (tyco, (vs, cs)) = | 
| 
4b53042d7a40
explicit computation of sort arguments for code equations makes less assumption about sort arguments of underlying type class instances
 haftmann parents: 
60801diff
changeset | 100 | for_term_of_instance tyco vs (fn tyco => fn vs => add_term_of_code tyco vs cs); | 
| 39564 | 101 | |
| 102 | ||
| 103 | (* code equations for abstypes *) | |
| 104 | ||
| 39565 
f4f87c6e2fad
full palette of dynamic/static value(_strict/exn)
 haftmann parents: 
39564diff
changeset | 105 | fun mk_abs_term_of_eq thy ty abs ty_rep proj = | 
| 39564 | 106 | let | 
| 107 |     val arg = Var (("x", 0), ty);
 | |
| 108 |     val rhs = Abs ("y", @{typ term}, HOLogic.reflect_term (Const (abs, ty_rep --> ty) $ Bound 0)) $
 | |
| 109 | (HOLogic.mk_term_of ty_rep (Const (proj, ty --> ty_rep) $ arg)) | |
| 59621 
291934bac95e
Thm.cterm_of and Thm.ctyp_of operate on local context;
 wenzelm parents: 
59617diff
changeset | 110 | |> Thm.global_cterm_of thy; | 
| 
291934bac95e
Thm.cterm_of and Thm.ctyp_of operate on local context;
 wenzelm parents: 
59617diff
changeset | 111 | val cty = Thm.global_ctyp_of thy ty; | 
| 39564 | 112 | in | 
| 113 |     @{thm term_of_anything}
 | |
| 60801 | 114 | |> Thm.instantiate' [SOME cty] [SOME (Thm.global_cterm_of thy arg), SOME rhs] | 
| 39564 | 115 | |> Thm.varifyT_global | 
| 116 | end; | |
| 117 | ||
| 61667 
4b53042d7a40
explicit computation of sort arguments for code equations makes less assumption about sort arguments of underlying type class instances
 haftmann parents: 
60801diff
changeset | 118 | fun add_abs_term_of_code tyco vs abs raw_ty_rep proj thy = | 
| 39564 | 119 | let | 
| 120 | val ty = Type (tyco, map TFree vs); | |
| 121 | val ty_rep = map_atyps | |
| 122 | (fn TFree (v, _) => TFree (v, (the o AList.lookup (op =) vs) v)) raw_ty_rep; | |
| 51685 
385ef6706252
more standard module name Axclass (according to file name);
 wenzelm parents: 
48272diff
changeset | 123 |     val const = Axclass.param_of_inst thy (@{const_name term_of}, tyco);
 | 
| 39565 
f4f87c6e2fad
full palette of dynamic/static value(_strict/exn)
 haftmann parents: 
39564diff
changeset | 124 | val eq = mk_abs_term_of_eq thy ty abs ty_rep proj; | 
| 39564 | 125 | in | 
| 126 | thy | |
| 127 | |> Code.del_eqns const | |
| 128 | |> Code.add_eqn eq | |
| 129 | end; | |
| 130 | ||
| 61667 
4b53042d7a40
explicit computation of sort arguments for code equations makes less assumption about sort arguments of underlying type class instances
 haftmann parents: 
60801diff
changeset | 131 | fun ensure_abs_term_of_code (tyco, (vs, ((abs, (_, ty)), (proj, _)))) = | 
| 
4b53042d7a40
explicit computation of sort arguments for code equations makes less assumption about sort arguments of underlying type class instances
 haftmann parents: 
60801diff
changeset | 132 | for_term_of_instance tyco vs | 
| 
4b53042d7a40
explicit computation of sort arguments for code equations makes less assumption about sort arguments of underlying type class instances
 haftmann parents: 
60801diff
changeset | 133 | (fn tyco => fn vs => add_abs_term_of_code tyco vs abs ty proj); | 
| 39564 | 134 | |
| 135 | ||
| 56926 | 136 | (* setup *) | 
| 137 | ||
| 59323 | 138 | val _ = Theory.setup | 
| 56926 | 139 | (Code.datatype_interpretation ensure_term_of | 
| 140 | #> Code.abstype_interpretation ensure_term_of | |
| 141 | #> Code.datatype_interpretation ensure_term_of_code | |
| 59323 | 142 | #> Code.abstype_interpretation ensure_abs_term_of_code); | 
| 56926 | 143 | |
| 144 | ||
| 39564 | 145 | (** termifying syntax **) | 
| 146 | ||
| 147 | fun map_default f xs = | |
| 148 | let val ys = map f xs | |
| 149 | in if exists is_some ys | |
| 150 | then SOME (map2 the_default xs ys) | |
| 151 | else NONE | |
| 152 | end; | |
| 153 | ||
| 39565 
f4f87c6e2fad
full palette of dynamic/static value(_strict/exn)
 haftmann parents: 
39564diff
changeset | 154 | fun subst_termify_app (Const (@{const_name termify}, _), [t]) =
 | 
| 39564 | 155 | if not (Term.has_abs t) | 
| 156 | then if fold_aterms (fn Const _ => I | _ => K false) t true | |
| 157 | then SOME (HOLogic.reflect_term t) | |
| 51714 | 158 | else error "Cannot termify expression containing variable" | 
| 39564 | 159 | else error "Cannot termify expression containing abstraction" | 
| 160 | | subst_termify_app (t, ts) = case map_default subst_termify ts | |
| 161 | of SOME ts' => SOME (list_comb (t, ts')) | |
| 162 | | NONE => NONE | |
| 163 | and subst_termify (Abs (v, T, t)) = (case subst_termify t | |
| 164 | of SOME t' => SOME (Abs (v, T, t')) | |
| 165 | | NONE => NONE) | |
| 166 | | subst_termify t = subst_termify_app (strip_comb t) | |
| 167 | ||
| 56973 
62da80041afd
syntactic means to prevent accidental mixup of static and dynamic context
 haftmann parents: 
56926diff
changeset | 168 | fun check_termify _ ts = the_default ts (map_default subst_termify ts); | 
| 39564 | 169 | |
| 56926 | 170 | val _ = Context.>> (Syntax_Phases.term_check 0 "termify" check_termify); | 
| 171 | ||
| 39564 | 172 | |
| 173 | (** evaluation **) | |
| 174 | ||
| 41472 
f6ab14e61604
misc tuning and comments based on review of Theory_Data, Proof_Data, Generic_Data usage;
 wenzelm parents: 
41247diff
changeset | 175 | structure Evaluation = Proof_Data | 
| 
f6ab14e61604
misc tuning and comments based on review of Theory_Data, Proof_Data, Generic_Data usage;
 wenzelm parents: 
41247diff
changeset | 176 | ( | 
| 39564 | 177 | type T = unit -> term | 
| 59153 | 178 | val empty: T = fn () => raise Fail "Evaluation" | 
| 179 | fun init _ = empty | |
| 39564 | 180 | ); | 
| 181 | val put_term = Evaluation.put; | |
| 39565 
f4f87c6e2fad
full palette of dynamic/static value(_strict/exn)
 haftmann parents: 
39564diff
changeset | 182 | val cookie = (Evaluation.get, put_term, "Code_Evaluation.put_term"); | 
| 
f4f87c6e2fad
full palette of dynamic/static value(_strict/exn)
 haftmann parents: 
39564diff
changeset | 183 | |
| 
f4f87c6e2fad
full palette of dynamic/static value(_strict/exn)
 haftmann parents: 
39564diff
changeset | 184 | fun mk_term_of t = HOLogic.mk_term_of (fastype_of t) t; | 
| 
f4f87c6e2fad
full palette of dynamic/static value(_strict/exn)
 haftmann parents: 
39564diff
changeset | 185 | |
| 51685 
385ef6706252
more standard module name Axclass (according to file name);
 wenzelm parents: 
48272diff
changeset | 186 | fun term_of_const_for thy = Axclass.unoverload_const thy o dest_Const o HOLogic.term_of_const; | 
| 39565 
f4f87c6e2fad
full palette of dynamic/static value(_strict/exn)
 haftmann parents: 
39564diff
changeset | 187 | |
| 55757 | 188 | fun gen_dynamic_value dynamic_value ctxt t = | 
| 189 | dynamic_value cookie ctxt NONE I (mk_term_of t) []; | |
| 39565 
f4f87c6e2fad
full palette of dynamic/static value(_strict/exn)
 haftmann parents: 
39564diff
changeset | 190 | |
| 
f4f87c6e2fad
full palette of dynamic/static value(_strict/exn)
 haftmann parents: 
39564diff
changeset | 191 | val dynamic_value = gen_dynamic_value Code_Runtime.dynamic_value; | 
| 
f4f87c6e2fad
full palette of dynamic/static value(_strict/exn)
 haftmann parents: 
39564diff
changeset | 192 | val dynamic_value_strict = gen_dynamic_value Code_Runtime.dynamic_value_strict; | 
| 
f4f87c6e2fad
full palette of dynamic/static value(_strict/exn)
 haftmann parents: 
39564diff
changeset | 193 | val dynamic_value_exn = gen_dynamic_value Code_Runtime.dynamic_value_exn; | 
| 
f4f87c6e2fad
full palette of dynamic/static value(_strict/exn)
 haftmann parents: 
39564diff
changeset | 194 | |
| 56973 
62da80041afd
syntactic means to prevent accidental mixup of static and dynamic context
 haftmann parents: 
56926diff
changeset | 195 | fun gen_static_value static_value { ctxt, consts, Ts } =
 | 
| 55757 | 196 | let | 
| 56973 
62da80041afd
syntactic means to prevent accidental mixup of static and dynamic context
 haftmann parents: 
56926diff
changeset | 197 | val static_value' = static_value cookie | 
| 
62da80041afd
syntactic means to prevent accidental mixup of static and dynamic context
 haftmann parents: 
56926diff
changeset | 198 |       { ctxt = ctxt, target = NONE, lift_postproc = I, consts =
 | 
| 
62da80041afd
syntactic means to prevent accidental mixup of static and dynamic context
 haftmann parents: 
56926diff
changeset | 199 | union (op =) (map (term_of_const_for (Proof_Context.theory_of ctxt)) Ts) consts } | 
| 55757 | 200 | in fn ctxt' => fn t => static_value' ctxt' (mk_term_of t) end; | 
| 39565 
f4f87c6e2fad
full palette of dynamic/static value(_strict/exn)
 haftmann parents: 
39564diff
changeset | 201 | |
| 
f4f87c6e2fad
full palette of dynamic/static value(_strict/exn)
 haftmann parents: 
39564diff
changeset | 202 | val static_value = gen_static_value Code_Runtime.static_value; | 
| 
f4f87c6e2fad
full palette of dynamic/static value(_strict/exn)
 haftmann parents: 
39564diff
changeset | 203 | val static_value_strict = gen_static_value Code_Runtime.static_value_strict; | 
| 
f4f87c6e2fad
full palette of dynamic/static value(_strict/exn)
 haftmann parents: 
39564diff
changeset | 204 | val static_value_exn = gen_static_value Code_Runtime.static_value_exn; | 
| 
f4f87c6e2fad
full palette of dynamic/static value(_strict/exn)
 haftmann parents: 
39564diff
changeset | 205 | |
| 55757 | 206 | fun certify_eval ctxt value conv ct = | 
| 39567 
5ee997fbe5cc
dynamic_eval_conv static_eval_conv: certification of previously unreliably reconstructed evaluated term
 haftmann parents: 
39565diff
changeset | 207 | let | 
| 
5ee997fbe5cc
dynamic_eval_conv static_eval_conv: certification of previously unreliably reconstructed evaluated term
 haftmann parents: 
39565diff
changeset | 208 | val t = Thm.term_of ct; | 
| 
5ee997fbe5cc
dynamic_eval_conv static_eval_conv: certification of previously unreliably reconstructed evaluated term
 haftmann parents: 
39565diff
changeset | 209 | val T = fastype_of t; | 
| 59617 | 210 | val mk_eq = | 
| 59621 
291934bac95e
Thm.cterm_of and Thm.ctyp_of operate on local context;
 wenzelm parents: 
59617diff
changeset | 211 |       Thm.mk_binop (Thm.cterm_of ctxt (Const (@{const_name Pure.eq}, T --> T --> propT)));
 | 
| 55757 | 212 | in case value ctxt t | 
| 39567 
5ee997fbe5cc
dynamic_eval_conv static_eval_conv: certification of previously unreliably reconstructed evaluated term
 haftmann parents: 
39565diff
changeset | 213 | of NONE => Thm.reflexive ct | 
| 59621 
291934bac95e
Thm.cterm_of and Thm.ctyp_of operate on local context;
 wenzelm parents: 
59617diff
changeset | 214 |     | SOME t' => conv ctxt (mk_eq ct (Thm.cterm_of ctxt t')) RS @{thm eq_eq_TrueD}
 | 
| 39567 
5ee997fbe5cc
dynamic_eval_conv static_eval_conv: certification of previously unreliably reconstructed evaluated term
 haftmann parents: 
39565diff
changeset | 215 | handle THM _ => | 
| 55757 | 216 |           error ("Failed to certify evaluation result of " ^ Syntax.string_of_term ctxt t)
 | 
| 39567 
5ee997fbe5cc
dynamic_eval_conv static_eval_conv: certification of previously unreliably reconstructed evaluated term
 haftmann parents: 
39565diff
changeset | 217 | end; | 
| 
5ee997fbe5cc
dynamic_eval_conv static_eval_conv: certification of previously unreliably reconstructed evaluated term
 haftmann parents: 
39565diff
changeset | 218 | |
| 55757 | 219 | fun dynamic_conv ctxt = certify_eval ctxt dynamic_value | 
| 220 | Code_Runtime.dynamic_holds_conv; | |
| 39567 
5ee997fbe5cc
dynamic_eval_conv static_eval_conv: certification of previously unreliably reconstructed evaluated term
 haftmann parents: 
39565diff
changeset | 221 | |
| 56973 
62da80041afd
syntactic means to prevent accidental mixup of static and dynamic context
 haftmann parents: 
56926diff
changeset | 222 | fun static_conv { ctxt, consts, Ts }  =
 | 
| 39567 
5ee997fbe5cc
dynamic_eval_conv static_eval_conv: certification of previously unreliably reconstructed evaluated term
 haftmann parents: 
39565diff
changeset | 223 | let | 
| 56245 | 224 |     val eqs = @{const_name Pure.eq} :: @{const_name HOL.eq} ::
 | 
| 55757 | 225 | map (fn T => Axclass.unoverload_const (Proof_Context.theory_of ctxt) | 
| 56245 | 226 |         (@{const_name HOL.equal}, T)) Ts; (*assumes particular code equations for Pure.eq etc.*)
 | 
| 56973 
62da80041afd
syntactic means to prevent accidental mixup of static and dynamic context
 haftmann parents: 
56926diff
changeset | 227 |     val value = static_value { ctxt = ctxt, consts = consts, Ts = Ts };
 | 
| 
62da80041afd
syntactic means to prevent accidental mixup of static and dynamic context
 haftmann parents: 
56926diff
changeset | 228 |     val holds = Code_Runtime.static_holds_conv { ctxt = ctxt, consts = union (op =) eqs consts };
 | 
| 39567 
5ee997fbe5cc
dynamic_eval_conv static_eval_conv: certification of previously unreliably reconstructed evaluated term
 haftmann parents: 
39565diff
changeset | 229 | in | 
| 55757 | 230 | fn ctxt' => certify_eval ctxt' value holds | 
| 39567 
5ee997fbe5cc
dynamic_eval_conv static_eval_conv: certification of previously unreliably reconstructed evaluated term
 haftmann parents: 
39565diff
changeset | 231 | end; | 
| 
5ee997fbe5cc
dynamic_eval_conv static_eval_conv: certification of previously unreliably reconstructed evaluated term
 haftmann parents: 
39565diff
changeset | 232 | |
| 39565 
f4f87c6e2fad
full palette of dynamic/static value(_strict/exn)
 haftmann parents: 
39564diff
changeset | 233 | |
| 
f4f87c6e2fad
full palette of dynamic/static value(_strict/exn)
 haftmann parents: 
39564diff
changeset | 234 | (** diagnostic **) | 
| 39564 | 235 | |
| 236 | fun tracing s x = (Output.tracing s; x); | |
| 237 | ||
| 238 | end; |