src/Tools/Code/code_target.ML
changeset 38914 0a49a34e5d37
parent 38913 d1d4d808be26
child 38916 c0b857a04758
equal deleted inserted replaced
38913:d1d4d808be26 38914:0a49a34e5d37
    29     -> Code_Thingol.naming -> Code_Thingol.program -> string list -> serialization
    29     -> Code_Thingol.naming -> Code_Thingol.program -> string list -> serialization
    30   val serialize_custom: theory -> string * serializer -> string option
    30   val serialize_custom: theory -> string * serializer -> string option
    31     -> Code_Thingol.naming -> Code_Thingol.program -> string list
    31     -> Code_Thingol.naming -> Code_Thingol.program -> string list
    32     -> string * string option list
    32     -> string * string option list
    33   val the_literals: theory -> string -> literals
    33   val the_literals: theory -> string -> literals
    34   val export: serialization -> unit
    34   val file: Path.T option -> serialization -> unit
    35   val file: Path.T -> serialization -> unit
       
    36   val string: string list -> serialization -> string
    35   val string: string list -> serialization -> string
    37   val code_of: theory -> string -> int option -> string
    36   val code_of: theory -> string -> int option -> string
    38     -> string list -> (Code_Thingol.naming -> string list) -> string
    37     -> string list -> (Code_Thingol.naming -> string list) -> string
    39   val set_default_code_width: int -> theory -> theory
    38   val set_default_code_width: int -> theory -> theory
    40   val shell_command: string (*theory name*) -> string (*export_code expr*) -> unit
    39   val shell_command: string (*theory name*) -> string (*export_code expr*) -> unit
    63 (** basics **)
    62 (** basics **)
    64 
    63 
    65 datatype destination = File of Path.T option | String of string list;
    64 datatype destination = File of Path.T option | String of string list;
    66 type serialization = destination -> (string * string option list) option;
    65 type serialization = destination -> (string * string option list) option;
    67 
    66 
    68 fun export f = (f (File NONE); ());
    67 fun file some_path f = (f (File some_path); ());
    69 fun file path f = (f (File (SOME path)); ());
       
    70 fun string stmt_names f = fst (the (f (String stmt_names)));
    68 fun string stmt_names f = fst (the (f (String stmt_names)));
    71 
    69 
    72 fun stmt_names_of_destination (String stmt_names) = stmt_names
    70 fun stmt_names_of_destination (String stmt_names) = stmt_names
    73   | stmt_names_of_destination _ = [];
    71   | stmt_names_of_destination _ = [];
    74 
    72 
    75 fun mk_serialization output _ pretty width (File path) = (output width path pretty; NONE)
    73 fun mk_serialization output _ pretty width (File some_path) = (output width some_path pretty; NONE)
    76   | mk_serialization _ string pretty width (String _) = SOME (string width pretty);
    74   | mk_serialization _ string pretty width (String _) = SOME (string width pretty);
    77 
    75 
    78 
    76 
    79 (** theory data **)
    77 (** theory data **)
    80 
    78 
   333       (#check o the_fundamental thy) target;
   331       (#check o the_fundamental thy) target;
   334     val env_param = getenv env_var;
   332     val env_param = getenv env_var;
   335     fun ext_check env_param p =
   333     fun ext_check env_param p =
   336       let 
   334       let 
   337         val destination = make_destination p;
   335         val destination = make_destination p;
   338         val _ = file destination (serialize thy target (SOME 80)
   336         val _ = file (SOME destination) (serialize thy target (SOME 80)
   339           (SOME module_name) args naming program names_cs);
   337           (SOME module_name) args naming program names_cs);
   340         val cmd = make_command env_param module_name;
   338         val cmd = make_command env_param module_name;
   341       in if bash ("cd " ^ File.shell_path p ^ " && " ^ cmd ^ " 2>&1") <> 0
   339       in if bash ("cd " ^ File.shell_path p ^ " && " ^ cmd ^ " 2>&1") <> 0
   342         then error ("Code check failed for " ^ target ^ ": " ^ cmd)
   340         then error ("Code check failed for " ^ target ^ ": " ^ cmd)
   343         else ()
   341         else ()
   385   in union (op =) cs3 cs1 end;
   383   in union (op =) cs3 cs1 end;
   386 
   384 
   387 fun export_code thy cs seris =
   385 fun export_code thy cs seris =
   388   let
   386   let
   389     val (names_cs, (naming, program)) = Code_Thingol.consts_program thy false cs;
   387     val (names_cs, (naming, program)) = Code_Thingol.consts_program thy false cs;
   390     fun mk_seri_dest dest = if dest = "" orelse dest = "-" then export
   388     fun mk_destination dest = if dest = "" orelse dest = "-"
   391       else file (Path.explode dest);
   389       then NONE else SOME (Path.explode dest);
   392     val _ = map (fn (((target, module), dest), args) =>
   390     val _ = map (fn (((target, module), dest), args) =>
   393       (mk_seri_dest dest (serialize thy target NONE module args naming program names_cs))) seris;
   391       (file (mk_destination dest) (serialize thy target NONE module args naming program names_cs))) seris;
   394   in () end;
   392   in () end;
   395 
   393 
   396 fun export_code_cmd raw_cs seris thy = export_code thy (read_const_exprs thy raw_cs) seris;
   394 fun export_code_cmd raw_cs seris thy = export_code thy (read_const_exprs thy raw_cs) seris;
   397 
   395 
   398 fun check_code thy cs seris =
   396 fun check_code thy cs seris =