author | paulson |
Fri, 02 Sep 2005 15:25:44 +0200 | |
changeset 17231 | f42bc4f7afdf |
parent 17216 | df66d8feec63 |
child 17234 | 12a9393c5d77 |
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 |
||
16 |
(*use "Proof_Transfer"; |
|
17 |
use "VampireCommunication"; |
|
16089
9169bdf930f8
trying to set up portable calling sequences for SPASS and tptp2X
paulson
parents:
16061
diff
changeset
|
18 |
use "SpassCommunication";*) |
15642 | 19 |
(*use "/homes/clq20/Jia_Code/TransStartIsar";*) |
20 |
||
21 |
||
22 |
structure Watcher: WATCHER = |
|
23 |
struct |
|
24 |
||
16805 | 25 |
open ReconPrelim Recon_Transfer |
26 |
||
15642 | 27 |
val goals_being_watched = ref 0; |
28 |
||
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
29 |
(*****************************************) |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
30 |
(* 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
|
31 |
(*****************************************) |
15642 | 32 |
|
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
33 |
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
|
34 |
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
|
35 |
instr : TextIO.instream, |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
36 |
outstr : TextIO.outstream |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
37 |
}; |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
38 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
39 |
(*****************************************) |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
40 |
(* 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
|
41 |
(*****************************************) |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
42 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
43 |
datatype cmdproc = CMDPROC of { |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
44 |
prover: string, (* Name of the resolution prover used, e.g. Vampire, SPASS *) |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
45 |
cmd: string, (* The file containing the goal for res prover to prove *) |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
46 |
thmstring: string, (* string representation of subgoal after negation, skolemization*) |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
47 |
goalstring: string, (* string representation of subgoal*) |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
48 |
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
|
49 |
instr : TextIO.instream, (* Input stream to child process *) |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
50 |
outstr : TextIO.outstream (* Output stream from child process *) |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
51 |
}; |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
52 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
53 |
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
|
54 |
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
|
55 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
56 |
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
|
57 |
|
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 |
fun reap(pid, instr, outstr) = |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
60 |
let |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
61 |
val u = TextIO.closeIn instr; |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
62 |
val u = TextIO.closeOut outstr; |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
63 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
64 |
val (_, status) = |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
65 |
Posix.Process.waitpid(Posix.Process.W_CHILD pid, []) |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
66 |
in |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
67 |
status |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
68 |
end |
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 |
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
|
71 |
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
|
72 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
73 |
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
|
74 |
Posix.IO.mkTextWriter { |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
75 |
appendMode = false, |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
76 |
initBlkMode = true, |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
77 |
name = name, |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
78 |
chunkSize=4096, |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
79 |
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 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
82 |
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
|
83 |
TextIO.mkOutstream ( |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
84 |
TextIO.StreamIO.mkOutstream ( |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
85 |
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
|
86 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
87 |
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
|
88 |
TextIO.mkInstream ( |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
89 |
TextIO.StreamIO.mkInstream ( |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
90 |
fdReader (name, fd), "")); |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
91 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
92 |
fun killChild child_handle = Unix.reap child_handle |
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 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
|
95 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
96 |
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
|
97 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
98 |
fun cmdInStream (CMDPROC{instr,outstr,...}) = (instr); |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
99 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
100 |
fun cmdchildInfo (CMDPROC{prover,cmd,thmstring,proc_handle,goalstring,instr,outstr}) = (prover,(cmd, (instr,outstr))); |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
101 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
102 |
fun cmdchildHandle (CMDPROC{prover,cmd,thmstring,goalstring,proc_handle,instr,outstr}) = proc_handle; |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
103 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
104 |
fun cmdProver (CMDPROC{prover,cmd,thmstring,goalstring,proc_handle,instr,outstr}) = (prover); |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
105 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
106 |
fun cmdThm (CMDPROC{prover,cmd,thmstring,goalstring,proc_handle,instr,outstr}) = (thmstring); |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
107 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
108 |
fun cmdGoal (CMDPROC{prover,cmd,thmstring,goalstring,proc_handle,instr,outstr}) = (goalstring); |
15642 | 109 |
|
110 |
fun sendOutput (outstr,str) = (TextIO.outputSubstr (outstr, (Substring.all str));TextIO.flushOut outstr); |
|
111 |
||
112 |
(********************************************************************************************) |
|
113 |
(* takes a list of arguments and sends them individually to the watcher process by pipe *) |
|
114 |
(********************************************************************************************) |
|
115 |
||
116 |
fun outputArgs (toWatcherStr, []) = () |
|
117 |
| outputArgs (toWatcherStr, (x::xs)) = (TextIO.output (toWatcherStr, x); |
|
118 |
TextIO.flushOut toWatcherStr; |
|
119 |
outputArgs (toWatcherStr, xs)) |
|
120 |
||
121 |
(********************************************************************************) |
|
122 |
(* gets individual args from instream and concatenates them into a list *) |
|
123 |
(********************************************************************************) |
|
124 |
||
125 |
fun getArgs (fromParentStr, toParentStr,ys) = let |
|
126 |
val thisLine = TextIO.input fromParentStr |
|
127 |
in |
|
128 |
((ys@[thisLine])) |
|
129 |
end |
|
130 |
||
131 |
(********************************************************************************) |
|
132 |
(* Remove the \n character from the end of each filename *) |
|
133 |
(********************************************************************************) |
|
134 |
||
16478 | 135 |
(*fun getCmd cmdStr = let val backList = ((rev(explode cmdStr))) |
15642 | 136 |
in |
137 |
if (String.isPrefix "\n" (implode backList )) |
|
16089
9169bdf930f8
trying to set up portable calling sequences for SPASS and tptp2X
paulson
parents:
16061
diff
changeset
|
138 |
then (implode (rev ((tl backList)))) |
9169bdf930f8
trying to set up portable calling sequences for SPASS and tptp2X
paulson
parents:
16061
diff
changeset
|
139 |
else cmdStr |
16478 | 140 |
end*) |
15642 | 141 |
|
142 |
(********************************************************************************) |
|
143 |
(* Send request to Watcher for a vampire to be called for filename in arg *) |
|
144 |
(********************************************************************************) |
|
145 |
||
17231 | 146 |
fun callResProver (toWatcherStr, arg) = |
147 |
(sendOutput (toWatcherStr, arg^"\n"); |
|
148 |
TextIO.flushOut toWatcherStr) |
|
15642 | 149 |
|
150 |
(*****************************************************************************************) |
|
16357 | 151 |
(* Send request to Watcher for multiple provers to be called for filenames in arg *) |
152 |
(* need to do the dfg stuff in the watcher, not here! send over the clasimp and stuff files too*) |
|
15642 | 153 |
(*****************************************************************************************) |
154 |
||
16357 | 155 |
|
15642 | 156 |
(* need to modify to send over hyps file too *) |
16475 | 157 |
fun callResProvers (toWatcherStr, []) = |
158 |
(sendOutput (toWatcherStr, "End of calls\n"); TextIO.flushOut toWatcherStr) |
|
159 |
| callResProvers (toWatcherStr, |
|
160 |
(prover,thmstring,goalstring, proverCmd,settings,clasimpfile, |
|
161 |
axfile, hypsfile,probfile) :: args) = |
|
162 |
let val _ = File.write (File.tmp_path (Path.basic "tog_comms")) |
|
163 |
(prover^thmstring^goalstring^proverCmd^settings^ |
|
164 |
clasimpfile^hypsfile^probfile) |
|
165 |
in sendOutput (toWatcherStr, |
|
16675 | 166 |
(prover^"$"^thmstring^"$"^goalstring^"$"^proverCmd^"$"^ |
167 |
settings^"$"^clasimpfile^"$"^hypsfile^"$"^probfile^"\n")); |
|
16475 | 168 |
goals_being_watched := (!goals_being_watched) + 1; |
169 |
TextIO.flushOut toWatcherStr; |
|
170 |
callResProvers (toWatcherStr,args) |
|
171 |
end |
|
16357 | 172 |
|
16156
2f6fc19aba1e
Fixed array containing clasimpset rules. Added flags to turn on and off reconstruction and full spass
quigley
parents:
16100
diff
changeset
|
173 |
|
15782 | 174 |
(* |
15642 | 175 |
fun callResProversStr (toWatcherStr, []) = "End of calls\n" |
176 |
||
15782 | 177 |
| callResProversStr (toWatcherStr,(prover,thmstring,goalstring, proverCmd,settings,clasimpfile, axfile, hypsfile, probfile)::args) = |
178 |
((prover^"*"^thmstring^"*"^goalstring^"*"^proverCmd^"*"^settings^"*"^clasimpfile^"*"^axfile^"*"^hypsfile^"*"^probfile^"\n") |
|
15642 | 179 |
|
15782 | 180 |
*) |
15642 | 181 |
|
182 |
(**************************************************************) |
|
183 |
(* Send message to watcher to kill currently running vampires *) |
|
184 |
(**************************************************************) |
|
185 |
||
186 |
fun callSlayer (toWatcherStr) = (sendOutput (toWatcherStr, "Kill vampires\n"); |
|
187 |
TextIO.flushOut toWatcherStr) |
|
188 |
||
189 |
||
190 |
||
191 |
(**************************************************************) |
|
192 |
(* Remove \n token from a vampire goal filename and extract *) |
|
193 |
(* prover, proverCmd, settings and file from input string *) |
|
194 |
(**************************************************************) |
|
195 |
||
196 |
||
197 |
fun takeUntil ch [] res = (res, []) |
|
17216 | 198 |
| takeUntil ch (x::xs) res = |
199 |
if x = ch then (res, xs) |
|
200 |
else takeUntil ch xs (res@[x]) |
|
15642 | 201 |
|
202 |
fun getSettings [] settings = settings |
|
17216 | 203 |
| getSettings (xs) settings = |
204 |
let val (set, rest ) = takeUntil "%" xs [] |
|
205 |
in |
|
206 |
getSettings rest (settings@[(implode set)]) |
|
207 |
end |
|
15642 | 208 |
|
16475 | 209 |
fun separateFields str = |
210 |
let val outfile = TextIO.openAppend(*("sep_field")*)(File.platform_path(File.tmp_path (Path.basic "sep_field"))) |
|
211 |
val _ = TextIO.output (outfile,("In separateFields, str is: "^(implode str)^"\n\n") ) |
|
212 |
val _ = TextIO.closeOut outfile |
|
16675 | 213 |
val (prover, rest) = takeUntil "$" str [] |
16475 | 214 |
val prover = implode prover |
16357 | 215 |
|
16675 | 216 |
val (thmstring, rest) = takeUntil "$" rest [] |
16475 | 217 |
val thmstring = implode thmstring |
16357 | 218 |
|
16675 | 219 |
val (goalstring, rest) = takeUntil "$" rest [] |
16475 | 220 |
val goalstring = implode goalstring |
16357 | 221 |
|
16675 | 222 |
val (proverCmd, rest ) = takeUntil "$" rest [] |
16475 | 223 |
val proverCmd = implode proverCmd |
224 |
||
16675 | 225 |
val (settings, rest) = takeUntil "$" rest [] |
16475 | 226 |
val settings = getSettings settings [] |
16357 | 227 |
|
16675 | 228 |
val (clasimpfile, rest ) = takeUntil "$" rest [] |
16475 | 229 |
val clasimpfile = implode clasimpfile |
230 |
||
16675 | 231 |
val (hypsfile, rest ) = takeUntil "$" rest [] |
16475 | 232 |
val hypsfile = implode hypsfile |
15642 | 233 |
|
16675 | 234 |
val (file, rest) = takeUntil "$" rest [] |
16475 | 235 |
val file = implode file |
236 |
||
237 |
val _ = File.append (File.tmp_path (Path.basic "sep_comms")) |
|
238 |
("Sep comms are: "^(implode str)^"**"^ |
|
16675 | 239 |
prover^" thmstring: "^thmstring^"\n goalstr: "^goalstring^" \n provercmd: "^proverCmd^" \n clasimp "^clasimpfile^" \n hyps "^hypsfile^"\n prob "^file^"\n\n") |
16475 | 240 |
in |
241 |
(prover,thmstring,goalstring, proverCmd, settings, clasimpfile, hypsfile, file) |
|
242 |
end |
|
243 |
||
16357 | 244 |
|
245 |
(***********************************************************************************) |
|
246 |
(* do tptp2x and cat to turn clasimpfile, hypsfile and probfile into one .dfg file *) |
|
247 |
(***********************************************************************************) |
|
248 |
||
249 |
fun formatCmd (prover,thmstring,goalstring, proverCmd, settings, clasimpfile, hypsfile ,probfile) = |
|
16475 | 250 |
let |
251 |
(*** want to cat clasimp ax hyps prob, then send the resulting file to tptp2x ***) |
|
252 |
val probID = List.last(explode probfile) |
|
253 |
val wholefile = File.tmp_path (Path.basic ("ax_prob_" ^ probID)) |
|
254 |
||
255 |
(*** only include problem and clasimp for the moment, not sure |
|
256 |
how to refer to hyps/local axioms just now ***) |
|
257 |
val whole_prob_file = Unix.execute("/bin/cat", |
|
258 |
[clasimpfile,(*axfile, hypsfile,*)probfile, ">", |
|
259 |
File.platform_path wholefile]) |
|
260 |
||
261 |
val dfg_dir = File.tmp_path (Path.basic "dfg"); |
|
262 |
val dfg_path = File.platform_path dfg_dir; |
|
263 |
||
16561 | 264 |
(*** want to cat clasimp ax hyps prob, then send the resulting file to tptp2x ***) |
265 |
val probID = List.last(explode probfile) |
|
266 |
val wholefile = File.tmp_path (Path.basic ("ax_prob_"^probID)) |
|
16478 | 267 |
|
16561 | 268 |
(*** only include problem and clasimp for the moment, not sure how to refer to ***) |
269 |
(*** hyps/local axioms just now ***) |
|
270 |
val whole_prob_file = Unix.execute("/bin/cat", [clasimpfile,(*axfile, hypsfile,*)probfile, ">", (File.platform_path wholefile)]) |
|
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
17121
diff
changeset
|
271 |
|
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
17121
diff
changeset
|
272 |
(* if using spass prob_n already contains whole DFG file, otherwise need to mash axioms*) |
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
17121
diff
changeset
|
273 |
(* from clasimpset onto problem file *) |
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
17121
diff
changeset
|
274 |
val newfile = if !SpassComm.spass |
17231 | 275 |
then probfile |
276 |
else (File.platform_path wholefile) |
|
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
17121
diff
changeset
|
277 |
|
16561 | 278 |
val _ = File.append (File.tmp_path (Path.basic"thmstring_in_watcher")) |
279 |
(thmstring^"\n goals_watched"^(string_of_int(!goals_being_watched))^newfile^"\n") |
|
280 |
in |
|
281 |
(prover,thmstring,goalstring, proverCmd, settings,newfile) |
|
282 |
end; |
|
16478 | 283 |
|
16357 | 284 |
|
285 |
||
286 |
(* remove \n from end of command and put back into tuple format *) |
|
287 |
||
288 |
||
16478 | 289 |
(* val cmdStr = "spass*((ALL xa. (~ P x | P xa) & (~ P xa | P x)) & (P xa | (ALL x. P x)) & ((ALL x. ~ P x) | ~ P xb) [.])*(EX x. ALL y. P x = P y) --> (EX x. P x) = (ALL y. P y)*/homes/clq20/bin/SPASS*-DocProof*/local/scratch/clq20/27023/clasimp*/local/scratch/clq20/27023/hyps*/local/scratch/clq20/27023/prob_1\n" |
290 |
||
291 |
val cmdStr = "vampire*(length (rev xs) = length xs [.]) & (length (rev (a # xs)) ~= length (a # xs) [.])*length (rev []) = length []*/homes/jm318/Vampire8/vkernel*-t 300%-m 100000*/local/scratch/clq20/23523/clasimp*/local/scratch/clq20/23523/hyps*/local/scratch/clq20/23523/prob_1\n" |
|
292 |
*) |
|
16357 | 293 |
|
294 |
(*FIX: are the two getCmd procs getting confused? Why do I have two anyway? *) |
|
15642 | 295 |
|
16475 | 296 |
fun getCmd cmdStr = |
297 |
let val backList = rev(explode cmdStr) |
|
298 |
val _ = File.append (File.tmp_path (Path.basic"cmdStr")) cmdStr |
|
299 |
in |
|
300 |
if (String.isPrefix "\n" (implode backList )) |
|
301 |
then |
|
302 |
let val newCmdStr = (rev(tl backList)) |
|
303 |
in File.write (File.tmp_path (Path.basic"backlist")) |
|
304 |
("about to call sepfields with "^(implode newCmdStr)); |
|
305 |
formatCmd (separateFields newCmdStr) |
|
306 |
end |
|
307 |
else formatCmd (separateFields (explode cmdStr)) |
|
308 |
end |
|
15642 | 309 |
|
310 |
||
311 |
fun getProofCmd (a,b,c,d,e,f) = d |
|
312 |
||
16357 | 313 |
|
15642 | 314 |
(**************************************************************) |
315 |
(* Get commands from Isabelle *) |
|
316 |
(**************************************************************) |
|
16357 | 317 |
(* FIX: or perhaps do the tptp2x stuff here - so it's get commands and then format them, before passing them to spass *) |
15642 | 318 |
|
319 |
fun getCmds (toParentStr,fromParentStr, cmdList) = |
|
16475 | 320 |
let val thisLine = TextIO.inputLine fromParentStr |
321 |
val _ = File.append (File.tmp_path (Path.basic "parent_comms")) thisLine |
|
322 |
in |
|
323 |
if (thisLine = "End of calls\n") |
|
324 |
then cmdList |
|
325 |
else if (thisLine = "Kill children\n") |
|
326 |
then |
|
327 |
( TextIO.output (toParentStr,thisLine ); |
|
328 |
TextIO.flushOut toParentStr; |
|
329 |
(("","","","Kill children",[],"")::cmdList) |
|
330 |
) |
|
331 |
else let val thisCmd = getCmd (thisLine) |
|
332 |
(*********************************************************) |
|
333 |
(* thisCmd = (prover,thmstring,proverCmd, settings, file)*) |
|
334 |
(* i.e. put back into tuple format *) |
|
335 |
(*********************************************************) |
|
336 |
in |
|
337 |
(*TextIO.output (toParentStr, thisCmd); |
|
338 |
TextIO.flushOut toParentStr;*) |
|
339 |
getCmds (toParentStr,fromParentStr, (thisCmd::cmdList)) |
|
340 |
end |
|
341 |
end |
|
342 |
||
16357 | 343 |
|
15642 | 344 |
(**************************************************************) |
345 |
(* Get Io-descriptor for polling of an input stream *) |
|
346 |
(**************************************************************) |
|
347 |
||
348 |
fun getInIoDesc someInstr = |
|
349 |
let val (rd, buf) = TextIO.StreamIO.getReader(TextIO.getInstream someInstr) |
|
15702
2677db44c795
new signalling primmitives for sml/nj compatibility
paulson
parents:
15684
diff
changeset
|
350 |
val _ = TextIO.output (TextIO.stdOut, buf) |
15642 | 351 |
val ioDesc = |
352 |
case rd |
|
353 |
of TextPrimIO.RD{ioDesc = SOME iod, ...} =>SOME iod |
|
354 |
| _ => NONE |
|
355 |
in (* since getting the reader will have terminated the stream, we need |
|
356 |
* to build a new stream. *) |
|
357 |
TextIO.setInstream(someInstr, TextIO.StreamIO.mkInstream(rd, buf)); |
|
358 |
ioDesc |
|
359 |
end |
|
360 |
||
361 |
||
362 |
(*************************************) |
|
363 |
(* Set up a Watcher Process *) |
|
364 |
(*************************************) |
|
365 |
||
16061 | 366 |
fun setupWatcher (thm,clause_arr, num_of_clauses) = |
367 |
let |
|
368 |
(** pipes for communication between parent and watcher **) |
|
369 |
val p1 = Posix.IO.pipe () |
|
370 |
val p2 = Posix.IO.pipe () |
|
371 |
fun closep () = ( |
|
372 |
Posix.IO.close (#outfd p1); |
|
373 |
Posix.IO.close (#infd p1); |
|
374 |
Posix.IO.close (#outfd p2); |
|
375 |
Posix.IO.close (#infd p2) |
|
376 |
) |
|
377 |
(***********************************************************) |
|
378 |
(****** fork a watcher process and get it set up and going *) |
|
379 |
(***********************************************************) |
|
380 |
fun startWatcher (procList) = |
|
381 |
(case Posix.Process.fork() (***************************************) |
|
382 |
of SOME pid => pid (* parent - i.e. main Isabelle process *) |
|
383 |
(***************************************) |
|
384 |
||
385 |
(*************************) |
|
386 |
| NONE => let (* child - i.e. watcher *) |
|
387 |
val oldchildin = #infd p1 (*************************) |
|
388 |
val fromParent = Posix.FileSys.wordToFD 0w0 |
|
389 |
val oldchildout = #outfd p2 |
|
390 |
val toParent = Posix.FileSys.wordToFD 0w1 |
|
391 |
val fromParentIOD = Posix.FileSys.fdToIOD fromParent |
|
392 |
val fromParentStr = openInFD ("_exec_in_parent", fromParent) |
|
393 |
val toParentStr = openOutFD ("_exec_out_parent", toParent) |
|
394 |
val sign = sign_of_thm thm |
|
395 |
val prems = prems_of thm |
|
396 |
val prems_string = Meson.concat_with_and (map (Sign.string_of_term sign) prems) |
|
397 |
val _ = (warning ("subgoals forked to startWatcher: "^prems_string)); |
|
398 |
(* tracing *) |
|
399 |
(*val tenth_ax = fst( Array.sub(clause_arr, 1)) |
|
400 |
val tenth_ax_thms = memo_find_clause (tenth_ax, clause_tab) |
|
401 |
val clause_str = Meson.concat_with_and (map string_of_thm tenth_ax_thms) |
|
402 |
val _ = (warning ("tenth axiom in array in watcher is: "^tenth_ax)) |
|
403 |
val _ = (warning ("tenth axiom in table in watcher is: "^clause_str)) |
|
404 |
val _ = (warning ("num_of_clauses in watcher is: "^(string_of_int (num_of_clauses))) ) |
|
405 |
*) |
|
406 |
(*val goalstr = string_of_thm (the_goal) |
|
16260 | 407 |
val outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "goal_in_watcher"))); |
16061 | 408 |
val _ = TextIO.output (outfile,goalstr ) |
409 |
val _ = TextIO.closeOut outfile*) |
|
410 |
fun killChildren [] = () |
|
411 |
| killChildren (child_handle::children) = (killChild child_handle; killChildren children) |
|
15642 | 412 |
|
16061 | 413 |
(*************************************************************) |
414 |
(* take an instream and poll its underlying reader for input *) |
|
415 |
(*************************************************************) |
|
15642 | 416 |
|
16061 | 417 |
fun pollParentInput () = |
16475 | 418 |
let val pd = OS.IO.pollDesc (fromParentIOD) |
419 |
in |
|
420 |
if (isSome pd ) then |
|
421 |
let val pd' = OS.IO.pollIn (valOf pd) |
|
422 |
val pdl = OS.IO.poll ([pd'], SOME (Time.fromMilliseconds 2000)) |
|
423 |
val _ = File.append (File.tmp_path (Path.basic "parent_poll")) |
|
424 |
("In parent_poll\n") |
|
425 |
in |
|
426 |
if null pdl |
|
427 |
then |
|
428 |
NONE |
|
429 |
else if (OS.IO.isIn (hd pdl)) |
|
17231 | 430 |
then SOME (getCmds (toParentStr, fromParentStr, [])) |
431 |
else NONE |
|
16475 | 432 |
end |
17231 | 433 |
else NONE |
16475 | 434 |
end |
16061 | 435 |
|
436 |
fun pollChildInput (fromStr) = |
|
17216 | 437 |
let val _ = File.append (File.tmp_path (Path.basic "child_poll")) |
438 |
("In child_poll\n") |
|
439 |
val iod = getInIoDesc fromStr |
|
440 |
in |
|
441 |
if isSome iod |
|
442 |
then |
|
443 |
let val pd = OS.IO.pollDesc (valOf iod) |
|
16478 | 444 |
in |
17216 | 445 |
if (isSome pd ) then |
446 |
let val pd' = OS.IO.pollIn (valOf pd) |
|
447 |
val pdl = OS.IO.poll ([pd'], SOME (Time.fromMilliseconds 2000)) |
|
448 |
in |
|
449 |
if null pdl |
|
450 |
then |
|
451 |
( File.append (File.tmp_path (Path.basic "child_poll_res")) |
|
452 |
("Null pdl \n");NONE) |
|
453 |
else if (OS.IO.isIn (hd pdl)) |
|
454 |
then |
|
455 |
(let val inval = (TextIO.inputLine fromStr) |
|
456 |
val _ = File.append (File.tmp_path (Path.basic "child_poll_res")) (inval^"\n") |
|
457 |
in |
|
458 |
SOME inval |
|
459 |
end) |
|
460 |
else |
|
461 |
( File.append (File.tmp_path (Path.basic "child_poll_res")) |
|
462 |
("Null pdl \n");NONE) |
|
463 |
end |
|
464 |
else NONE |
|
465 |
end |
|
466 |
else NONE |
|
467 |
end |
|
15642 | 468 |
|
469 |
||
16061 | 470 |
(****************************************************************************) |
471 |
(* Check all vampire processes currently running for output *) |
|
472 |
(****************************************************************************) |
|
473 |
(*********************************) |
|
474 |
fun checkChildren ([], toParentStr) = [] (*** no children to check ********) |
|
475 |
(*********************************) |
|
476 |
| checkChildren ((childProc::otherChildren), toParentStr) = |
|
16357 | 477 |
let val _ = File.append (File.tmp_path (Path.basic "child_check")) |
478 |
("In check child, length of queue:"^(string_of_int (length (childProc::otherChildren)))^"\n") |
|
479 |
val (childInput,childOutput) = cmdstreamsOf childProc |
|
16061 | 480 |
val child_handle= cmdchildHandle childProc |
481 |
(* childCmd is the .dfg file that the problem is in *) |
|
482 |
val childCmd = fst(snd (cmdchildInfo childProc)) |
|
16357 | 483 |
val _ = File.append (File.tmp_path (Path.basic "child_command")) |
484 |
(childCmd^"\n") |
|
16061 | 485 |
(* now get the number of the subgoal from the filename *) |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
17121
diff
changeset
|
486 |
val sg_num = (*if (!SpassComm.spass ) |
16520 | 487 |
then |
488 |
int_of_string(ReconOrderClauses.get_nth 5 (rev(explode childCmd))) |
|
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
17121
diff
changeset
|
489 |
else*) |
16520 | 490 |
int_of_string(hd (rev(explode childCmd))) |
491 |
||
16061 | 492 |
val childIncoming = pollChildInput childInput |
16357 | 493 |
val _ = File.append (File.tmp_path (Path.basic "child_check_polled")) |
494 |
("finished polling child \n") |
|
16061 | 495 |
val parentID = Posix.ProcEnv.getppid() |
496 |
val prover = cmdProver childProc |
|
497 |
val thmstring = cmdThm childProc |
|
498 |
val sign = sign_of_thm thm |
|
499 |
val prems = prems_of thm |
|
500 |
val prems_string = Meson.concat_with_and (map (Sign.string_of_term sign) prems) |
|
16100 | 501 |
val _ = warning("subgoals forked to checkChildren: "^prems_string) |
502 |
val goalstring = cmdGoal childProc |
|
16357 | 503 |
val _ = File.append (File.tmp_path (Path.basic "child_comms")) |
504 |
(prover^thmstring^goalstring^childCmd^"\n") |
|
16061 | 505 |
in |
506 |
if (isSome childIncoming) |
|
507 |
then |
|
508 |
(* check here for prover label on child*) |
|
17231 | 509 |
let val _ = File.write (File.tmp_path (Path.basic "child_incoming")) |
510 |
("subgoals forked to checkChildren:"^ |
|
511 |
prems_string^prover^thmstring^goalstring^childCmd) |
|
16478 | 512 |
val childDone = (case prover of |
513 |
"vampire" => (VampComm.checkVampProofFound(childInput, toParentStr, parentID,thmstring,goalstring, childCmd, thm, sg_num,clause_arr, num_of_clauses) ) |
|
514 |
|"spass" => (SpassComm.checkSpassProofFound(childInput, toParentStr, parentID,thmstring,goalstring, childCmd, thm, sg_num,clause_arr, num_of_clauses) ) ) |
|
16061 | 515 |
in |
516 |
if childDone (**********************************************) |
|
17216 | 517 |
then (* child has found a proof and transferred it *) |
16061 | 518 |
(* Remove this child and go on to check others*) |
519 |
(**********************************************) |
|
17216 | 520 |
(Unix.reap child_handle; |
521 |
checkChildren(otherChildren, toParentStr)) |
|
16061 | 522 |
else |
523 |
(**********************************************) |
|
524 |
(* Keep this child and go on to check others *) |
|
525 |
(**********************************************) |
|
17216 | 526 |
(childProc::(checkChildren (otherChildren, toParentStr))) |
16061 | 527 |
end |
528 |
else |
|
16100 | 529 |
(File.append (File.tmp_path (Path.basic "child_incoming")) "No child output "; |
530 |
childProc::(checkChildren (otherChildren, toParentStr))) |
|
16061 | 531 |
end |
15642 | 532 |
|
16061 | 533 |
|
534 |
(********************************************************************) |
|
535 |
(* call resolution processes *) |
|
536 |
(* settings should be a list of strings *) |
|
16520 | 537 |
(* e.g. ["-t 300", "-m 100000"] (TextIO.input instr)^ *) |
16061 | 538 |
(* takes list of (string, string, string list, string)list proclist *) |
539 |
(********************************************************************) |
|
15642 | 540 |
|
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
541 |
|
16061 | 542 |
(*** add subgoal id num to this *) |
543 |
fun execCmds [] procList = procList |
|
16561 | 544 |
| execCmds ((prover, thmstring,goalstring,proverCmd,settings,file)::cmds) procList = let val _ = File.append (File.tmp_path (Path.basic "pre_exec_child")) ("\nAbout to execute command for goal:\n"^goalstring^proverCmd^(concat settings)^file^" at "^(Date.toString(Date.fromTimeLocal(Time.now())))) |
16357 | 545 |
in |
546 |
if (prover = "spass") |
|
16561 | 547 |
then |
548 |
let val childhandle:(TextIO.instream,TextIO.outstream) Unix.proc = |
|
549 |
(Unix.execute(proverCmd, (["-FullRed=0"]@settings@[file]))) |
|
550 |
val (instr, outstr) = Unix.streamsOf childhandle |
|
551 |
val newProcList = (((CMDPROC{ |
|
552 |
prover = prover, |
|
553 |
cmd = file, |
|
554 |
thmstring = thmstring, |
|
555 |
goalstring = goalstring, |
|
556 |
proc_handle = childhandle, |
|
557 |
instr = instr, |
|
558 |
outstr = outstr })::procList)) |
|
559 |
val _ = File.append (File.tmp_path (Path.basic "exec_child")) |
|
560 |
("\nexecuting command for goal:\n"^ |
|
561 |
goalstring^proverCmd^(concat settings)^file^" at "^(Date.toString(Date.fromTimeLocal(Time.now())))) |
|
562 |
in |
|
563 |
Posix.Process.sleep (Time.fromSeconds 1);execCmds cmds newProcList |
|
564 |
end |
|
565 |
else |
|
566 |
let val childhandle:(TextIO.instream,TextIO.outstream) Unix.proc = |
|
567 |
(Unix.execute(proverCmd, (settings@[file]))) |
|
568 |
val (instr, outstr) = Unix.streamsOf childhandle |
|
569 |
||
17216 | 570 |
val newProcList = (CMDPROC{ |
16561 | 571 |
prover = prover, |
572 |
cmd = file, |
|
573 |
thmstring = thmstring, |
|
574 |
goalstring = goalstring, |
|
575 |
proc_handle = childhandle, |
|
576 |
instr = instr, |
|
17216 | 577 |
outstr = outstr }) :: procList |
16561 | 578 |
|
17216 | 579 |
val _ = File.append (File.tmp_path (Path.basic "exec_child")) |
580 |
("executing command for goal:\n"^ |
|
581 |
goalstring^proverCmd^(concat settings)^file^ |
|
582 |
" at "^(Date.toString(Date.fromTimeLocal(Time.now())))) |
|
16561 | 583 |
in |
584 |
Posix.Process.sleep (Time.fromSeconds 1); execCmds cmds newProcList |
|
585 |
end |
|
16357 | 586 |
end |
15642 | 587 |
|
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
588 |
|
16061 | 589 |
(****************************************) |
590 |
(* call resolution processes remotely *) |
|
591 |
(* settings should be a list of strings *) |
|
592 |
(* e.g. ["-t 300", "-m 100000"] *) |
|
593 |
(****************************************) |
|
594 |
||
595 |
(* fun execRemoteCmds [] procList = procList |
|
596 |
| execRemoteCmds ((prover, thmstring,goalstring,proverCmd ,settings,file)::cmds) procList = |
|
597 |
let val newProcList = mySshExecuteToList ("/usr/bin/ssh",([prover,thmstring,goalstring,"-t", "shep"]@[proverCmd]@settings@[file]), procList) |
|
598 |
in |
|
599 |
execRemoteCmds cmds newProcList |
|
600 |
end |
|
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
601 |
*) |
15642 | 602 |
|
16061 | 603 |
fun printList (outStr, []) = () |
604 |
| printList (outStr, (x::xs)) = (TextIO.output (outStr, x);TextIO.flushOut outStr; printList (outStr,xs)) |
|
15642 | 605 |
|
606 |
||
16061 | 607 |
(**********************************************) |
608 |
(* Watcher Loop *) |
|
609 |
(**********************************************) |
|
610 |
||
611 |
fun keepWatching (toParentStr, fromParentStr,procList) = |
|
17216 | 612 |
let fun loop (procList) = |
613 |
let val cmdsFromIsa = pollParentInput () |
|
614 |
fun killchildHandler (n:int) = |
|
615 |
(TextIO.output(toParentStr, "Killing child proof processes!\n"); |
|
616 |
TextIO.flushOut toParentStr; |
|
617 |
killChildren (map (cmdchildHandle) procList); |
|
618 |
()) |
|
619 |
in |
|
620 |
(*Signal.signal (Posix.Signal.usr2, Signal.SIG_HANDLE killchildHandler);*) |
|
621 |
(**********************************) |
|
622 |
if (isSome cmdsFromIsa) |
|
623 |
then (* deal with input from Isabelle *) |
|
624 |
if (getProofCmd(hd(valOf cmdsFromIsa)) = "Kill children" ) |
|
625 |
then |
|
626 |
let val child_handles = map cmdchildHandle procList |
|
627 |
in |
|
628 |
killChildren child_handles; |
|
629 |
(*Posix.Process.kill(Posix.Process.K_PROC (Posix.ProcEnv.getppid()), Posix.Signal.usr2);*) |
|
630 |
loop ([]) |
|
631 |
end |
|
632 |
else |
|
633 |
if ((length procList)<10) (********************) |
|
634 |
then (* Execute locally *) |
|
635 |
let |
|
636 |
val newProcList = execCmds (valOf cmdsFromIsa) procList |
|
637 |
val parentID = Posix.ProcEnv.getppid() |
|
638 |
val _ = (File.append (File.tmp_path (Path.basic "prekeep_watch")) "Just execed a child\n ") |
|
639 |
val newProcList' =checkChildren (newProcList, toParentStr) |
|
16357 | 640 |
|
17216 | 641 |
val _ = warning("off to keep watching...") |
642 |
val _ = (File.append (File.tmp_path (Path.basic "keep_watch")) "Off to keep watching...\n ") |
|
643 |
in |
|
644 |
(*Posix.Process.sleep (Time.fromSeconds 1);*) |
|
645 |
loop (newProcList') |
|
646 |
end |
|
647 |
else (* Execute remotely *) |
|
648 |
(* (actually not remote for now )*) |
|
649 |
let |
|
650 |
val newProcList = execCmds (valOf cmdsFromIsa) procList |
|
651 |
val parentID = Posix.ProcEnv.getppid() |
|
652 |
val newProcList' =checkChildren (newProcList, toParentStr) |
|
653 |
in |
|
654 |
(*Posix.Process.sleep (Time.fromSeconds 1);*) |
|
655 |
loop (newProcList') |
|
656 |
end |
|
657 |
else (* No new input from Isabelle *) |
|
658 |
let val newProcList = checkChildren ((procList), toParentStr) |
|
659 |
in |
|
660 |
(*Posix.Process.sleep (Time.fromSeconds 1);*) |
|
661 |
(File.append (File.tmp_path (Path.basic "keep_watch")) "Off to keep watching.2..\n "); |
|
662 |
loop (newProcList) |
|
663 |
end |
|
664 |
end |
|
665 |
in |
|
666 |
loop (procList) |
|
667 |
end |
|
16061 | 668 |
|
669 |
||
670 |
in |
|
671 |
(***************************) |
|
672 |
(*** Sort out pipes ********) |
|
673 |
(***************************) |
|
15642 | 674 |
|
16061 | 675 |
Posix.IO.close (#outfd p1); |
676 |
Posix.IO.close (#infd p2); |
|
677 |
Posix.IO.dup2{old = oldchildin, new = fromParent}; |
|
678 |
Posix.IO.close oldchildin; |
|
679 |
Posix.IO.dup2{old = oldchildout, new = toParent}; |
|
680 |
Posix.IO.close oldchildout; |
|
15642 | 681 |
|
16061 | 682 |
(***************************) |
683 |
(* start the watcher loop *) |
|
684 |
(***************************) |
|
685 |
keepWatching (toParentStr, fromParentStr, procList); |
|
686 |
(****************************************************************************) |
|
17231 | 687 |
(* fake return value - actually want the watcher to loop until killed *) |
16061 | 688 |
(****************************************************************************) |
689 |
Posix.Process.wordToPid 0w0 |
|
690 |
end); |
|
691 |
(* end case *) |
|
15642 | 692 |
|
693 |
||
16061 | 694 |
val _ = TextIO.flushOut TextIO.stdOut |
15642 | 695 |
|
16061 | 696 |
(*******************************) |
697 |
(*** set watcher going ********) |
|
698 |
(*******************************) |
|
15642 | 699 |
|
16061 | 700 |
val procList = [] |
701 |
val pid = startWatcher (procList) |
|
702 |
(**************************************************) |
|
703 |
(* communication streams to watcher *) |
|
704 |
(**************************************************) |
|
15642 | 705 |
|
16061 | 706 |
val instr = openInFD ("_exec_in", #infd p2) |
707 |
val outstr = openOutFD ("_exec_out", #outfd p1) |
|
708 |
||
709 |
in |
|
710 |
(*******************************) |
|
711 |
(* close the child-side fds *) |
|
712 |
(*******************************) |
|
713 |
Posix.IO.close (#outfd p2); |
|
714 |
Posix.IO.close (#infd p1); |
|
715 |
(* set the fds close on exec *) |
|
716 |
Posix.IO.setfd (#infd p2, Posix.IO.FD.flags [Posix.IO.FD.cloexec]); |
|
717 |
Posix.IO.setfd (#outfd p1, Posix.IO.FD.flags [Posix.IO.FD.cloexec]); |
|
718 |
||
719 |
(*******************************) |
|
720 |
(* return value *) |
|
721 |
(*******************************) |
|
722 |
PROC{pid = pid, |
|
723 |
instr = instr, |
|
724 |
outstr = outstr |
|
725 |
} |
|
726 |
end; |
|
15642 | 727 |
|
728 |
||
729 |
||
730 |
(**********************************************************) |
|
731 |
(* Start a watcher and set up signal handlers *) |
|
732 |
(**********************************************************) |
|
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
733 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
734 |
fun killWatcher pid= Posix.Process.kill(Posix.Process.K_PROC pid, Posix.Signal.kill); |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
735 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
736 |
fun reapWatcher(pid, instr, outstr) = |
17216 | 737 |
let val u = TextIO.closeIn instr; |
738 |
val u = TextIO.closeOut outstr; |
|
739 |
val (_, status) = Posix.Process.waitpid(Posix.Process.W_CHILD pid, []) |
|
740 |
in |
|
741 |
status |
|
16100 | 742 |
end |
15642 | 743 |
|
17216 | 744 |
fun createWatcher (thm,clause_arr, ( num_of_clauses:int)) = |
745 |
let val mychild = childInfo (setupWatcher(thm,clause_arr, num_of_clauses)) |
|
17231 | 746 |
val streams = snd mychild |
17216 | 747 |
val childin = fst streams |
748 |
val childout = snd streams |
|
749 |
val childpid = fst mychild |
|
750 |
val sign = sign_of_thm thm |
|
751 |
val prems = prems_of thm |
|
752 |
val prems_string = Meson.concat_with_and (map (Sign.string_of_term sign) prems) |
|
753 |
val _ = (warning ("subgoals forked to createWatcher: "^prems_string)); |
|
754 |
fun vampire_proofHandler (n) = |
|
755 |
(Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")]))); |
|
756 |
VampComm.getVampInput childin; Pretty.writeln(Pretty.str (oct_char "361"))) |
|
757 |
fun spass_proofHandler (n) = ( |
|
758 |
let val outfile = TextIO.openAppend(File.platform_path(File.tmp_path (Path.basic "foo_signal1"))); |
|
759 |
val _ = TextIO.output (outfile, ("In signal handler now\n")) |
|
760 |
val _ = TextIO.closeOut outfile |
|
761 |
val (reconstr, goalstring, thmstring) = SpassComm.getSpassInput childin |
|
762 |
val outfile = TextIO.openAppend(File.platform_path(File.tmp_path (Path.basic "foo_signal"))); |
|
763 |
||
764 |
val _ = TextIO.output (outfile, ("In signal handler "^reconstr^thmstring^goalstring^"goals_being_watched is: "^(string_of_int (!goals_being_watched)))) |
|
765 |
val _ = TextIO.closeOut outfile |
|
766 |
in (* if a proof has been found and sent back as a reconstruction proof *) |
|
17231 | 767 |
if substring (reconstr, 0,1) = "[" |
17216 | 768 |
then (Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")]))); |
769 |
Recon_Transfer.apply_res_thm reconstr goalstring; |
|
770 |
Pretty.writeln(Pretty.str (oct_char "361")); |
|
771 |
||
772 |
goals_being_watched := ((!goals_being_watched) - 1); |
|
773 |
||
17231 | 774 |
if (!goals_being_watched) = 0 |
17216 | 775 |
then |
17231 | 776 |
let val _ = File.write (File.tmp_path (Path.basic "foo_reap_found")) |
777 |
("Reaping a watcher, goals watched is: "^ |
|
778 |
(string_of_int (!goals_being_watched))^"\n") |
|
17216 | 779 |
in |
780 |
killWatcher (childpid); reapWatcher (childpid,childin, childout); () |
|
17231 | 781 |
end |
17216 | 782 |
else () ) |
783 |
(* if there's no proof, but a message from Spass *) |
|
17231 | 784 |
else if substring (reconstr, 0,5) = "SPASS" |
17216 | 785 |
then (goals_being_watched := (!goals_being_watched) -1; |
786 |
Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")]))); |
|
787 |
Pretty.writeln(Pretty.str ((Recon_Transfer.restore_linebreaks goalstring)^reconstr)); |
|
788 |
Pretty.writeln(Pretty.str (oct_char "361")); |
|
789 |
if (!goals_being_watched = 0) |
|
790 |
then (File.write (File.tmp_path (Path.basic "foo_reap_comp")) |
|
791 |
("Reaping a watcher, goals watched is: " ^ |
|
792 |
(string_of_int (!goals_being_watched))^"\n"); |
|
793 |
killWatcher (childpid); reapWatcher (childpid,childin, childout); ()) |
|
794 |
else () ) |
|
795 |
(* print out a list of rules used from clasimpset*) |
|
17231 | 796 |
else if substring (reconstr, 0,5) = "Rules" |
17216 | 797 |
then (goals_being_watched := (!goals_being_watched) -1; |
798 |
Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")]))); |
|
799 |
Pretty.writeln(Pretty.str (goalstring^reconstr)); |
|
800 |
Pretty.writeln(Pretty.str (oct_char "361")); |
|
801 |
if (!goals_being_watched = 0) |
|
802 |
then (File.write (File.tmp_path (Path.basic "foo_reap_comp")) |
|
803 |
("Reaping a watcher, goals watched is: " ^ |
|
804 |
(string_of_int (!goals_being_watched))^"\n"); |
|
805 |
killWatcher (childpid); reapWatcher (childpid,childin, childout);() |
|
806 |
) |
|
807 |
else () ) |
|
808 |
(* if proof translation failed *) |
|
17231 | 809 |
else if substring (reconstr, 0,5) = "Proof" |
17216 | 810 |
then (goals_being_watched := (!goals_being_watched) -1; |
811 |
Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")]))); |
|
812 |
Pretty.writeln(Pretty.str (goalstring^(Recon_Transfer.restore_linebreaks reconstr))); |
|
813 |
Pretty.writeln(Pretty.str (oct_char "361")); |
|
814 |
if (!goals_being_watched = 0) |
|
815 |
then (File.write (File.tmp_path (Path.basic "foo_reap_comp")) |
|
816 |
("Reaping a watcher, goals watched is: " ^ |
|
817 |
(string_of_int (!goals_being_watched))^"\n"); |
|
818 |
killWatcher (childpid); reapWatcher (childpid,childin, childout);() |
|
819 |
) |
|
820 |
else () ) |
|
15642 | 821 |
|
17231 | 822 |
else if substring (reconstr, 0,1) = "%" |
17216 | 823 |
then (goals_being_watched := (!goals_being_watched) -1; |
824 |
Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")]))); |
|
825 |
Pretty.writeln(Pretty.str (goalstring^(Recon_Transfer.restore_linebreaks reconstr))); |
|
826 |
Pretty.writeln(Pretty.str (oct_char "361")); |
|
827 |
if (!goals_being_watched = 0) |
|
828 |
then (File.write (File.tmp_path (Path.basic "foo_reap_comp")) |
|
829 |
("Reaping a watcher, goals watched is: " ^ |
|
830 |
(string_of_int (!goals_being_watched))^"\n"); |
|
831 |
killWatcher (childpid); reapWatcher (childpid,childin, childout);() |
|
832 |
) |
|
833 |
else () ) |
|
834 |
||
835 |
else (* add something here ?*) |
|
836 |
(goals_being_watched := (!goals_being_watched) -1; |
|
837 |
Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")]))); |
|
17231 | 838 |
Pretty.writeln(Pretty.str ("Ran out of options in handler")); |
839 |
Pretty.writeln(Pretty.str (oct_char "361")); |
|
840 |
if (!goals_being_watched = 0) |
|
841 |
then (File.write (File.tmp_path (Path.basic "foo_reap_comp")) |
|
842 |
("Reaping a watcher, goals watched is: " ^ |
|
843 |
(string_of_int (!goals_being_watched))^"\n"); |
|
844 |
killWatcher (childpid); reapWatcher (childpid,childin, childout);() |
|
845 |
) |
|
846 |
else () ) |
|
17216 | 847 |
end) |
848 |
||
849 |
in IsaSignal.signal (IsaSignal.usr1, IsaSignal.SIG_HANDLE vampire_proofHandler); |
|
850 |
IsaSignal.signal (IsaSignal.usr2, IsaSignal.SIG_HANDLE spass_proofHandler); |
|
851 |
(childin, childout, childpid) |
|
852 |
||
853 |
end |
|
15642 | 854 |
|
855 |
end (* structure Watcher *) |