src/Pure/Thy/export.ML
author wenzelm
Sat, 19 Oct 2019 11:33:36 +0200
changeset 70907 7e3f25a0cee4
parent 70499 f389019024ce
child 70991 f9f7c34b7dd4
permissions -rw-r--r--
proper protocol_message for bootstrap proofs;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
68090
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Thy/export.ML
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
     3
68102
813b5d0904c6 clarified signature;
wenzelm
parents: 68101
diff changeset
     4
Manage theory exports: compressed blobs.
68090
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
     5
*)
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
     6
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
     7
signature EXPORT =
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
     8
sig
70051
7a4dc1e60dc8 added command 'compile_generated_files';
wenzelm
parents: 70016
diff changeset
     9
  val report_export: theory -> Path.binding -> unit
70499
f389019024ce allow duplicate exports via strict = false;
wenzelm
parents: 70055
diff changeset
    10
  type params =
f389019024ce allow duplicate exports via strict = false;
wenzelm
parents: 70055
diff changeset
    11
    {theory: theory, binding: Path.binding, executable: bool, compress: bool, strict: bool}
69788
c175499a7537 added executable flag for exports;
wenzelm
parents: 69784
diff changeset
    12
  val export_params: params -> string list -> unit
70015
c8e08d8ffb93 clarified signature: more explicit type Path.binding;
wenzelm
parents: 70013
diff changeset
    13
  val export: theory -> Path.binding -> string list -> unit
c8e08d8ffb93 clarified signature: more explicit type Path.binding;
wenzelm
parents: 70013
diff changeset
    14
  val export_executable: theory -> Path.binding -> string list -> unit
c8e08d8ffb93 clarified signature: more explicit type Path.binding;
wenzelm
parents: 70013
diff changeset
    15
  val export_file: theory -> Path.binding -> Path.T -> unit
c8e08d8ffb93 clarified signature: more explicit type Path.binding;
wenzelm
parents: 70013
diff changeset
    16
  val export_executable_file: theory -> Path.binding -> Path.T -> unit
70009
435fb018e8ee "export_code ... file_prefix ..." is the preferred way to produce output within the logical file-system within the theory context, as well as session exports;
wenzelm
parents: 69788
diff changeset
    17
  val markup: theory -> Path.T -> Markup.T
435fb018e8ee "export_code ... file_prefix ..." is the preferred way to produce output within the logical file-system within the theory context, as well as session exports;
wenzelm
parents: 69788
diff changeset
    18
  val message: theory -> Path.T -> string
70907
7e3f25a0cee4 proper protocol_message for bootstrap proofs;
wenzelm
parents: 70499
diff changeset
    19
  val protocol_message: Properties.T -> string list -> unit
68090
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    20
end;
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    21
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    22
structure Export: EXPORT =
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    23
struct
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    24
69648
97ddaec3e2ae support hyperlink to theory exports;
wenzelm
parents: 69627
diff changeset
    25
(* export *)
97ddaec3e2ae support hyperlink to theory exports;
wenzelm
parents: 69627
diff changeset
    26
70051
7a4dc1e60dc8 added command 'compile_generated_files';
wenzelm
parents: 70016
diff changeset
    27
fun report_export thy binding =
7a4dc1e60dc8 added command 'compile_generated_files';
wenzelm
parents: 70016
diff changeset
    28
  let
7a4dc1e60dc8 added command 'compile_generated_files';
wenzelm
parents: 70016
diff changeset
    29
    val theory_name = Context.theory_long_name thy;
7a4dc1e60dc8 added command 'compile_generated_files';
wenzelm
parents: 70016
diff changeset
    30
    val (path, pos) = Path.dest_binding binding;
7a4dc1e60dc8 added command 'compile_generated_files';
wenzelm
parents: 70016
diff changeset
    31
    val markup = Markup.export_path (Path.implode (Path.append (Path.basic theory_name) path));
7a4dc1e60dc8 added command 'compile_generated_files';
wenzelm
parents: 70016
diff changeset
    32
  in Context_Position.report_generic (Context.Theory thy) pos markup end;
7a4dc1e60dc8 added command 'compile_generated_files';
wenzelm
parents: 70016
diff changeset
    33
70499
f389019024ce allow duplicate exports via strict = false;
wenzelm
parents: 70055
diff changeset
    34
type params =
f389019024ce allow duplicate exports via strict = false;
wenzelm
parents: 70055
diff changeset
    35
  {theory: theory, binding: Path.binding, executable: bool, compress: bool, strict: bool};
68105
577072a0ceed more checks;
wenzelm
parents: 68102
diff changeset
    36
70499
f389019024ce allow duplicate exports via strict = false;
wenzelm
parents: 70055
diff changeset
    37
fun export_params ({theory = thy, binding, executable, compress, strict}: params) blob =
70051
7a4dc1e60dc8 added command 'compile_generated_files';
wenzelm
parents: 70016
diff changeset
    38
 (report_export thy binding;
7a4dc1e60dc8 added command 'compile_generated_files';
wenzelm
parents: 70016
diff changeset
    39
  (Output.try_protocol_message o Markup.export)
7a4dc1e60dc8 added command 'compile_generated_files';
wenzelm
parents: 70016
diff changeset
    40
   {id = Position.get_id (Position.thread_data ()),
7a4dc1e60dc8 added command 'compile_generated_files';
wenzelm
parents: 70016
diff changeset
    41
    serial = serial (),
7a4dc1e60dc8 added command 'compile_generated_files';
wenzelm
parents: 70016
diff changeset
    42
    theory_name = Context.theory_long_name thy,
70055
36fb663145e5 type Path.binding may be empty: check later via proper_binding;
wenzelm
parents: 70051
diff changeset
    43
    name = Path.implode_binding (tap Path.proper_binding binding),
70051
7a4dc1e60dc8 added command 'compile_generated_files';
wenzelm
parents: 70016
diff changeset
    44
    executable = executable,
70499
f389019024ce allow duplicate exports via strict = false;
wenzelm
parents: 70055
diff changeset
    45
    compress = compress,
f389019024ce allow duplicate exports via strict = false;
wenzelm
parents: 70055
diff changeset
    46
    strict = strict} blob);
68090
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    47
70015
c8e08d8ffb93 clarified signature: more explicit type Path.binding;
wenzelm
parents: 70013
diff changeset
    48
fun export thy binding blob =
70499
f389019024ce allow duplicate exports via strict = false;
wenzelm
parents: 70055
diff changeset
    49
  export_params
f389019024ce allow duplicate exports via strict = false;
wenzelm
parents: 70055
diff changeset
    50
    {theory = thy, binding = binding, executable = false, compress = true, strict = true} blob;
69788
c175499a7537 added executable flag for exports;
wenzelm
parents: 69784
diff changeset
    51
70015
c8e08d8ffb93 clarified signature: more explicit type Path.binding;
wenzelm
parents: 70013
diff changeset
    52
fun export_executable thy binding blob =
70499
f389019024ce allow duplicate exports via strict = false;
wenzelm
parents: 70055
diff changeset
    53
  export_params
f389019024ce allow duplicate exports via strict = false;
wenzelm
parents: 70055
diff changeset
    54
    {theory = thy, binding = binding, executable = true, compress = true, strict = true} blob;
70013
6de8b7a5cd44 tuned signature -- more operations;
wenzelm
parents: 70011
diff changeset
    55
70015
c8e08d8ffb93 clarified signature: more explicit type Path.binding;
wenzelm
parents: 70013
diff changeset
    56
fun export_file thy binding file = export thy binding [File.read file];
c8e08d8ffb93 clarified signature: more explicit type Path.binding;
wenzelm
parents: 70013
diff changeset
    57
fun export_executable_file thy binding file = export_executable thy binding [File.read file];
68090
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    58
69648
97ddaec3e2ae support hyperlink to theory exports;
wenzelm
parents: 69627
diff changeset
    59
97ddaec3e2ae support hyperlink to theory exports;
wenzelm
parents: 69627
diff changeset
    60
(* information message *)
97ddaec3e2ae support hyperlink to theory exports;
wenzelm
parents: 69627
diff changeset
    61
70009
435fb018e8ee "export_code ... file_prefix ..." is the preferred way to produce output within the logical file-system within the theory context, as well as session exports;
wenzelm
parents: 69788
diff changeset
    62
fun markup thy path =
435fb018e8ee "export_code ... file_prefix ..." is the preferred way to produce output within the logical file-system within the theory context, as well as session exports;
wenzelm
parents: 69788
diff changeset
    63
  let
435fb018e8ee "export_code ... file_prefix ..." is the preferred way to produce output within the logical file-system within the theory context, as well as session exports;
wenzelm
parents: 69788
diff changeset
    64
    val thy_path = Path.append (Path.basic (Context.theory_long_name thy)) path;
435fb018e8ee "export_code ... file_prefix ..." is the preferred way to produce output within the logical file-system within the theory context, as well as session exports;
wenzelm
parents: 69788
diff changeset
    65
    val name = (Markup.nameN, Path.implode thy_path);
69650
c95edf19133b clarified message;
wenzelm
parents: 69648
diff changeset
    66
  in Active.make_markup Markup.theory_exportsN {implicit = false, properties = [name]} end;
69648
97ddaec3e2ae support hyperlink to theory exports;
wenzelm
parents: 69627
diff changeset
    67
70009
435fb018e8ee "export_code ... file_prefix ..." is the preferred way to produce output within the logical file-system within the theory context, as well as session exports;
wenzelm
parents: 69788
diff changeset
    68
fun message thy path =
435fb018e8ee "export_code ... file_prefix ..." is the preferred way to produce output within the logical file-system within the theory context, as well as session exports;
wenzelm
parents: 69788
diff changeset
    69
  "See " ^ Markup.markup (markup thy path) "theory exports";
69648
97ddaec3e2ae support hyperlink to theory exports;
wenzelm
parents: 69627
diff changeset
    70
70907
7e3f25a0cee4 proper protocol_message for bootstrap proofs;
wenzelm
parents: 70499
diff changeset
    71
7e3f25a0cee4 proper protocol_message for bootstrap proofs;
wenzelm
parents: 70499
diff changeset
    72
(* protocol message (bootstrap) *)
7e3f25a0cee4 proper protocol_message for bootstrap proofs;
wenzelm
parents: 70499
diff changeset
    73
7e3f25a0cee4 proper protocol_message for bootstrap proofs;
wenzelm
parents: 70499
diff changeset
    74
fun protocol_message props output =
7e3f25a0cee4 proper protocol_message for bootstrap proofs;
wenzelm
parents: 70499
diff changeset
    75
  (case props of
7e3f25a0cee4 proper protocol_message for bootstrap proofs;
wenzelm
parents: 70499
diff changeset
    76
    function :: args =>
7e3f25a0cee4 proper protocol_message for bootstrap proofs;
wenzelm
parents: 70499
diff changeset
    77
      if function = (Markup.functionN, Markup.exportN) andalso
7e3f25a0cee4 proper protocol_message for bootstrap proofs;
wenzelm
parents: 70499
diff changeset
    78
        not (null args) andalso #1 (hd args) = Markup.idN
7e3f25a0cee4 proper protocol_message for bootstrap proofs;
wenzelm
parents: 70499
diff changeset
    79
      then
7e3f25a0cee4 proper protocol_message for bootstrap proofs;
wenzelm
parents: 70499
diff changeset
    80
        let
7e3f25a0cee4 proper protocol_message for bootstrap proofs;
wenzelm
parents: 70499
diff changeset
    81
          val path = Path.expand (Path.explode ("$ISABELLE_EXPORT_TMP/export" ^ serial_string ()));
7e3f25a0cee4 proper protocol_message for bootstrap proofs;
wenzelm
parents: 70499
diff changeset
    82
          val _ = File.write_list path output;
7e3f25a0cee4 proper protocol_message for bootstrap proofs;
wenzelm
parents: 70499
diff changeset
    83
        in Protocol_Message.inline (#2 function) (tl args @ [(Markup.fileN, Path.implode path)]) end
7e3f25a0cee4 proper protocol_message for bootstrap proofs;
wenzelm
parents: 70499
diff changeset
    84
      else raise Output.Protocol_Message props
7e3f25a0cee4 proper protocol_message for bootstrap proofs;
wenzelm
parents: 70499
diff changeset
    85
  | [] => raise Output.Protocol_Message props);
7e3f25a0cee4 proper protocol_message for bootstrap proofs;
wenzelm
parents: 70499
diff changeset
    86
7e3f25a0cee4 proper protocol_message for bootstrap proofs;
wenzelm
parents: 70499
diff changeset
    87
val _ =
7e3f25a0cee4 proper protocol_message for bootstrap proofs;
wenzelm
parents: 70499
diff changeset
    88
  if Thread_Data.is_virtual then ()
7e3f25a0cee4 proper protocol_message for bootstrap proofs;
wenzelm
parents: 70499
diff changeset
    89
  else Private_Output.protocol_message_fn := protocol_message;
7e3f25a0cee4 proper protocol_message for bootstrap proofs;
wenzelm
parents: 70499
diff changeset
    90
68090
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    91
end;