src/HOL/Tools/LSC/lazysmallcheck.ML
changeset 41908 3bd9a21366d2
parent 41905 e2611bc96022
child 41909 383bbdad1650
equal deleted inserted replaced
41907:b04e16854c08 41908:3bd9a21366d2
    24   ML_Context.exec (fn () => Secure.use_text ML_Env.local_context (0, "generated code") verbose code)
    24   ML_Context.exec (fn () => Secure.use_text ML_Env.local_context (0, "generated code") verbose code)
    25 
    25 
    26 fun value ctxt (get, put, put_ml) (code, value) =
    26 fun value ctxt (get, put, put_ml) (code, value) =
    27   let
    27   let
    28     val prefix = "LSC"
    28     val prefix = "LSC"
    29     fun make_cmd files = getenv "EXEC_GHC" ^ " -fglasgow-exts -e \"Main.main\" " ^ (space_implode " " (map Path.implode files))
    29     fun make_cmd executable files =
       
    30       getenv "EXEC_GHC" ^ " -fglasgow-exts " ^ (space_implode " " (map Path.implode files)) ^
       
    31         " -o " ^ executable ^ " && " ^ executable
    30     fun run in_path = 
    32     fun run in_path = 
    31       let
    33       let
    32         val code_file = Path.append in_path (Path.basic "Code.hs")
    34         val code_file = Path.append in_path (Path.basic "Code.hs")
    33         val lsc_file = Path.append in_path (Path.basic "LazySmallCheck.hs")
    35         val lsc_file = Path.append in_path (Path.basic "LazySmallCheck.hs")
    34         val main_file = Path.append in_path (Path.basic "Main.hs")
    36         val main_file = Path.append in_path (Path.basic "Main.hs")
    35         val main = "module Main where {\n\n" ^
    37         val main = "module Main where {\n\n" ^
    36           "import LazySmallCheck;\n" ^
    38           "import LazySmallCheck;\n" ^
    37           "import Code;\n\n" ^
    39           "import Code;\n\n" ^
    38           "main = LazySmallCheck.smallCheck 10 (Code.value ())\n\n" ^
    40           "main = LazySmallCheck.smallCheck 7 (Code.value ())\n\n" ^
    39           "}\n"
    41           "}\n"
    40         val _ = File.write code_file code
    42         val _ = File.write code_file code
    41         val _ = File.write lsc_file lsc_module
    43         val _ = File.write lsc_file lsc_module
    42         val _ = File.write main_file main
    44         val _ = File.write main_file main
    43         val cmd = make_cmd [code_file, lsc_file, main_file]
    45         val executable = Path.implode (Path.append in_path (Path.basic "isa_lsc"))
       
    46         val cmd = make_cmd executable [code_file, lsc_file, main_file]
    44       in
    47       in
    45         bash_output cmd
    48         bash_output cmd
    46       end 
    49       end 
    47     val result = Isabelle_System.with_tmp_dir prefix run
    50     val result = Isabelle_System.with_tmp_dir prefix run
    48     val _ = tracing (fst result)
       
    49     val output_value = the_default "NONE"
    51     val output_value = the_default "NONE"
    50       (try (snd o split_last o filter_out (fn s => s = "") o split_lines o fst) result)
    52       (try (snd o split_last o filter_out (fn s => s = "") o split_lines o fst) result)
    51     val ml_code = "\nval _ = Context.set_thread_data (SOME (Context.map_proof (" ^ put_ml
    53     val ml_code = "\nval _ = Context.set_thread_data (SOME (Context.map_proof (" ^ put_ml
    52       ^ " (fn () => " ^ output_value ^ ")) (ML_Context.the_generic_context ())))";
    54       ^ " (fn () => " ^ output_value ^ ")) (ML_Context.the_generic_context ())))";
    53     val ctxt' = ctxt
    55     val ctxt' = ctxt
    54       |> put (fn () => error ("Bad evaluation for " ^ quote put_ml))
    56       |> put (fn () => error ("Bad evaluation for " ^ quote put_ml))
    55       |> Context.proof_map (exec false ml_code);
    57       |> Context.proof_map (exec false ml_code);
    56     val _ = tracing "after exec"
       
    57   in get ctxt' () end;
    58   in get ctxt' () end;
    58 
    59 
    59 fun evaluation cookie thy evaluator vs_t args =
    60 fun evaluation cookie thy evaluator vs_t args =
    60   let
    61   let
    61     val ctxt = ProofContext.init_global thy;
    62     val ctxt = ProofContext.init_global thy;
    86     fun ensure_testable t =
    87     fun ensure_testable t =
    87       Const (@{const_name LSC.ensure_testable}, fastype_of t --> fastype_of t) $ t
    88       Const (@{const_name LSC.ensure_testable}, fastype_of t --> fastype_of t) $ t
    88     val t = dynamic_value_strict
    89     val t = dynamic_value_strict
    89       (Lazysmallcheck_Result.get, Lazysmallcheck_Result.put, "Lazysmallcheck.put_counterexample")
    90       (Lazysmallcheck_Result.get, Lazysmallcheck_Result.put, "Lazysmallcheck.put_counterexample")
    90       thy (Option.map o map) (ensure_testable t) []
    91       thy (Option.map o map) (ensure_testable t) []
    91     val _ = tracing "end of compile generator..."
       
    92   in
    92   in
    93     (t, NONE)
    93     (t, NONE)
    94   end;
    94   end;
    95 
    95 
    96 
    96