src/HOL/Library/code_test.ML
changeset 64581 ee4b9cea7fb5
parent 64580 43ad19fbe9dc
child 64582 3d20ded18f14
equal deleted inserted replaced
64580:43ad19fbe9dc 64581:ee4b9cea7fb5
     7 signature CODE_TEST =
     7 signature CODE_TEST =
     8 sig
     8 sig
     9   val add_driver:
     9   val add_driver:
    10     string * ((Proof.context -> (string * string) list * string -> Path.T -> string) * string) ->
    10     string * ((Proof.context -> (string * string) list * string -> Path.T -> string) * string) ->
    11     theory -> theory
    11     theory -> theory
    12   val get_driver: theory -> string ->
       
    13     ((Proof.context -> (string * string) list * string -> Path.T -> string) * string) option
       
    14   val overlord: bool Config.T
    12   val overlord: bool Config.T
    15   val successN: string
    13   val successN: string
    16   val failureN: string
    14   val failureN: string
    17   val start_markerN: string
    15   val start_markerN: string
    18   val end_markerN: string
    16   val end_markerN: string
    19   val test_terms: Proof.context -> term list -> string -> unit
    17   val test_terms: Proof.context -> term list -> string -> unit
    20   val test_targets: Proof.context -> term list -> string list -> unit
    18   val test_targets: Proof.context -> term list -> string list -> unit
    21   val test_code_cmd: string list -> string list -> Proof.context -> unit
    19   val test_code_cmd: string list -> string list -> Proof.context -> unit
    22 
       
    23   val eval_term: string -> Proof.context -> term -> term
    20   val eval_term: string -> Proof.context -> term -> term
    24 
    21   val evaluate:
    25   val gen_driver:
       
    26    (theory -> Path.T -> string list -> string ->
    22    (theory -> Path.T -> string list -> string ->
    27     {files: (Path.T * string) list,
    23     {files: (Path.T * string) list,
    28      compile_cmd: string option,
    24      compile_cmd: string option,
    29      run_cmd: string,
    25      run_cmd: string,
    30      mk_code_file: string -> Path.T}) ->
    26      mk_code_file: string -> Path.T}) ->
    31    string -> string -> string -> theory -> (string * string) list * string -> Path.T -> string
    27    string -> string -> string -> theory -> (string * string) list * string -> Path.T -> string
    32 
       
    33   val ISABELLE_POLYML: string
       
    34   val polymlN: string
       
    35   val evaluate_in_polyml: Proof.context -> (string * string) list * string -> Path.T -> string
    28   val evaluate_in_polyml: Proof.context -> (string * string) list * string -> Path.T -> string
    36 
       
    37   val mltonN: string
       
    38   val ISABELLE_MLTON: string
       
    39   val evaluate_in_mlton: Proof.context -> (string * string) list * string -> Path.T -> string
    29   val evaluate_in_mlton: Proof.context -> (string * string) list * string -> Path.T -> string
    40 
       
    41   val smlnjN: string
       
    42   val ISABELLE_SMLNJ: string
       
    43   val evaluate_in_smlnj: Proof.context -> (string * string) list * string -> Path.T -> string
    30   val evaluate_in_smlnj: Proof.context -> (string * string) list * string -> Path.T -> string
    44 
       
    45   val ocamlN: string
       
    46   val ISABELLE_OCAMLC: string
       
    47   val evaluate_in_ocaml: Proof.context -> (string * string) list * string -> Path.T -> string
    31   val evaluate_in_ocaml: Proof.context -> (string * string) list * string -> Path.T -> string
    48 
       
    49   val ghcN: string
       
    50   val ISABELLE_GHC: string
       
    51   val ghc_options: string Config.T
    32   val ghc_options: string Config.T
    52   val evaluate_in_ghc: Proof.context -> (string * string) list * string -> Path.T -> string
    33   val evaluate_in_ghc: Proof.context -> (string * string) list * string -> Path.T -> string
    53 
       
    54   val scalaN: string
       
    55   val ISABELLE_SCALA: string
       
    56   val evaluate_in_scala: Proof.context -> (string * string) list * string -> Path.T -> string
    34   val evaluate_in_scala: Proof.context -> (string * string) list * string -> Path.T -> string
    57 end
    35 end
    58 
    36 
    59 structure Code_Test: CODE_TEST =
    37 structure Code_Test: CODE_TEST =
    60 struct
    38 struct
   293   in (case result of [(_, SOME [t])] => t | _ => error "Evaluation failed") end
   271   in (case result of [(_, SOME [t])] => t | _ => error "Evaluation failed") end
   294 
   272 
   295 
   273 
   296 (* generic driver *)
   274 (* generic driver *)
   297 
   275 
   298 fun gen_driver mk_driver env_var env_var_dest compilerN ctxt (code_files, value_name) =
   276 fun evaluate mk_driver env_var env_var_dest compilerN ctxt (code_files, value_name) =
   299   let
   277   let
   300     val compiler = getenv env_var
   278     val compiler = getenv env_var
   301     val _ =
   279     val _ =
   302       if compiler <> "" then ()
   280       if compiler <> "" then ()
   303       else error (Pretty.string_of (Pretty.para
   281       else error (Pretty.string_of (Pretty.para
   366   in
   344   in
   367     {files = [(driver_path, driver)], compile_cmd = NONE, run_cmd = cmd, mk_code_file = K code_path}
   345     {files = [(driver_path, driver)], compile_cmd = NONE, run_cmd = cmd, mk_code_file = K code_path}
   368   end
   346   end
   369 
   347 
   370 fun evaluate_in_polyml ctxt =
   348 fun evaluate_in_polyml ctxt =
   371   gen_driver mk_driver_polyml ISABELLE_POLYML "PolyML executable" polymlN ctxt
   349   evaluate mk_driver_polyml ISABELLE_POLYML "PolyML executable" polymlN ctxt
   372 
   350 
   373 
   351 
   374 (* driver for mlton *)
   352 (* driver for mlton *)
   375 
   353 
   376 val mltonN = "MLton"
   354 val mltonN = "MLton"
   408     {files = [(driver_path, driver), (ml_basis_path, ml_basis)],
   386     {files = [(driver_path, driver), (ml_basis_path, ml_basis)],
   409      compile_cmd = SOME compile_cmd, run_cmd = run_cmd, mk_code_file = K code_path}
   387      compile_cmd = SOME compile_cmd, run_cmd = run_cmd, mk_code_file = K code_path}
   410   end
   388   end
   411 
   389 
   412 fun evaluate_in_mlton ctxt =
   390 fun evaluate_in_mlton ctxt =
   413   gen_driver mk_driver_mlton ISABELLE_MLTON "MLton executable" mltonN ctxt
   391   evaluate mk_driver_mlton ISABELLE_MLTON "MLton executable" mltonN ctxt
   414 
   392 
   415 
   393 
   416 (* driver for SML/NJ *)
   394 (* driver for SML/NJ *)
   417 
   395 
   418 val smlnjN = "SMLNJ"
   396 val smlnjN = "SMLNJ"
   448   in
   426   in
   449     {files = [(driver_path, driver)], compile_cmd = NONE, run_cmd = cmd, mk_code_file = K code_path}
   427     {files = [(driver_path, driver)], compile_cmd = NONE, run_cmd = cmd, mk_code_file = K code_path}
   450   end
   428   end
   451 
   429 
   452 fun evaluate_in_smlnj ctxt =
   430 fun evaluate_in_smlnj ctxt =
   453   gen_driver mk_driver_smlnj ISABELLE_SMLNJ "SMLNJ executable" smlnjN ctxt
   431   evaluate mk_driver_smlnj ISABELLE_SMLNJ "SMLNJ executable" smlnjN ctxt
   454 
   432 
   455 
   433 
   456 (* driver for OCaml *)
   434 (* driver for OCaml *)
   457 
   435 
   458 val ocamlN = "OCaml"
   436 val ocamlN = "OCaml"
   490     {files = [(driver_path, driver)],
   468     {files = [(driver_path, driver)],
   491      compile_cmd = SOME compile_cmd, run_cmd = run_cmd, mk_code_file = K code_path}
   469      compile_cmd = SOME compile_cmd, run_cmd = run_cmd, mk_code_file = K code_path}
   492   end
   470   end
   493 
   471 
   494 fun evaluate_in_ocaml ctxt =
   472 fun evaluate_in_ocaml ctxt =
   495   gen_driver mk_driver_ocaml ISABELLE_OCAMLC "ocamlc executable" ocamlN ctxt
   473   evaluate mk_driver_ocaml ISABELLE_OCAMLC "ocamlc executable" ocamlN ctxt
   496 
   474 
   497 
   475 
   498 (* driver for GHC *)
   476 (* driver for GHC *)
   499 
   477 
   500 val ghcN = "GHC"
   478 val ghcN = "GHC"
   536     {files = [(driver_path, driver)],
   514     {files = [(driver_path, driver)],
   537      compile_cmd = SOME compile_cmd, run_cmd = run_cmd, mk_code_file = mk_code_file}
   515      compile_cmd = SOME compile_cmd, run_cmd = run_cmd, mk_code_file = mk_code_file}
   538   end
   516   end
   539 
   517 
   540 fun evaluate_in_ghc ctxt =
   518 fun evaluate_in_ghc ctxt =
   541   gen_driver mk_driver_ghc ISABELLE_GHC "GHC executable" ghcN ctxt
   519   evaluate mk_driver_ghc ISABELLE_GHC "GHC executable" ghcN ctxt
   542 
   520 
   543 
   521 
   544 (* driver for Scala *)
   522 (* driver for Scala *)
   545 
   523 
   546 val scalaN = "Scala"
   524 val scalaN = "Scala"
   584     {files = [(driver_path, driver)],
   562     {files = [(driver_path, driver)],
   585      compile_cmd = SOME compile_cmd, run_cmd = run_cmd, mk_code_file = K code_path}
   563      compile_cmd = SOME compile_cmd, run_cmd = run_cmd, mk_code_file = K code_path}
   586   end
   564   end
   587 
   565 
   588 fun evaluate_in_scala ctxt =
   566 fun evaluate_in_scala ctxt =
   589   gen_driver mk_driver_scala ISABELLE_SCALA "Scala directory" scalaN ctxt
   567   evaluate mk_driver_scala ISABELLE_SCALA "Scala directory" scalaN ctxt
   590 
   568 
   591 
   569 
   592 (* command setup *)
   570 (* command setup *)
   593 
   571 
   594 val _ =
   572 val _ =