src/HOL/Tools/code_evaluation.ML
changeset 51685 385ef6706252
parent 48272 db75b4005d9a
child 51714 88f7f38d5cb9
equal deleted inserted replaced
51671:0d142a78fb7c 51685:385ef6706252
    76     val vs = map (fn (v, sort) =>
    76     val vs = map (fn (v, sort) =>
    77       (v, curry (Sorts.inter_sort algebra) @{sort typerep} sort)) raw_vs;
    77       (v, curry (Sorts.inter_sort algebra) @{sort typerep} sort)) raw_vs;
    78     val ty = Type (tyco, map TFree vs);
    78     val ty = Type (tyco, map TFree vs);
    79     val cs = (map o apsnd o apsnd o map o map_atyps)
    79     val cs = (map o apsnd o apsnd o map o map_atyps)
    80       (fn TFree (v, _) => TFree (v, (the o AList.lookup (op =) vs) v)) raw_cs;
    80       (fn TFree (v, _) => TFree (v, (the o AList.lookup (op =) vs) v)) raw_cs;
    81     val const = AxClass.param_of_inst thy (@{const_name term_of}, tyco);
    81     val const = Axclass.param_of_inst thy (@{const_name term_of}, tyco);
    82     val eqs = map (mk_term_of_eq thy ty) cs;
    82     val eqs = map (mk_term_of_eq thy ty) cs;
    83  in
    83  in
    84     thy
    84     thy
    85     |> Code.del_eqns const
    85     |> Code.del_eqns const
    86     |> fold Code.add_eqn eqs
    86     |> fold Code.add_eqn eqs
   113     val vs = map (fn (v, sort) =>
   113     val vs = map (fn (v, sort) =>
   114       (v, curry (Sorts.inter_sort algebra) @{sort typerep} sort)) raw_vs;
   114       (v, curry (Sorts.inter_sort algebra) @{sort typerep} sort)) raw_vs;
   115     val ty = Type (tyco, map TFree vs);
   115     val ty = Type (tyco, map TFree vs);
   116     val ty_rep = map_atyps
   116     val ty_rep = map_atyps
   117       (fn TFree (v, _) => TFree (v, (the o AList.lookup (op =) vs) v)) raw_ty_rep;
   117       (fn TFree (v, _) => TFree (v, (the o AList.lookup (op =) vs) v)) raw_ty_rep;
   118     val const = AxClass.param_of_inst thy (@{const_name term_of}, tyco);
   118     val const = Axclass.param_of_inst thy (@{const_name term_of}, tyco);
   119     val eq = mk_abs_term_of_eq thy ty abs ty_rep proj;
   119     val eq = mk_abs_term_of_eq thy ty abs ty_rep proj;
   120  in
   120  in
   121     thy
   121     thy
   122     |> Code.del_eqns const
   122     |> Code.del_eqns const
   123     |> Code.add_eqn eq
   123     |> Code.add_eqn eq
   167 val put_term = Evaluation.put;
   167 val put_term = Evaluation.put;
   168 val cookie = (Evaluation.get, put_term, "Code_Evaluation.put_term");
   168 val cookie = (Evaluation.get, put_term, "Code_Evaluation.put_term");
   169 
   169 
   170 fun mk_term_of t = HOLogic.mk_term_of (fastype_of t) t;
   170 fun mk_term_of t = HOLogic.mk_term_of (fastype_of t) t;
   171 
   171 
   172 fun term_of_const_for thy = AxClass.unoverload_const thy o dest_Const o HOLogic.term_of_const;
   172 fun term_of_const_for thy = Axclass.unoverload_const thy o dest_Const o HOLogic.term_of_const;
   173 
   173 
   174 fun gen_dynamic_value dynamic_value thy t =
   174 fun gen_dynamic_value dynamic_value thy t =
   175   dynamic_value cookie thy NONE I (mk_term_of t) [];
   175   dynamic_value cookie thy NONE I (mk_term_of t) [];
   176 
   176 
   177 val dynamic_value = gen_dynamic_value Code_Runtime.dynamic_value;
   177 val dynamic_value = gen_dynamic_value Code_Runtime.dynamic_value;
   202   (Code_Runtime.dynamic_holds_conv thy);
   202   (Code_Runtime.dynamic_holds_conv thy);
   203 
   203 
   204 fun static_conv thy consts Ts =
   204 fun static_conv thy consts Ts =
   205   let
   205   let
   206     val eqs = "==" :: @{const_name HOL.eq} ::
   206     val eqs = "==" :: @{const_name HOL.eq} ::
   207       map (fn T => AxClass.unoverload_const thy (@{const_name HOL.equal}, T)) Ts;
   207       map (fn T => Axclass.unoverload_const thy (@{const_name HOL.equal}, T)) Ts;
   208         (*assumes particular code equations for "==" etc.*)
   208         (*assumes particular code equations for "==" etc.*)
   209   in
   209   in
   210     certify_eval thy (static_value thy consts Ts)
   210     certify_eval thy (static_value thy consts Ts)
   211       (Code_Runtime.static_holds_conv thy (union (op =) eqs consts))
   211       (Code_Runtime.static_holds_conv thy (union (op =) eqs consts))
   212   end;
   212   end;