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