src/HOL/Tools/LSC/lazysmallcheck.ML
changeset 41909 383bbdad1650
parent 41908 3bd9a21366d2
equal deleted inserted replaced
41908:3bd9a21366d2 41909:383bbdad1650
    23 fun exec verbose code =
    23 fun exec verbose code =
    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 tmp_prefix = "LSC"
    29     fun make_cmd executable files =
    29     fun make_cmd executable files =
    30       getenv "EXEC_GHC" ^ " -fglasgow-exts " ^ (space_implode " " (map Path.implode files)) ^
    30       getenv "EXEC_GHC" ^ " -fglasgow-exts " ^ (space_implode " " (map Path.implode files)) ^
    31         " -o " ^ executable ^ " && " ^ executable
    31         " -o " ^ executable ^ " && " ^ executable
    32     fun run in_path = 
    32     fun run in_path = 
    33       let
    33       let
    37         val main = "module Main where {\n\n" ^
    37         val main = "module Main where {\n\n" ^
    38           "import LazySmallCheck;\n" ^
    38           "import LazySmallCheck;\n" ^
    39           "import Code;\n\n" ^
    39           "import Code;\n\n" ^
    40           "main = LazySmallCheck.smallCheck 7 (Code.value ())\n\n" ^
    40           "main = LazySmallCheck.smallCheck 7 (Code.value ())\n\n" ^
    41           "}\n"
    41           "}\n"
    42         val _ = File.write code_file code
    42         val code' = prefix "module Code where {\n\ndata Typerep = Typerep String [Typerep];\n"
       
    43           (unprefix "module Code where {" code)
       
    44         val _ = File.write code_file code'
    43         val _ = File.write lsc_file lsc_module
    45         val _ = File.write lsc_file lsc_module
    44         val _ = File.write main_file main
    46         val _ = File.write main_file main
    45         val executable = Path.implode (Path.append in_path (Path.basic "isa_lsc"))
    47         val executable = Path.implode (Path.append in_path (Path.basic "isa_lsc"))
    46         val cmd = make_cmd executable [code_file, lsc_file, main_file]
    48         val cmd = make_cmd executable [code_file, lsc_file, main_file]
    47       in
    49       in
    48         bash_output cmd
    50         bash_output cmd
    49       end 
    51       end 
    50     val result = Isabelle_System.with_tmp_dir prefix run
    52     val result = Isabelle_System.with_tmp_dir tmp_prefix run
    51     val output_value = the_default "NONE"
    53     val output_value = the_default "NONE"
    52       (try (snd o split_last o filter_out (fn s => s = "") o split_lines o fst) result)
    54       (try (snd o split_last o filter_out (fn s => s = "") o split_lines o fst) result)
    53     val ml_code = "\nval _ = Context.set_thread_data (SOME (Context.map_proof (" ^ put_ml
    55     val ml_code = "\nval _ = Context.set_thread_data (SOME (Context.map_proof (" ^ put_ml
    54       ^ " (fn () => " ^ output_value ^ ")) (ML_Context.the_generic_context ())))";
    56       ^ " (fn () => " ^ output_value ^ ")) (ML_Context.the_generic_context ())))";
    55     val ctxt' = ctxt
    57     val ctxt' = ctxt