src/Tools/code/code_package.ML
changeset 26336 a0e2b706ce73
parent 26285 3905e52a1a0e
child 26604 3f757f8acf44
equal deleted inserted replaced
26335:961bbcc9d85b 26336:a0e2b706ce73
   185         val vars = Term.add_frees t [];
   185         val vars = Term.add_frees t [];
   186         val tfrees2 = fold (Term.add_tfreesT o snd) vars [];
   186         val tfrees2 = fold (Term.add_tfreesT o snd) vars [];
   187         val tfrees' = subtract (op =) tfrees2 tfrees1 |> map TFree;
   187         val tfrees' = subtract (op =) tfrees2 tfrees1 |> map TFree;
   188         val ty = map Term.itselfT tfrees' @ map snd vars ---> ty_judg;
   188         val ty = map Term.itselfT tfrees' @ map snd vars ---> ty_judg;
   189         val tfree_vars = map Logic.mk_type tfrees';
   189         val tfree_vars = map Logic.mk_type tfrees';
   190         val c = PureThy.string_of_thmref thmref
   190         val c = Facts.string_of_ref thmref
   191           |> NameSpace.explode
   191           |> NameSpace.explode
   192           |> (fn [x] => [x] | (x::xs) => xs)
   192           |> (fn [x] => [x] | (x::xs) => xs)
   193           |> space_implode "_"
   193           |> space_implode "_"
   194         val propdef = (((c, ty), tfree_vars @ map Free vars), t);
   194         val propdef = (((c, ty), tfree_vars @ map Free vars), t);
   195       in if c = "" then NONE else SOME (thmref, propdef) end;
   195       in if c = "" then NONE else SOME (thmref, propdef) end;
   196   in
   196   in
   197     Facts.dest (PureThy.all_facts_of thy)
   197     Facts.dest (PureThy.all_facts_of thy)
   198     |> maps PureThy.selections
   198     |> maps Facts.selections
   199     |> map_filter select
   199     |> map_filter select
   200     |> map_filter mk_codeprop
   200     |> map_filter mk_codeprop
   201   end;
   201   end;
   202 
   202 
   203 fun add_codeprops all_cs sel_cs thy =
   203 fun add_codeprops all_cs sel_cs thy =
   204   let
   204   let
   205     val codeprops = mk_codeprops thy all_cs sel_cs;
   205     val codeprops = mk_codeprops thy all_cs sel_cs;
   206     fun lift_name_yield f x = (Name.context, x) |> f ||> snd;
   206     fun lift_name_yield f x = (Name.context, x) |> f ||> snd;
   207     fun add (thmref, (((raw_c, ty), ts), t)) (names, thy) =
   207     fun add (thmref, (((raw_c, ty), ts), t)) (names, thy) =
   208       let
   208       let
   209         val _ = warning ("Adding theorem " ^ quote (PureThy.string_of_thmref thmref)
   209         val _ = warning ("Adding theorem " ^ quote (Facts.string_of_ref thmref)
   210           ^ " as code property " ^ quote raw_c);
   210           ^ " as code property " ^ quote raw_c);
   211         val ([raw_c'], names') = Name.variants [raw_c] names;
   211         val ([raw_c'], names') = Name.variants [raw_c] names;
   212         val (const as Const (c, _), thy') = thy |> Sign.declare_const [] (raw_c', ty, NoSyn);
   212         val (const as Const (c, _), thy') = thy |> Sign.declare_const [] (raw_c', ty, NoSyn);
   213         val eq = Logic.mk_equals (list_comb (const, ts), t);
   213         val eq = Logic.mk_equals (list_comb (const, ts), t);
   214         val ([def], thy'') = thy' |> PureThy.add_defs_i false [((Thm.def_name raw_c', eq), [])];
   214         val ([def], thy'') = thy' |> PureThy.add_defs_i false [((Thm.def_name raw_c', eq), [])];