author | aspinall |
Fri, 30 Sep 2005 18:18:34 +0200 | |
changeset 17740 | fc385ce6187d |
parent 17716 | 89932e53f31d |
child 17746 | af59c748371d |
permissions | -rw-r--r-- |
15789
4cb16144c81b
added hearder lines and deleted some redundant material
paulson
parents:
15787
diff
changeset
|
1 |
(* Title: Watcher.ML |
4cb16144c81b
added hearder lines and deleted some redundant material
paulson
parents:
15787
diff
changeset
|
2 |
ID: $Id$ |
4cb16144c81b
added hearder lines and deleted some redundant material
paulson
parents:
15787
diff
changeset
|
3 |
Author: Claire Quigley |
4cb16144c81b
added hearder lines and deleted some redundant material
paulson
parents:
15787
diff
changeset
|
4 |
Copyright 2004 University of Cambridge |
15642 | 5 |
*) |
6 |
||
7 |
(***************************************************************************) |
|
8 |
(* The watcher process starts a resolution process when it receives a *) |
|
9 |
(* message from Isabelle *) |
|
10 |
(* Signals Isabelle, puts output of child into pipe to Isabelle, *) |
|
11 |
(* and removes dead processes. Also possible to kill all the resolution *) |
|
12 |
(* processes currently running. *) |
|
13 |
(* Hardwired version of where to pick up the tptp files for the moment *) |
|
14 |
(***************************************************************************) |
|
15 |
||
17305
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
16 |
signature WATCHER = |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
17 |
sig |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
18 |
|
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
19 |
(* Send request to Watcher for multiple spasses to be called for filenames in arg *) |
17568 | 20 |
(* callResProvers (outstreamtoWatcher, prover name,prover-command, (settings,file) list *) |
17305
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
21 |
|
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
22 |
val callResProvers : |
17422 | 23 |
TextIO.outstream * (string*string*string*string*string) list |
17305
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
24 |
-> unit |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
25 |
|
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
26 |
(* Send message to watcher to kill currently running resolution provers *) |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
27 |
val callSlayer : TextIO.outstream -> unit |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
28 |
|
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
29 |
(* Start a watcher and set up signal handlers *) |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
30 |
val createWatcher : |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
31 |
thm * (ResClause.clause * thm) Array.array -> |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
32 |
TextIO.instream * TextIO.outstream * Posix.Process.pid |
17305
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
33 |
|
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
34 |
(* Kill watcher process *) |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
35 |
val killWatcher : Posix.Process.pid -> unit |
17488
67376a311a2b
further simplification of the Isabelle-ATP linkup
paulson
parents:
17484
diff
changeset
|
36 |
val killWatcher' : int -> unit |
17305
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
37 |
end |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
38 |
|
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
39 |
|
15642 | 40 |
|
41 |
structure Watcher: WATCHER = |
|
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
42 |
struct |
15642 | 43 |
|
17488
67376a311a2b
further simplification of the Isabelle-ATP linkup
paulson
parents:
17484
diff
changeset
|
44 |
open Recon_Transfer |
16805 | 45 |
|
15642 | 46 |
val goals_being_watched = ref 0; |
47 |
||
17583
c272b91b619f
removal of "sleep" to stop looping in Poly/ML, and replacement of funny codes by tracing statements
paulson
parents:
17568
diff
changeset
|
48 |
val trace_path = Path.basic "watcher_trace"; |
c272b91b619f
removal of "sleep" to stop looping in Poly/ML, and replacement of funny codes by tracing statements
paulson
parents:
17568
diff
changeset
|
49 |
|
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
50 |
fun trace s = if !Output.show_debug_msgs then File.append (File.tmp_path trace_path) s |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
51 |
else (); |
17583
c272b91b619f
removal of "sleep" to stop looping in Poly/ML, and replacement of funny codes by tracing statements
paulson
parents:
17568
diff
changeset
|
52 |
|
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
53 |
(* The result of calling createWatcher *) |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
54 |
datatype proc = PROC of { |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
55 |
pid : Posix.Process.pid, |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
56 |
instr : TextIO.instream, |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
57 |
outstr : TextIO.outstream |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
58 |
}; |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
59 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
60 |
(* The result of calling executeToList *) |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
61 |
datatype cmdproc = CMDPROC of { |
17568 | 62 |
prover: string, (* Name of the resolution prover used, e.g. Vampire*) |
63 |
cmd: string, (* The file containing the goal for res prover to prove *) |
|
64 |
goalstring: string, (* string representation of subgoal*) |
|
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
65 |
proc_handle : (TextIO.instream,TextIO.outstream) Unix.proc, |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
66 |
instr : TextIO.instream, (* Input stream to child process *) |
17568 | 67 |
outstr : TextIO.outstream}; (* Output stream from child process *) |
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
68 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
69 |
type signal = Posix.Signal.signal |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
70 |
datatype exit_status = datatype Posix.Process.exit_status |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
71 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
72 |
val fromStatus = Posix.Process.fromStatus |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
73 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
74 |
fun reap(pid, instr, outstr) = |
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
75 |
let val u = TextIO.closeIn instr; |
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
76 |
val u = TextIO.closeOut outstr; |
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
77 |
val (_, status) = Posix.Process.waitpid(Posix.Process.W_CHILD pid, []) |
17568 | 78 |
in status end |
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
79 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
80 |
fun fdReader (name : string, fd : Posix.IO.file_desc) = |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
81 |
Posix.IO.mkTextReader {initBlkMode = true,name = name,fd = fd }; |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
82 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
83 |
fun fdWriter (name, fd) = |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
84 |
Posix.IO.mkTextWriter { |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
85 |
appendMode = false, |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
86 |
initBlkMode = true, |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
87 |
name = name, |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
88 |
chunkSize=4096, |
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
89 |
fd = fd}; |
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
90 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
91 |
fun openOutFD (name, fd) = |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
92 |
TextIO.mkOutstream ( |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
93 |
TextIO.StreamIO.mkOutstream ( |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
94 |
fdWriter (name, fd), IO.BLOCK_BUF)); |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
95 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
96 |
fun openInFD (name, fd) = |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
97 |
TextIO.mkInstream ( |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
98 |
TextIO.StreamIO.mkInstream ( |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
99 |
fdReader (name, fd), "")); |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
100 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
101 |
fun childInfo (PROC{pid,instr,outstr }) = (pid,(instr,outstr)); |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
102 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
103 |
fun cmdstreamsOf (CMDPROC{instr,outstr,...}) = (instr, outstr); |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
104 |
|
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
105 |
fun cmdInStream (CMDPROC{instr,outstr,...}) = instr; |
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
106 |
|
17422 | 107 |
fun cmdchildInfo (CMDPROC{prover,cmd,proc_handle,goalstring,instr,outstr}) = |
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
108 |
(prover,(cmd, (instr,outstr))); |
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
109 |
|
17422 | 110 |
fun cmdchildHandle (CMDPROC{prover,cmd,goalstring,proc_handle,instr,outstr}) = |
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
111 |
proc_handle; |
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
112 |
|
17422 | 113 |
fun cmdProver (CMDPROC{prover,cmd,goalstring,proc_handle,instr,outstr}) = |
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
114 |
prover; |
15642 | 115 |
|
17422 | 116 |
fun cmdGoal (CMDPROC{prover,cmd,goalstring,proc_handle,instr,outstr}) = |
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
117 |
goalstring; |
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
118 |
|
15642 | 119 |
|
120 |
(* gets individual args from instream and concatenates them into a list *) |
|
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
121 |
fun getArgs (fromParentStr, toParentStr, ys) = |
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
122 |
let val thisLine = TextIO.input fromParentStr |
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
123 |
in ys@[thisLine] end |
15642 | 124 |
|
125 |
||
126 |
(* Send request to Watcher for a vampire to be called for filename in arg *) |
|
17568 | 127 |
|
17231 | 128 |
fun callResProver (toWatcherStr, arg) = |
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
129 |
(TextIO.output (toWatcherStr, arg^"\n"); |
17231 | 130 |
TextIO.flushOut toWatcherStr) |
15642 | 131 |
|
132 |
(*****************************************************************************************) |
|
16357 | 133 |
(* Send request to Watcher for multiple provers to be called for filenames in arg *) |
134 |
(* need to do the dfg stuff in the watcher, not here! send over the clasimp and stuff files too*) |
|
15642 | 135 |
(*****************************************************************************************) |
136 |
||
16357 | 137 |
|
17305
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
138 |
(*Uses the $-character to separate items sent to watcher*) |
16475 | 139 |
fun callResProvers (toWatcherStr, []) = |
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
140 |
(TextIO.output (toWatcherStr, "End of calls\n"); TextIO.flushOut toWatcherStr) |
16475 | 141 |
| callResProvers (toWatcherStr, |
17422 | 142 |
(prover,goalstring, proverCmd,settings, |
143 |
probfile) :: args) = |
|
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
144 |
let val _ = trace (space_implode "\n" |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
145 |
(["\ncallResProvers:",prover,goalstring,proverCmd,settings, |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
146 |
probfile])) |
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
147 |
in TextIO.output (toWatcherStr, |
17422 | 148 |
(prover^"$"^goalstring^"$"^proverCmd^"$"^ |
149 |
settings^"$"^probfile^"\n")); |
|
16475 | 150 |
goals_being_watched := (!goals_being_watched) + 1; |
151 |
TextIO.flushOut toWatcherStr; |
|
152 |
callResProvers (toWatcherStr,args) |
|
153 |
end |
|
16357 | 154 |
|
17305
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
155 |
|
15642 | 156 |
|
157 |
(**************************************************************) |
|
158 |
(* Send message to watcher to kill currently running vampires *) |
|
159 |
(**************************************************************) |
|
160 |
||
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
161 |
fun callSlayer toWatcherStr = (TextIO.output (toWatcherStr, "Kill vampires\n"); |
15642 | 162 |
TextIO.flushOut toWatcherStr) |
163 |
||
164 |
||
165 |
(**************************************************************) |
|
166 |
(* Remove \n token from a vampire goal filename and extract *) |
|
167 |
(* prover, proverCmd, settings and file from input string *) |
|
168 |
(**************************************************************) |
|
169 |
||
17305
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
170 |
val remove_newlines = String.translate (fn c => if c = #"\n" then "" else str c); |
15642 | 171 |
|
17305
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
172 |
fun getCmd cmdStr = |
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
173 |
let val [prover,goalstring,proverCmd,settingstr,probfile] = |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
174 |
String.tokens (fn c => c = #"$") (remove_newlines cmdStr) |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
175 |
val settings = String.tokens (fn c => c = #"%") settingstr |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
176 |
val _ = trace ("getCmd: " ^ cmdStr ^ |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
177 |
"\nprover" ^ prover ^ " goalstr: "^goalstring^ |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
178 |
"\nprovercmd: " ^ proverCmd^ |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
179 |
"\nprob " ^ probfile ^ "\n\n") |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
180 |
in (prover,goalstring, proverCmd, settings, probfile) end |
15642 | 181 |
|
182 |
(**************************************************************) |
|
183 |
(* Get commands from Isabelle *) |
|
184 |
(**************************************************************) |
|
185 |
fun getCmds (toParentStr,fromParentStr, cmdList) = |
|
16475 | 186 |
let val thisLine = TextIO.inputLine fromParentStr |
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
187 |
val _ = trace("\nGot command from parent: " ^ thisLine) |
16475 | 188 |
in |
17568 | 189 |
if thisLine = "End of calls\n" orelse thisLine = "" then cmdList |
17422 | 190 |
else if thisLine = "Kill children\n" |
17568 | 191 |
then (TextIO.output (toParentStr,thisLine ); |
192 |
TextIO.flushOut toParentStr; |
|
193 |
(("","","Kill children",[],"")::cmdList) ) |
|
17422 | 194 |
else let val thisCmd = getCmd thisLine |
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
195 |
in getCmds (toParentStr, fromParentStr, thisCmd::cmdList) end |
16475 | 196 |
end |
197 |
||
16357 | 198 |
|
15642 | 199 |
(**************************************************************) |
200 |
(* Get Io-descriptor for polling of an input stream *) |
|
201 |
(**************************************************************) |
|
202 |
||
203 |
fun getInIoDesc someInstr = |
|
204 |
let val (rd, buf) = TextIO.StreamIO.getReader(TextIO.getInstream someInstr) |
|
15702
2677db44c795
new signalling primmitives for sml/nj compatibility
paulson
parents:
15684
diff
changeset
|
205 |
val _ = TextIO.output (TextIO.stdOut, buf) |
15642 | 206 |
val ioDesc = |
207 |
case rd |
|
208 |
of TextPrimIO.RD{ioDesc = SOME iod, ...} =>SOME iod |
|
209 |
| _ => NONE |
|
210 |
in (* since getting the reader will have terminated the stream, we need |
|
211 |
* to build a new stream. *) |
|
212 |
TextIO.setInstream(someInstr, TextIO.StreamIO.mkInstream(rd, buf)); |
|
213 |
ioDesc |
|
214 |
end |
|
215 |
||
216 |
||
217 |
(*************************************) |
|
218 |
(* Set up a Watcher Process *) |
|
219 |
(*************************************) |
|
220 |
||
17422 | 221 |
fun getProofCmd (a,c,d,e,f) = d |
222 |
||
17716 | 223 |
(* for tracing: encloses each string element in brackets. *) |
224 |
val concat_with_and = space_implode " & " o map (enclose "(" ")"); |
|
225 |
||
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
226 |
fun prems_string_of th = |
17716 | 227 |
concat_with_and (map (Sign.string_of_term (sign_of_thm th)) (prems_of th)) |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
228 |
|
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17502
diff
changeset
|
229 |
fun killChild proc = (Unix.kill(proc, Posix.Signal.kill); Unix.reap proc); |
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17502
diff
changeset
|
230 |
|
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17502
diff
changeset
|
231 |
fun killChildren procs = List.app (ignore o killChild) procs; |
17502 | 232 |
|
17568 | 233 |
(*************************************************************) |
234 |
(* take an instream and poll its underlying reader for input *) |
|
235 |
(*************************************************************) |
|
236 |
||
237 |
fun pollParentInput (fromParentIOD, fromParentStr, toParentStr) = |
|
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
238 |
case OS.IO.pollDesc fromParentIOD of |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
239 |
SOME pd => |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
240 |
(case OS.IO.poll ([OS.IO.pollIn pd], SOME (Time.fromSeconds 2)) of |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
241 |
[] => NONE |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
242 |
| pd''::_ => if OS.IO.isIn pd'' |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
243 |
then SOME (getCmds (toParentStr, fromParentStr, [])) |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
244 |
else NONE) |
17568 | 245 |
| NONE => NONE; |
246 |
||
17583
c272b91b619f
removal of "sleep" to stop looping in Poly/ML, and replacement of funny codes by tracing statements
paulson
parents:
17568
diff
changeset
|
247 |
(*get the number of the subgoal from the filename: the last digit string*) |
c272b91b619f
removal of "sleep" to stop looping in Poly/ML, and replacement of funny codes by tracing statements
paulson
parents:
17568
diff
changeset
|
248 |
fun number_from_filename s = |
c272b91b619f
removal of "sleep" to stop looping in Poly/ML, and replacement of funny codes by tracing statements
paulson
parents:
17568
diff
changeset
|
249 |
case String.tokens (not o Char.isDigit) s of |
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
250 |
[] => (trace "\nWatcher could not read subgoal nunber!!"; raise ERROR) |
17583
c272b91b619f
removal of "sleep" to stop looping in Poly/ML, and replacement of funny codes by tracing statements
paulson
parents:
17568
diff
changeset
|
251 |
| numbers => valOf (Int.fromString (List.last numbers)); |
c272b91b619f
removal of "sleep" to stop looping in Poly/ML, and replacement of funny codes by tracing statements
paulson
parents:
17568
diff
changeset
|
252 |
|
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
253 |
fun setupWatcher (thm,clause_arr) = |
16061 | 254 |
let |
255 |
(** pipes for communication between parent and watcher **) |
|
256 |
val p1 = Posix.IO.pipe () |
|
257 |
val p2 = Posix.IO.pipe () |
|
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
258 |
fun closep () = |
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
259 |
(Posix.IO.close (#outfd p1); |
16061 | 260 |
Posix.IO.close (#infd p1); |
261 |
Posix.IO.close (#outfd p2); |
|
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
262 |
Posix.IO.close (#infd p2)) |
16061 | 263 |
(***********************************************************) |
264 |
(****** fork a watcher process and get it set up and going *) |
|
265 |
(***********************************************************) |
|
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
266 |
fun startWatcher procList = |
17234 | 267 |
(case Posix.Process.fork() (***************************************) |
268 |
of SOME pid => pid (* parent - i.e. main Isabelle process *) |
|
269 |
(***************************************) |
|
16061 | 270 |
|
17234 | 271 |
(*************************) |
272 |
| NONE => let (* child - i.e. watcher *) |
|
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
273 |
val oldchildin = #infd p1 (*************************) |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
274 |
val fromParent = Posix.FileSys.wordToFD 0w0 |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
275 |
val oldchildout = #outfd p2 |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
276 |
val toParent = Posix.FileSys.wordToFD 0w1 |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
277 |
val fromParentIOD = Posix.FileSys.fdToIOD fromParent |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
278 |
val fromParentStr = openInFD ("_exec_in_parent", fromParent) |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
279 |
val toParentStr = openOutFD ("_exec_out_parent", toParent) |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
280 |
val _ = debug ("subgoals forked to startWatcher: "^ prems_string_of thm); |
17568 | 281 |
|
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
282 |
fun pollChildInput fromStr = |
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
283 |
case getInIoDesc fromStr of |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
284 |
SOME iod => |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
285 |
(case OS.IO.pollDesc iod of |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
286 |
SOME pd => |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
287 |
let val pd' = OS.IO.pollIn pd |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
288 |
in |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
289 |
case OS.IO.poll ([pd'], SOME (Time.fromSeconds 2)) of |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
290 |
[] => false |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
291 |
| pd''::_ => OS.IO.isIn pd'' |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
292 |
end |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
293 |
| NONE => false) |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
294 |
| NONE => false |
15642 | 295 |
|
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
296 |
|
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
297 |
(* Check all ATP processes currently running for output *) |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
298 |
fun checkChildren ([], toParentStr) = [] (* no children to check *) |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
299 |
| checkChildren (childProc::otherChildren, toParentStr) = |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
300 |
let val _ = trace ("\nIn check child, length of queue:"^ |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
301 |
Int.toString (length (childProc::otherChildren))) |
17568 | 302 |
val (childInput,childOutput) = cmdstreamsOf childProc |
303 |
val child_handle = cmdchildHandle childProc |
|
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
304 |
(* childCmd is the file that the problem is in *) |
17234 | 305 |
val childCmd = fst(snd (cmdchildInfo childProc)) |
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
306 |
val _ = trace ("\nchildCmd = " ^ childCmd) |
17583
c272b91b619f
removal of "sleep" to stop looping in Poly/ML, and replacement of funny codes by tracing statements
paulson
parents:
17568
diff
changeset
|
307 |
val sg_num = number_from_filename childCmd |
17234 | 308 |
val childIncoming = pollChildInput childInput |
309 |
val parentID = Posix.ProcEnv.getppid() |
|
310 |
val prover = cmdProver childProc |
|
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
311 |
val prems_string = prems_string_of thm |
17234 | 312 |
val goalstring = cmdGoal childProc |
313 |
in |
|
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
314 |
trace("\nsubgoals forked to checkChildren: " ^ goalstring); |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
315 |
if childIncoming |
17234 | 316 |
then |
17306 | 317 |
(* check here for prover label on child*) |
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
318 |
let val _ = trace ("\nInput available from child: " ^ |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
319 |
childCmd ^ |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
320 |
"\ngoalstring is " ^ goalstring ^ "\n\n") |
17306 | 321 |
val childDone = (case prover of |
17488
67376a311a2b
further simplification of the Isabelle-ATP linkup
paulson
parents:
17484
diff
changeset
|
322 |
"vampire" => AtpCommunication.checkVampProofFound(childInput, toParentStr, parentID,goalstring, childCmd, clause_arr) |
67376a311a2b
further simplification of the Isabelle-ATP linkup
paulson
parents:
17484
diff
changeset
|
323 |
| "E" => AtpCommunication.checkEProofFound(childInput, toParentStr, parentID,goalstring, childCmd, clause_arr) |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
324 |
|"spass" => AtpCommunication.checkSpassProofFound(childInput, toParentStr, parentID,goalstring, childCmd, thm, sg_num,clause_arr) ) |
17306 | 325 |
in |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
326 |
if childDone |
17306 | 327 |
then (* child has found a proof and transferred it *) |
328 |
(* Remove this child and go on to check others*) |
|
329 |
(Unix.reap child_handle; |
|
17716 | 330 |
OS.FileSys.remove childCmd; |
17306 | 331 |
checkChildren(otherChildren, toParentStr)) |
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
332 |
else (* Keep this child and go on to check others *) |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
333 |
childProc :: checkChildren (otherChildren, toParentStr) |
17306 | 334 |
end |
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
335 |
else (trace "\nNo child output"; |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
336 |
childProc::(checkChildren (otherChildren, toParentStr))) |
17234 | 337 |
end |
15642 | 338 |
|
17234 | 339 |
|
340 |
(********************************************************************) |
|
341 |
(* call resolution processes *) |
|
342 |
(* settings should be a list of strings *) |
|
343 |
(* e.g. ["-t 300", "-m 100000"] (TextIO.input instr)^ *) |
|
344 |
(* takes list of (string, string, string list, string)list proclist *) |
|
345 |
(********************************************************************) |
|
15642 | 346 |
|
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
347 |
|
16061 | 348 |
(*** add subgoal id num to this *) |
17234 | 349 |
fun execCmds [] procList = procList |
17422 | 350 |
| execCmds ((prover, goalstring,proverCmd,settings,file)::cmds) procList = |
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
351 |
let val _ = trace |
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
352 |
(space_implode "\n" |
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
353 |
(["\nAbout to execute command for goal:", |
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
354 |
goalstring, proverCmd] @ settings @ |
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
355 |
[file, Date.toString(Date.fromTimeLocal(Time.now()))])) |
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
356 |
val childhandle:(TextIO.instream,TextIO.outstream) Unix.proc = |
17234 | 357 |
(Unix.execute(proverCmd, (settings@[file]))) |
358 |
val (instr, outstr) = Unix.streamsOf childhandle |
|
359 |
val newProcList = (CMDPROC{ |
|
360 |
prover = prover, |
|
361 |
cmd = file, |
|
362 |
goalstring = goalstring, |
|
363 |
proc_handle = childhandle, |
|
364 |
instr = instr, |
|
365 |
outstr = outstr }) :: procList |
|
366 |
||
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
367 |
val _ = trace ("\nFinished at " ^ |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
368 |
Date.toString(Date.fromTimeLocal(Time.now()))) |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
369 |
in execCmds cmds newProcList end |
15642 | 370 |
|
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
371 |
|
17234 | 372 |
(****************************************) |
373 |
(* call resolution processes remotely *) |
|
374 |
(* settings should be a list of strings *) |
|
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
375 |
(* e.g. ["-t300", "-m100000"] *) |
17234 | 376 |
(****************************************) |
16061 | 377 |
|
17234 | 378 |
(* fun execRemoteCmds [] procList = procList |
17422 | 379 |
| execRemoteCmds ((prover, goalstring,proverCmd ,settings,file)::cmds) procList = |
380 |
let val newProcList = mySshExecuteToList ("/usr/bin/ssh",([prover,goalstring,"-t", "shep"]@[proverCmd]@settings@[file]), procList) |
|
381 |
in |
|
382 |
execRemoteCmds cmds newProcList |
|
383 |
end |
|
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
384 |
*) |
15642 | 385 |
|
17234 | 386 |
(**********************************************) |
387 |
(* Watcher Loop *) |
|
388 |
(**********************************************) |
|
17583
c272b91b619f
removal of "sleep" to stop looping in Poly/ML, and replacement of funny codes by tracing statements
paulson
parents:
17568
diff
changeset
|
389 |
val iterations_left = ref 500; (*don't let it run forever*) |
16061 | 390 |
|
17568 | 391 |
fun keepWatching (procList) = |
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
392 |
let fun loop procList = |
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
393 |
let val _ = trace ("\nCalling pollParentInput: " ^ |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
394 |
Int.toString (!iterations_left)); |
17568 | 395 |
val cmdsFromIsa = pollParentInput |
396 |
(fromParentIOD, fromParentStr, toParentStr) |
|
17234 | 397 |
in |
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
398 |
OS.Process.sleep (Time.fromMilliseconds 100); |
17306 | 399 |
iterations_left := !iterations_left - 1; |
17568 | 400 |
if !iterations_left <= 0 |
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
401 |
then |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
402 |
(trace "\nTimeout: Killing proof processes"; |
17568 | 403 |
TextIO.output(toParentStr, "Timeout: Killing proof processes!\n"); |
17502 | 404 |
TextIO.flushOut toParentStr; |
17583
c272b91b619f
removal of "sleep" to stop looping in Poly/ML, and replacement of funny codes by tracing statements
paulson
parents:
17568
diff
changeset
|
405 |
killChildren (map cmdchildHandle procList); |
c272b91b619f
removal of "sleep" to stop looping in Poly/ML, and replacement of funny codes by tracing statements
paulson
parents:
17568
diff
changeset
|
406 |
exit 0) |
17306 | 407 |
else if isSome cmdsFromIsa |
17234 | 408 |
then (* deal with input from Isabelle *) |
17306 | 409 |
if getProofCmd(hd(valOf cmdsFromIsa)) = "Kill children" |
17234 | 410 |
then |
411 |
let val child_handles = map cmdchildHandle procList |
|
412 |
in |
|
413 |
killChildren child_handles; |
|
17306 | 414 |
loop [] |
17234 | 415 |
end |
416 |
else |
|
17306 | 417 |
if length procList < 5 (********************) |
17234 | 418 |
then (* Execute locally *) |
419 |
let |
|
420 |
val newProcList = execCmds (valOf cmdsFromIsa) procList |
|
17568 | 421 |
val _ = Posix.ProcEnv.getppid() |
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
422 |
val _ = trace "\nJust execed a child" |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
423 |
val newProcList' = checkChildren (newProcList, toParentStr) |
17234 | 424 |
in |
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
425 |
trace ("\nOff to keep watching: " ^ |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
426 |
Int.toString (!iterations_left)); |
17306 | 427 |
loop newProcList' |
17234 | 428 |
end |
429 |
else (* Execute remotely *) |
|
430 |
(* (actually not remote for now )*) |
|
431 |
let |
|
432 |
val newProcList = execCmds (valOf cmdsFromIsa) procList |
|
17568 | 433 |
val _ = Posix.ProcEnv.getppid() |
17234 | 434 |
val newProcList' =checkChildren (newProcList, toParentStr) |
435 |
in |
|
17306 | 436 |
loop newProcList' |
17234 | 437 |
end |
438 |
else (* No new input from Isabelle *) |
|
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
439 |
let val newProcList = checkChildren (procList, toParentStr) |
17234 | 440 |
in |
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
441 |
trace ("\nNo new input, still watching: " ^ |
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
442 |
Int.toString (!iterations_left)); |
17306 | 443 |
loop newProcList |
17234 | 444 |
end |
445 |
end |
|
446 |
in |
|
17306 | 447 |
loop procList |
17234 | 448 |
end |
449 |
||
15642 | 450 |
|
17234 | 451 |
in |
452 |
(***************************) |
|
453 |
(*** Sort out pipes ********) |
|
454 |
(***************************) |
|
15642 | 455 |
|
17234 | 456 |
Posix.IO.close (#outfd p1); |
457 |
Posix.IO.close (#infd p2); |
|
458 |
Posix.IO.dup2{old = oldchildin, new = fromParent}; |
|
459 |
Posix.IO.close oldchildin; |
|
460 |
Posix.IO.dup2{old = oldchildout, new = toParent}; |
|
461 |
Posix.IO.close oldchildout; |
|
462 |
||
463 |
(***************************) |
|
464 |
(* start the watcher loop *) |
|
465 |
(***************************) |
|
17568 | 466 |
keepWatching (procList); |
17234 | 467 |
(****************************************************************************) |
468 |
(* fake return value - actually want the watcher to loop until killed *) |
|
469 |
(****************************************************************************) |
|
470 |
Posix.Process.wordToPid 0w0 |
|
471 |
end); |
|
472 |
(* end case *) |
|
15642 | 473 |
|
474 |
||
16061 | 475 |
val _ = TextIO.flushOut TextIO.stdOut |
15642 | 476 |
|
16061 | 477 |
(*******************************) |
478 |
(*** set watcher going ********) |
|
479 |
(*******************************) |
|
15642 | 480 |
|
16061 | 481 |
val procList = [] |
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
482 |
val pid = startWatcher procList |
16061 | 483 |
(**************************************************) |
484 |
(* communication streams to watcher *) |
|
485 |
(**************************************************) |
|
15642 | 486 |
|
16061 | 487 |
val instr = openInFD ("_exec_in", #infd p2) |
488 |
val outstr = openOutFD ("_exec_out", #outfd p1) |
|
489 |
||
17568 | 490 |
in |
491 |
(*******************************) |
|
492 |
(* close the child-side fds *) |
|
493 |
(*******************************) |
|
494 |
Posix.IO.close (#outfd p2); |
|
495 |
Posix.IO.close (#infd p1); |
|
496 |
(* set the fds close on exec *) |
|
497 |
Posix.IO.setfd (#infd p2, Posix.IO.FD.flags [Posix.IO.FD.cloexec]); |
|
498 |
Posix.IO.setfd (#outfd p1, Posix.IO.FD.flags [Posix.IO.FD.cloexec]); |
|
499 |
||
500 |
(*******************************) |
|
501 |
(* return value *) |
|
502 |
(*******************************) |
|
503 |
PROC{pid = pid, instr = instr, outstr = outstr} |
|
504 |
end; |
|
15642 | 505 |
|
506 |
||
507 |
||
508 |
(**********************************************************) |
|
509 |
(* Start a watcher and set up signal handlers *) |
|
510 |
(**********************************************************) |
|
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
511 |
|
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
512 |
fun killWatcher pid = Posix.Process.kill(Posix.Process.K_PROC pid, Posix.Signal.kill); |
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
513 |
|
17488
67376a311a2b
further simplification of the Isabelle-ATP linkup
paulson
parents:
17484
diff
changeset
|
514 |
val killWatcher' = killWatcher o ResLib.pidOfInt; |
67376a311a2b
further simplification of the Isabelle-ATP linkup
paulson
parents:
17484
diff
changeset
|
515 |
|
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
516 |
fun reapWatcher(pid, instr, outstr) = |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
517 |
(TextIO.closeIn instr; TextIO.closeOut outstr; |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
518 |
Posix.Process.waitpid(Posix.Process.W_CHILD pid, []); ()) |
15642 | 519 |
|
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
520 |
fun createWatcher (thm, clause_arr) = |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
521 |
let val (childpid,(childin,childout)) = childInfo (setupWatcher(thm,clause_arr)) |
17435 | 522 |
fun decr_watched() = |
17502 | 523 |
(goals_being_watched := !goals_being_watched - 1; |
17435 | 524 |
if !goals_being_watched = 0 |
525 |
then |
|
17716 | 526 |
(debug ("\nReaping a watcher, childpid = "^ |
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
527 |
LargeWord.toString (Posix.Process.pidToWord childpid)); |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
528 |
killWatcher childpid; reapWatcher (childpid,childin, childout)) |
17435 | 529 |
else ()) |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
530 |
val _ = debug ("subgoals forked to createWatcher: "^ prems_string_of thm); |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
531 |
fun proofHandler n = |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
532 |
let val outcome = TextIO.inputLine childin |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
533 |
val goalstring = TextIO.inputLine childin |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
534 |
val _ = debug ("In signal handler. outcome = \"" ^ outcome ^ |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
535 |
"\"\ngoalstring = " ^ goalstring ^ |
17568 | 536 |
"\ngoals_being_watched: "^ Int.toString (!goals_being_watched)) |
17502 | 537 |
in |
538 |
if String.isPrefix "[" outcome (*indicates a proof reconstruction*) |
|
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
539 |
then (priority (Recon_Transfer.apply_res_thm outcome goalstring); |
17435 | 540 |
decr_watched()) |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
541 |
else if String.isPrefix "Invalid" outcome |
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
542 |
then (priority (goalstring ^ "is not provable"); |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
543 |
decr_watched()) |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
544 |
else if String.isPrefix "Failure" outcome |
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
545 |
then (priority (goalstring ^ "proof attempt failed"); |
17435 | 546 |
decr_watched()) |
17216 | 547 |
(* print out a list of rules used from clasimpset*) |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
548 |
else if String.isPrefix "Success" outcome |
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
549 |
then (priority (goalstring^outcome); |
17435 | 550 |
decr_watched()) |
17216 | 551 |
(* if proof translation failed *) |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
552 |
else if String.isPrefix "Translation failed" outcome |
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
553 |
then (priority (goalstring ^ outcome); |
17435 | 554 |
decr_watched()) |
17690
8ba7c3cd24a8
time limit option; fixed bug concerning first line of ATP output
paulson
parents:
17583
diff
changeset
|
555 |
else (priority "System error in proof handler"; |
17435 | 556 |
decr_watched()) |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
557 |
end |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
558 |
in IsaSignal.signal (IsaSignal.usr2, IsaSignal.SIG_HANDLE proofHandler); |
17216 | 559 |
(childin, childout, childpid) |
560 |
end |
|
15642 | 561 |
|
562 |
end (* structure Watcher *) |