src/Pure/theory.ML
changeset 3878 0258594baaa9
parent 3865 0035d1f97096
child 3885 dccac762b0be
equal deleted inserted replaced
3877:83c5310aaaab 3878:0258594baaa9
    26   val pure_thy          : theory
    26   val pure_thy          : theory
    27   val cpure_thy         : theory
    27   val cpure_thy         : theory
    28   val cert_axm          : Sign.sg -> string * term -> string * term
    28   val cert_axm          : Sign.sg -> string * term -> string * term
    29   val read_axm          : Sign.sg -> string * string -> string * term
    29   val read_axm          : Sign.sg -> string * string -> string * term
    30   val inferT_axm        : Sign.sg -> string * term -> string * term
    30   val inferT_axm        : Sign.sg -> string * term -> string * term
    31   val merge_theories    : theory * theory -> theory
       
    32 end
    31 end
    33 
    32 
    34 signature THEORY =
    33 signature THEORY =
    35 sig
    34 sig
    36   include BASIC_THEORY
    35   include BASIC_THEORY
    73   val add_defs		: (xstring * string) list -> theory -> theory
    72   val add_defs		: (xstring * string) list -> theory -> theory
    74   val add_defs_i	: (xstring * term) list -> theory -> theory
    73   val add_defs_i	: (xstring * term) list -> theory -> theory
    75   val add_path		: string -> theory -> theory
    74   val add_path		: string -> theory -> theory
    76   val add_space		: string * string list -> theory -> theory
    75   val add_space		: string * string list -> theory -> theory
    77   val add_name		: string -> theory -> theory
    76   val add_name		: string -> theory -> theory
    78   val init_data		: string * exn * (exn * exn -> exn) * (string -> exn -> Pretty.T)
    77   val init_data		: string * exn * (exn -> exn) * (exn * exn -> exn) *
    79     -> theory -> theory
    78     (string -> exn -> unit) -> theory -> theory
    80   val get_data		: theory -> string -> exn
    79   val get_data		: theory -> string -> exn
    81   val put_data		: string * exn -> theory -> theory
    80   val put_data		: string * exn -> theory -> theory
    82   val merge_thy_list    : bool -> theory list -> theory
    81   val merge_list	: theory list -> theory
    83 end;
    82 end;
    84 
    83 
    85 
    84 
    86 structure Theory: THEORY =
    85 structure Theory: THEORY =
    87 struct
    86 struct
   116 val eq_thy = Sign.eq_sg o pairself sign_of;
   115 val eq_thy = Sign.eq_sg o pairself sign_of;
   117 
   116 
   118 
   117 
   119 (* the Pure theories *)
   118 (* the Pure theories *)
   120 
   119 
   121 fun make_thy sign parents =
   120 fun make_thy sign axms oras parents =
   122   Theory {sign = sign, new_axioms = Symtab.null,
   121   Theory {sign = sign, new_axioms = axms, oracles = oras, parents = parents};
   123     oracles = Symtab.null, parents = parents};
   122 
   124 
   123 val proto_pure_thy = make_thy Sign.proto_pure Symtab.null Symtab.null [];
   125 val proto_pure_thy = make_thy Sign.proto_pure [];
   124 val pure_thy = make_thy Sign.pure Symtab.null Symtab.null [proto_pure_thy];
   126 val pure_thy = make_thy Sign.pure [proto_pure_thy];
   125 val cpure_thy = make_thy Sign.cpure Symtab.null Symtab.null [proto_pure_thy];
   127 val cpure_thy = make_thy Sign.cpure [proto_pure_thy];
       
   128 
   126 
   129 
   127 
   130 
   128 
   131 (** extend theory **)
   129 (** extend theory **)
   132 
   130 
   154     val oracles' =
   152     val oracles' =
   155       Symtab.extend_new (oracles, new_oras)
   153       Symtab.extend_new (oracles, new_oras)
   156         handle Symtab.DUPS names => err_dup_oras names;
   154         handle Symtab.DUPS names => err_dup_oras names;
   157     val parents' = if draft then parents else [thy];
   155     val parents' = if draft then parents else [thy];
   158   in
   156   in
   159     Theory {sign = sign', new_axioms = new_axioms',
   157     make_thy sign' new_axioms' oracles' parents'
   160       oracles = oracles', parents = parents'}
       
   161   end;
   158   end;
   162 
   159 
   163 
   160 
   164 (* extend signature of a theory *)
   161 (* extend signature of a theory *)
   165 
   162 
   377 
   374 
   378 val add_defs_i = ext_defns cert_axm;
   375 val add_defs_i = ext_defns cert_axm;
   379 val add_defs = ext_defns read_axm;
   376 val add_defs = ext_defns read_axm;
   380 
   377 
   381 
   378 
       
   379 
   382 (** additional theory data **)
   380 (** additional theory data **)
   383 
   381 
   384 val init_data = ext_sg Sign.init_data;
   382 val init_data = ext_sg Sign.init_data;
   385 val get_data = Sign.get_data o sign_of;
   383 val get_data = Sign.get_data o sign_of;
   386 val put_data = ext_sg Sign.put_data;
   384 val put_data = ext_sg Sign.put_data;
   387 
   385 
   388 
   386 
   389 
   387 
   390 (** merge theories **)
   388 (** merge theories **)
   391 
   389 
   392 fun merge_thy_list mk_draft thys =
   390 (*merge list of theories from left to right, preparing extend*)
       
   391 fun merge_list thys =
   393   let
   392   let
   394     fun is_union thy = forall (fn t => subthy (t, thy)) thys;
   393     fun is_union thy = forall (fn t => subthy (t, thy)) thys;
   395     val is_draft = Sign.is_draft o sign_of;
   394     val is_draft = Sign.is_draft o sign_of;
   396 
   395 
   397     fun add_sign (sg, Theory {sign, ...}) =
   396     fun add_sign (sg, Theory {sign, ...}) =
   398       Sign.merge (sg, sign) handle TERM (msg, _) => error msg;
   397       Sign.nontriv_merge (sg, sign) handle TERM (msg, _) => error msg;
   399 
   398 
   400     fun oracles_of (Theory {oracles, ...}) = Symtab.dest oracles;
   399     fun oracles_of (Theory {oracles, ...}) = Symtab.dest oracles;
   401     fun eq_ora ((_, (_, s1: stamp)), (_, (_, s2))) = s1 = s2;
   400     fun eq_ora ((_, (_, s1: stamp)), (_, (_, s2))) = s1 = s2;
   402     val all_oracles =
   401   in
   403       Symtab.make (gen_distinct eq_ora (flat (map oracles_of thys)))
   402     if exists is_draft thys then
   404         handle Symtab.DUPS names => err_dup_oras names;
   403       raise THEORY ("Illegal merge of draft theories", thys)
   405   in
   404     else
   406     (case (find_first is_union thys, exists is_draft thys) of
   405       (case find_first is_union thys of
   407       (Some thy, _) => thy
   406         Some (Theory {sign, oracles, new_axioms = _, parents = _}) =>
   408     | (None, true) => raise THEORY ("Illegal merge of draft theories", thys)
   407           make_thy (Sign.prep_ext sign) Symtab.null oracles thys
   409     | (None, false) => Theory {
   408       | None =>
   410         sign =
   409           make_thy
   411           (if mk_draft then Sign.make_draft else I)
   410             (Sign.prep_ext (foldl add_sign (Sign.proto_pure, thys)))
   412           (foldl add_sign (Sign.proto_pure, thys)),
   411             Symtab.null
   413         new_axioms = Symtab.null,
   412             (Symtab.make (gen_distinct eq_ora (flat (map oracles_of thys)))
   414         oracles = all_oracles,
   413               handle Symtab.DUPS names => err_dup_oras names)
   415         parents = thys})
   414             thys)
   416   end;
   415   end;
   417 
       
   418 fun merge_theories (thy1, thy2) = merge_thy_list false [thy1, thy2];
       
   419 
   416 
   420 
   417 
   421 end;
   418 end;
   422 
   419 
   423 structure BasicTheory: BASIC_THEORY = Theory;
   420 structure BasicTheory: BASIC_THEORY = Theory;