src/HOL/Tools/Predicate_Compile/code_prolog.ML
changeset 38951 a16ee2b38db2
parent 38950 62578950e748
child 38956 2e5bf3bc7361
equal deleted inserted replaced
38950:62578950e748 38951:a16ee2b38db2
   542 
   542 
   543 fun invoke system file_name =
   543 fun invoke system file_name =
   544   let
   544   let
   545     val cmd =
   545     val cmd =
   546       case system of SWI_PROLOG => "/usr/local/bin/swipl -f " | YAP => "/usr/local/bin/yap -L "
   546       case system of SWI_PROLOG => "/usr/local/bin/swipl -f " | YAP => "/usr/local/bin/yap -L "
   547   in bash_output (cmd ^ file_name) end
   547   in fst (bash_output (cmd ^ file_name)) end
   548 
   548 
   549 (* parsing prolog solution *)
   549 (* parsing prolog solution *)
   550 
   550 
   551 val scan_number =
   551 val scan_number =
   552   Scan.many1 Symbol.is_ascii_digit
   552   Scan.many1 Symbol.is_ascii_digit
   598   
   598   
   599 (* calling external interpreter and getting results *)
   599 (* calling external interpreter and getting results *)
   600 
   600 
   601 fun run system p query_rel vnames nsols =
   601 fun run system p query_rel vnames nsols =
   602   let
   602   let
   603     val cmd = Path.named_root
       
   604     val p' = rename_vars_program p
   603     val p' = rename_vars_program p
   605     val _ = tracing "Renaming variable names..."
   604     val _ = tracing "Renaming variable names..."
   606     val renaming = fold mk_renaming vnames [] 
   605     val renaming = fold mk_renaming vnames [] 
   607     val vnames' = map (fn v => the (AList.lookup (op =) renaming v)) vnames
   606     val vnames' = map (fn v => the (AList.lookup (op =) renaming v)) vnames
   608     val prog = prelude system ^ query system nsols query_rel vnames' ^ write_program p'
   607     val prog = prelude system ^ query system nsols query_rel vnames' ^ write_program p'
   609     val _ = tracing ("Generated prolog program:\n" ^ prog)
   608     val _ = tracing ("Generated prolog program:\n" ^ prog)
   610     val prolog_file = File.tmp_path (Path.basic "prolog_file")
   609     val solution = Cache_IO.with_tmp_file "prolog_file" (fn prolog_file =>
   611     val _ = File.write prolog_file prog
   610       (File.write prolog_file prog; invoke system (Path.implode prolog_file)))
   612     val (solution, _) = invoke system (File.shell_path prolog_file)
       
   613     val _ = tracing ("Prolog returned solution(s):\n" ^ solution)
   611     val _ = tracing ("Prolog returned solution(s):\n" ^ solution)
   614     val tss = parse_solutions solution
   612     val tss = parse_solutions solution
   615   in
   613   in
   616     tss
   614     tss
   617   end
   615   end