Generated source files for other languages: with antiquotations, without Isabelle symbols.
*)
signature GENERATED_FILES = sig val add_files: Path.binding * Bytes.T -> theory -> theory type file = {path: Path.T, pos: Position.T, content: Bytes.T} val file_binding: file -> Path.binding val file_markup: file -> Markup.T val print_file: file -> string val report_file: Proof.context -> Position.T -> file -> unit val get_files: theory -> file list val get_file: theory -> Path.binding -> file val get_files_in: Path.binding list * theory -> (file * Position.T) list val check_files_in: Proof.context ->
(string * Position.T) list * (string * Position.T) option -> Path.binding list * theory val write_file: Path.T -> file -> unit val export_file: theory -> file -> unit type file_type =
{name: string, ext: string, make_comment: string -> string, make_string: string -> string} val file_type:
binding -> {ext: string, make_comment: string -> string, make_string: string -> string} ->
theory -> theory val antiquotation: binding -> 'a Token.context_parser ->
({context: Proof.context, source: Token.src, file_type: file_type, argument: 'a} -> string) ->
theory -> theory val set_string: string -> Proof.context -> Proof.context val generate_file: Path.binding * Input.source -> Proof.context -> local_theory val generate_file_cmd: (string * Position.T) * Input.source -> local_theory -> local_theory val export_generated_files: Proof.context -> (Path.binding list * theory) list -> unit val export_generated_files_cmd: Proof.context ->
((string * Position.T) list * (string * Position.T) option) list -> unit val check_external_files: Proof.context ->
Input.source list * Input.source -> Path.T list * Path.T val get_external_files: Path.T -> Path.T list * Path.T -> unit val scala_build_generated_files: Proof.context -> (Path.binding list * theory) list ->
(Path.T list * Path.T) list -> unit val scala_build_generated_files_cmd: Proof.context ->
((string * Position.T) list * (string * Position.T) option) list ->
(Input.source list * Input.source) list -> unit val with_compile_dir: (Path.T -> unit) -> unit val compile_generated_files: Proof.context ->
(Path.binding list * theory) list ->
(Path.T list * Path.T) list ->
(Path.binding list * booloption) list ->
Path.binding -> Input.source -> unit val compile_generated_files_cmd: Proof.context ->
((string * Position.T) list * (string * Position.T) option) list ->
(Input.source list * Input.source) list ->
((string * Position.T) list * booloption) list -> string * Position.T -> Input.source -> unit val execute: Path.T -> Input.source -> string -> string end;
fun check_files_in ctxt (files, opt_thy) = let val thy =
(case opt_thy of
SOME name => Theory.check {long = false} ctxt name
| NONE => Proof_Context.theory_of ctxt); in (map Path.explode_binding files, thy) end;
fun write_file dir (file: file) = let val path = Path.expand (dir + #path file); val _ = Isabelle_System.make_directory (Path.dir path); val content = #content file; val write_content =
(casetry Bytes.read path of
SOME old_content => not (Bytes.eq (content, old_content))
| NONE => true) inif write_content then Bytes.write path content else () end;
val _ = Context_Position.reports ctxt (Antiquote.antiq_reports input);
fun expand antiq =
(case antiq of
Antiquote.Text s => s
| Antiquote.Control {name, body, ...} => let val src = Token.make_src name (if null body then [] else [Token.read_cartouche body]); val (src', ant) = Token.check_src ctxt get_antiquotations src; in ant src' ctxt file_type end
| Antiquote.Antiq antiq => error ("Bad antiquotation " ^ Position.here (#1 (#range antiq)))); in implode (map expand input) end;
(** Isar commands **)
(* generate_file *)
fun generate_file (binding, source) lthy = let val thy = Proof_Context.theory_of lthy;
val compile_dir = Config.declare_string ("compile_dir", \<^here>) (K "");
fun with_compile_dir body : unit =
body (Path.explode (Config.get (Context.the_local_context ()) compile_dir));
fun compile_generated_files ctxt args external export export_prefix source =
Isabelle_System.with_tmp_dir "compile" (fn dir => let val thy = Proof_Context.theory_of ctxt;
val files = maps get_files_in args; val _ = List.app (fn (file, pos) => report_file ctxt pos file) files; val _ = List.app (write_file dir o #1) files; val _ = List.app (get_external_files dir) external; val _ =
ML_Context.eval_in (SOME (Config.put compile_dir (Path.implode dir) ctxt))
ML_Compiler.flags (Input.pos_of source)
(ML_Lex.read "Generated_Files.with_compile_dir (" @
ML_Lex.read_source source @ ML_Lex.read ")"); val _ =
export |> List.app (fn (bindings, executable) =>
bindings |> List.app (fn binding0 => let val binding = binding0
|> Path.map_binding (executable = SOME true ? Path.platform_exe); val (path, pos) = Path.dest_binding binding; val content =
(casetry Bytes.read (dir + path) of
SOME bytes => Bytes.contents_blob bytes
| NONE => error ("Missing result file " ^ Path.print path ^ Position.here pos)); val _ =
Export.report (Context.Theory thy) (Context.theory_long_name thy) export_prefix; val binding' =
Path.map_binding (Path.append (Path.path_of_binding export_prefix)) binding; in
(if is_some executable then Export.export_executable else Export.export)
thy binding' content end)); val _ = if null export then () else writeln (Export.message thy (Path.path_of_binding export_prefix)); in () end);
fun compile_generated_files_cmd ctxt args external export export_prefix source =
compile_generated_files ctxt
(map (check_files_in ctxt) args)
(map (check_external_files ctxt) external)
((map o apfst o map) Path.explode_binding export)
(Path.explode_binding export_prefix)
source;
(* execute compiler -- auxiliary *)
fun execute dir title compile =
Isabelle_System.bash_process (Bash.script compile |> Bash.cwd dir)
|> Process_Result.check
|> Process_Result.out handle ERROR msg => letval (s, pos) = Input.source_content title in error (s ^ " failed" ^ Position.here pos ^ ":\n" ^ msg) end;
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.17Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.