author | paulson |
Fri, 02 Sep 2005 17:55:24 +0200 | |
changeset 17234 | 12a9393c5d77 |
parent 17231 | f42bc4f7afdf |
child 17235 | 8e55ad29b690 |
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)^"**"^ |
|
17234 | 239 |
prover^" thmstring: "^thmstring^"\n goalstr: "^goalstring^ |
240 |
" \n provercmd: "^proverCmd^" \n clasimp "^clasimpfile^ |
|
241 |
" \n hyps "^hypsfile^"\n prob "^file^"\n\n") |
|
16475 | 242 |
in |
243 |
(prover,thmstring,goalstring, proverCmd, settings, clasimpfile, hypsfile, file) |
|
244 |
end |
|
245 |
||
16357 | 246 |
|
247 |
(***********************************************************************************) |
|
248 |
(* do tptp2x and cat to turn clasimpfile, hypsfile and probfile into one .dfg file *) |
|
249 |
(***********************************************************************************) |
|
250 |
||
251 |
fun formatCmd (prover,thmstring,goalstring, proverCmd, settings, clasimpfile, hypsfile ,probfile) = |
|
16475 | 252 |
let |
253 |
(*** want to cat clasimp ax hyps prob, then send the resulting file to tptp2x ***) |
|
254 |
val probID = List.last(explode probfile) |
|
255 |
val wholefile = File.tmp_path (Path.basic ("ax_prob_" ^ probID)) |
|
256 |
||
257 |
(*** only include problem and clasimp for the moment, not sure |
|
258 |
how to refer to hyps/local axioms just now ***) |
|
259 |
val whole_prob_file = Unix.execute("/bin/cat", |
|
17234 | 260 |
[clasimpfile,probfile, ">", |
16475 | 261 |
File.platform_path wholefile]) |
262 |
||
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
17121
diff
changeset
|
263 |
(* 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
|
264 |
(* from clasimpset onto problem file *) |
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
17121
diff
changeset
|
265 |
val newfile = if !SpassComm.spass |
17231 | 266 |
then probfile |
267 |
else (File.platform_path wholefile) |
|
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
17121
diff
changeset
|
268 |
|
16561 | 269 |
val _ = File.append (File.tmp_path (Path.basic"thmstring_in_watcher")) |
17234 | 270 |
(thmstring^"\n goals_watched"^ |
271 |
(string_of_int(!goals_being_watched))^newfile^"\n") |
|
16561 | 272 |
in |
273 |
(prover,thmstring,goalstring, proverCmd, settings,newfile) |
|
274 |
end; |
|
16478 | 275 |
|
16357 | 276 |
|
277 |
||
278 |
(* remove \n from end of command and put back into tuple format *) |
|
279 |
||
280 |
||
16478 | 281 |
(* 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" |
282 |
||
283 |
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" |
|
284 |
*) |
|
16357 | 285 |
|
286 |
(*FIX: are the two getCmd procs getting confused? Why do I have two anyway? *) |
|
15642 | 287 |
|
16475 | 288 |
fun getCmd cmdStr = |
289 |
let val backList = rev(explode cmdStr) |
|
290 |
val _ = File.append (File.tmp_path (Path.basic"cmdStr")) cmdStr |
|
291 |
in |
|
292 |
if (String.isPrefix "\n" (implode backList )) |
|
293 |
then |
|
294 |
let val newCmdStr = (rev(tl backList)) |
|
295 |
in File.write (File.tmp_path (Path.basic"backlist")) |
|
296 |
("about to call sepfields with "^(implode newCmdStr)); |
|
297 |
formatCmd (separateFields newCmdStr) |
|
298 |
end |
|
299 |
else formatCmd (separateFields (explode cmdStr)) |
|
300 |
end |
|
15642 | 301 |
|
302 |
||
303 |
fun getProofCmd (a,b,c,d,e,f) = d |
|
304 |
||
16357 | 305 |
|
15642 | 306 |
(**************************************************************) |
307 |
(* Get commands from Isabelle *) |
|
308 |
(**************************************************************) |
|
16357 | 309 |
(* FIX: or perhaps do the tptp2x stuff here - so it's get commands and then format them, before passing them to spass *) |
15642 | 310 |
|
311 |
fun getCmds (toParentStr,fromParentStr, cmdList) = |
|
16475 | 312 |
let val thisLine = TextIO.inputLine fromParentStr |
313 |
val _ = File.append (File.tmp_path (Path.basic "parent_comms")) thisLine |
|
314 |
in |
|
315 |
if (thisLine = "End of calls\n") |
|
316 |
then cmdList |
|
317 |
else if (thisLine = "Kill children\n") |
|
318 |
then |
|
319 |
( TextIO.output (toParentStr,thisLine ); |
|
320 |
TextIO.flushOut toParentStr; |
|
321 |
(("","","","Kill children",[],"")::cmdList) |
|
322 |
) |
|
323 |
else let val thisCmd = getCmd (thisLine) |
|
324 |
(*********************************************************) |
|
325 |
(* thisCmd = (prover,thmstring,proverCmd, settings, file)*) |
|
326 |
(* i.e. put back into tuple format *) |
|
327 |
(*********************************************************) |
|
328 |
in |
|
329 |
(*TextIO.output (toParentStr, thisCmd); |
|
330 |
TextIO.flushOut toParentStr;*) |
|
331 |
getCmds (toParentStr,fromParentStr, (thisCmd::cmdList)) |
|
332 |
end |
|
333 |
end |
|
334 |
||
16357 | 335 |
|
15642 | 336 |
(**************************************************************) |
337 |
(* Get Io-descriptor for polling of an input stream *) |
|
338 |
(**************************************************************) |
|
339 |
||
340 |
fun getInIoDesc someInstr = |
|
341 |
let val (rd, buf) = TextIO.StreamIO.getReader(TextIO.getInstream someInstr) |
|
15702
2677db44c795
new signalling primmitives for sml/nj compatibility
paulson
parents:
15684
diff
changeset
|
342 |
val _ = TextIO.output (TextIO.stdOut, buf) |
15642 | 343 |
val ioDesc = |
344 |
case rd |
|
345 |
of TextPrimIO.RD{ioDesc = SOME iod, ...} =>SOME iod |
|
346 |
| _ => NONE |
|
347 |
in (* since getting the reader will have terminated the stream, we need |
|
348 |
* to build a new stream. *) |
|
349 |
TextIO.setInstream(someInstr, TextIO.StreamIO.mkInstream(rd, buf)); |
|
350 |
ioDesc |
|
351 |
end |
|
352 |
||
353 |
||
354 |
(*************************************) |
|
355 |
(* Set up a Watcher Process *) |
|
356 |
(*************************************) |
|
357 |
||
16061 | 358 |
fun setupWatcher (thm,clause_arr, num_of_clauses) = |
359 |
let |
|
360 |
(** pipes for communication between parent and watcher **) |
|
361 |
val p1 = Posix.IO.pipe () |
|
362 |
val p2 = Posix.IO.pipe () |
|
363 |
fun closep () = ( |
|
364 |
Posix.IO.close (#outfd p1); |
|
365 |
Posix.IO.close (#infd p1); |
|
366 |
Posix.IO.close (#outfd p2); |
|
367 |
Posix.IO.close (#infd p2) |
|
368 |
) |
|
369 |
(***********************************************************) |
|
370 |
(****** fork a watcher process and get it set up and going *) |
|
371 |
(***********************************************************) |
|
372 |
fun startWatcher (procList) = |
|
17234 | 373 |
(case Posix.Process.fork() (***************************************) |
374 |
of SOME pid => pid (* parent - i.e. main Isabelle process *) |
|
375 |
(***************************************) |
|
16061 | 376 |
|
17234 | 377 |
(*************************) |
378 |
| NONE => let (* child - i.e. watcher *) |
|
379 |
val oldchildin = #infd p1 (*************************) |
|
380 |
val fromParent = Posix.FileSys.wordToFD 0w0 |
|
381 |
val oldchildout = #outfd p2 |
|
382 |
val toParent = Posix.FileSys.wordToFD 0w1 |
|
383 |
val fromParentIOD = Posix.FileSys.fdToIOD fromParent |
|
384 |
val fromParentStr = openInFD ("_exec_in_parent", fromParent) |
|
385 |
val toParentStr = openOutFD ("_exec_out_parent", toParent) |
|
386 |
val sign = sign_of_thm thm |
|
387 |
val prems = prems_of thm |
|
388 |
val prems_string = Meson.concat_with_and (map (Sign.string_of_term sign) prems) |
|
389 |
val _ = (warning ("subgoals forked to startWatcher: "^prems_string)); |
|
390 |
(* tracing *) |
|
391 |
(*val tenth_ax = fst( Array.sub(clause_arr, 1)) |
|
392 |
val tenth_ax_thms = memo_find_clause (tenth_ax, clause_tab) |
|
393 |
val clause_str = Meson.concat_with_and (map string_of_thm tenth_ax_thms) |
|
394 |
val _ = (warning ("tenth axiom in array in watcher is: "^tenth_ax)) |
|
395 |
val _ = (warning ("tenth axiom in table in watcher is: "^clause_str)) |
|
396 |
val _ = (warning ("num_of_clauses in watcher is: "^(string_of_int (num_of_clauses))) ) |
|
397 |
*) |
|
398 |
(*val goalstr = string_of_thm (the_goal) |
|
399 |
val outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "goal_in_watcher"))); |
|
400 |
val _ = TextIO.output (outfile,goalstr ) |
|
401 |
val _ = TextIO.closeOut outfile*) |
|
402 |
fun killChildren [] = () |
|
403 |
| killChildren (child_handle::children) = (killChild child_handle; killChildren children) |
|
15642 | 404 |
|
17234 | 405 |
(*************************************************************) |
406 |
(* take an instream and poll its underlying reader for input *) |
|
407 |
(*************************************************************) |
|
15642 | 408 |
|
17234 | 409 |
fun pollParentInput () = |
410 |
let val pd = OS.IO.pollDesc (fromParentIOD) |
|
411 |
in |
|
412 |
if (isSome pd ) then |
|
413 |
let val pd' = OS.IO.pollIn (valOf pd) |
|
414 |
val pdl = OS.IO.poll ([pd'], SOME (Time.fromMilliseconds 2000)) |
|
415 |
val _ = File.append (File.tmp_path (Path.basic "parent_poll")) |
|
416 |
("In parent_poll\n") |
|
417 |
in |
|
418 |
if null pdl |
|
419 |
then |
|
420 |
NONE |
|
421 |
else if (OS.IO.isIn (hd pdl)) |
|
422 |
then SOME (getCmds (toParentStr, fromParentStr, [])) |
|
423 |
else NONE |
|
424 |
end |
|
425 |
else NONE |
|
426 |
end |
|
427 |
||
428 |
fun pollChildInput (fromStr) = |
|
429 |
let val _ = File.append (File.tmp_path (Path.basic "child_poll")) |
|
430 |
("In child_poll\n") |
|
431 |
val iod = getInIoDesc fromStr |
|
432 |
in |
|
433 |
if isSome iod |
|
434 |
then |
|
435 |
let val pd = OS.IO.pollDesc (valOf iod) |
|
436 |
in |
|
437 |
if (isSome pd ) then |
|
438 |
let val pd' = OS.IO.pollIn (valOf pd) |
|
439 |
val pdl = OS.IO.poll ([pd'], SOME (Time.fromMilliseconds 2000)) |
|
440 |
in |
|
441 |
if null pdl |
|
442 |
then |
|
443 |
( File.append (File.tmp_path (Path.basic "child_poll_res")) |
|
444 |
("Null pdl \n");NONE) |
|
445 |
else if (OS.IO.isIn (hd pdl)) |
|
17216 | 446 |
then |
17234 | 447 |
(let val inval = (TextIO.inputLine fromStr) |
448 |
val _ = File.append (File.tmp_path (Path.basic "child_poll_res")) (inval^"\n") |
|
449 |
in |
|
450 |
SOME inval |
|
451 |
end) |
|
452 |
else |
|
453 |
( File.append (File.tmp_path (Path.basic "child_poll_res")) |
|
454 |
("Null pdl \n");NONE) |
|
455 |
end |
|
456 |
else NONE |
|
457 |
end |
|
458 |
else NONE |
|
459 |
end |
|
15642 | 460 |
|
461 |
||
17234 | 462 |
(****************************************************************************) |
463 |
(* Check all vampire processes currently running for output *) |
|
464 |
(****************************************************************************) |
|
465 |
(*********************************) |
|
466 |
fun checkChildren ([], toParentStr) = [] (*** no children to check ********) |
|
467 |
(*********************************) |
|
468 |
| checkChildren ((childProc::otherChildren), toParentStr) = |
|
469 |
let val _ = File.append (File.tmp_path (Path.basic "child_check")) |
|
470 |
("In check child, length of queue:"^(string_of_int (length (childProc::otherChildren)))^"\n") |
|
471 |
val (childInput,childOutput) = cmdstreamsOf childProc |
|
472 |
val child_handle= cmdchildHandle childProc |
|
473 |
(* childCmd is the .dfg file that the problem is in *) |
|
474 |
val childCmd = fst(snd (cmdchildInfo childProc)) |
|
475 |
val _ = File.append (File.tmp_path (Path.basic "child_command")) |
|
476 |
(childCmd^"\n") |
|
477 |
(* now get the number of the subgoal from the filename *) |
|
478 |
val sg_num = (*if (!SpassComm.spass ) |
|
479 |
then |
|
480 |
int_of_string(ReconOrderClauses.get_nth 5 (rev(explode childCmd))) |
|
481 |
else*) |
|
482 |
int_of_string(hd (rev(explode childCmd))) |
|
16520 | 483 |
|
17234 | 484 |
val childIncoming = pollChildInput childInput |
485 |
val _ = File.append (File.tmp_path (Path.basic "child_check_polled")) |
|
486 |
("finished polling child \n") |
|
487 |
val parentID = Posix.ProcEnv.getppid() |
|
488 |
val prover = cmdProver childProc |
|
489 |
val thmstring = cmdThm childProc |
|
490 |
val sign = sign_of_thm thm |
|
491 |
val prems = prems_of thm |
|
492 |
val prems_string = Meson.concat_with_and (map (Sign.string_of_term sign) prems) |
|
493 |
val _ = warning("subgoals forked to checkChildren: "^prems_string) |
|
494 |
val goalstring = cmdGoal childProc |
|
495 |
val _ = File.append (File.tmp_path (Path.basic "child_comms")) |
|
496 |
(prover^thmstring^goalstring^childCmd^"\n") |
|
497 |
in |
|
498 |
if (isSome childIncoming) |
|
499 |
then |
|
500 |
(* check here for prover label on child*) |
|
501 |
let val _ = File.write (File.tmp_path (Path.basic "child_incoming")) |
|
502 |
("subgoals forked to checkChildren:"^ |
|
503 |
prems_string^prover^thmstring^goalstring^childCmd) |
|
504 |
val childDone = (case prover of |
|
505 |
"vampire" => (VampComm.checkVampProofFound(childInput, toParentStr, parentID,thmstring,goalstring, childCmd, thm, sg_num,clause_arr, num_of_clauses) ) |
|
506 |
|"spass" => (SpassComm.checkSpassProofFound(childInput, toParentStr, parentID,thmstring,goalstring, childCmd, thm, sg_num,clause_arr, num_of_clauses) ) ) |
|
507 |
in |
|
508 |
if childDone (**********************************************) |
|
509 |
then (* child has found a proof and transferred it *) |
|
510 |
(* Remove this child and go on to check others*) |
|
511 |
(**********************************************) |
|
512 |
(Unix.reap child_handle; |
|
513 |
checkChildren(otherChildren, toParentStr)) |
|
514 |
else |
|
515 |
(**********************************************) |
|
516 |
(* Keep this child and go on to check others *) |
|
517 |
(**********************************************) |
|
518 |
(childProc::(checkChildren (otherChildren, toParentStr))) |
|
16061 | 519 |
end |
17234 | 520 |
else |
521 |
(File.append (File.tmp_path (Path.basic "child_incoming")) "No child output "; |
|
522 |
childProc::(checkChildren (otherChildren, toParentStr))) |
|
523 |
end |
|
15642 | 524 |
|
17234 | 525 |
|
526 |
(********************************************************************) |
|
527 |
(* call resolution processes *) |
|
528 |
(* settings should be a list of strings *) |
|
529 |
(* e.g. ["-t 300", "-m 100000"] (TextIO.input instr)^ *) |
|
530 |
(* takes list of (string, string, string list, string)list proclist *) |
|
531 |
(********************************************************************) |
|
15642 | 532 |
|
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
533 |
|
16061 | 534 |
(*** add subgoal id num to this *) |
17234 | 535 |
fun execCmds [] procList = procList |
536 |
| 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())))) |
|
537 |
in |
|
538 |
if (prover = "spass") |
|
539 |
then |
|
540 |
let val childhandle:(TextIO.instream,TextIO.outstream) Unix.proc = |
|
541 |
(Unix.execute(proverCmd, (["-FullRed=0"]@settings@[file]))) |
|
542 |
val (instr, outstr) = Unix.streamsOf childhandle |
|
543 |
val newProcList = (((CMDPROC{ |
|
544 |
prover = prover, |
|
545 |
cmd = file, |
|
546 |
thmstring = thmstring, |
|
547 |
goalstring = goalstring, |
|
548 |
proc_handle = childhandle, |
|
549 |
instr = instr, |
|
550 |
outstr = outstr })::procList)) |
|
551 |
val _ = File.append (File.tmp_path (Path.basic "exec_child")) |
|
552 |
("\nexecuting command for goal:\n"^ |
|
553 |
goalstring^proverCmd^(concat settings)^file^" at "^(Date.toString(Date.fromTimeLocal(Time.now())))) |
|
554 |
in |
|
555 |
Posix.Process.sleep (Time.fromSeconds 1); |
|
556 |
execCmds cmds newProcList |
|
557 |
end |
|
558 |
else |
|
559 |
let val childhandle:(TextIO.instream,TextIO.outstream) Unix.proc = |
|
560 |
(Unix.execute(proverCmd, (settings@[file]))) |
|
561 |
val (instr, outstr) = Unix.streamsOf childhandle |
|
562 |
||
563 |
val newProcList = (CMDPROC{ |
|
564 |
prover = prover, |
|
565 |
cmd = file, |
|
566 |
thmstring = thmstring, |
|
567 |
goalstring = goalstring, |
|
568 |
proc_handle = childhandle, |
|
569 |
instr = instr, |
|
570 |
outstr = outstr }) :: procList |
|
571 |
||
572 |
val _ = File.append (File.tmp_path (Path.basic "exec_child")) |
|
573 |
("executing command for goal:\n"^ |
|
574 |
goalstring^proverCmd^(concat settings)^file^ |
|
575 |
" at "^(Date.toString(Date.fromTimeLocal(Time.now())))) |
|
576 |
in |
|
577 |
Posix.Process.sleep (Time.fromSeconds 1); |
|
578 |
execCmds cmds newProcList |
|
579 |
end |
|
580 |
end |
|
15642 | 581 |
|
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
582 |
|
17234 | 583 |
(****************************************) |
584 |
(* call resolution processes remotely *) |
|
585 |
(* settings should be a list of strings *) |
|
586 |
(* e.g. ["-t 300", "-m 100000"] *) |
|
587 |
(****************************************) |
|
16061 | 588 |
|
17234 | 589 |
(* fun execRemoteCmds [] procList = procList |
590 |
| execRemoteCmds ((prover, thmstring,goalstring,proverCmd ,settings,file)::cmds) procList = |
|
591 |
let val newProcList = mySshExecuteToList ("/usr/bin/ssh",([prover,thmstring,goalstring,"-t", "shep"]@[proverCmd]@settings@[file]), procList) |
|
592 |
in |
|
593 |
execRemoteCmds cmds newProcList |
|
594 |
end |
|
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
595 |
*) |
15642 | 596 |
|
17234 | 597 |
fun printList (outStr, []) = () |
598 |
| printList (outStr, (x::xs)) = (TextIO.output (outStr, x);TextIO.flushOut outStr; printList (outStr,xs)) |
|
15642 | 599 |
|
600 |
||
17234 | 601 |
(**********************************************) |
602 |
(* Watcher Loop *) |
|
603 |
(**********************************************) |
|
16061 | 604 |
|
17234 | 605 |
fun keepWatching (toParentStr, fromParentStr,procList) = |
606 |
let fun loop (procList) = |
|
607 |
let val _ = Posix.Process.sleep (Time.fromMilliseconds 200) |
|
608 |
val cmdsFromIsa = pollParentInput () |
|
609 |
fun killchildHandler (n:int) = |
|
610 |
(TextIO.output(toParentStr, "Killing child proof processes!\n"); |
|
611 |
TextIO.flushOut toParentStr; |
|
612 |
killChildren (map (cmdchildHandle) procList); |
|
613 |
()) |
|
614 |
in |
|
615 |
(*Signal.signal (Posix.Signal.usr2, Signal.SIG_HANDLE killchildHandler);*) |
|
616 |
(**********************************) |
|
617 |
if (isSome cmdsFromIsa) |
|
618 |
then (* deal with input from Isabelle *) |
|
619 |
if (getProofCmd(hd(valOf cmdsFromIsa)) = "Kill children" ) |
|
620 |
then |
|
621 |
let val child_handles = map cmdchildHandle procList |
|
622 |
in |
|
623 |
killChildren child_handles; |
|
624 |
(*Posix.Process.kill(Posix.Process.K_PROC (Posix.ProcEnv.getppid()), Posix.Signal.usr2);*) |
|
625 |
loop ([]) |
|
626 |
end |
|
627 |
else |
|
628 |
if ((length procList)<10) (********************) |
|
629 |
then (* Execute locally *) |
|
630 |
let |
|
631 |
val newProcList = execCmds (valOf cmdsFromIsa) procList |
|
632 |
val parentID = Posix.ProcEnv.getppid() |
|
633 |
val _ = (File.append (File.tmp_path (Path.basic "prekeep_watch")) "Just execed a child\n ") |
|
634 |
val newProcList' =checkChildren (newProcList, toParentStr) |
|
16357 | 635 |
|
17234 | 636 |
val _ = warning("off to keep watching...") |
637 |
val _ = (File.append (File.tmp_path (Path.basic "keep_watch")) "Off to keep watching...\n ") |
|
638 |
in |
|
639 |
loop (newProcList') |
|
640 |
end |
|
641 |
else (* Execute remotely *) |
|
642 |
(* (actually not remote for now )*) |
|
643 |
let |
|
644 |
val newProcList = execCmds (valOf cmdsFromIsa) procList |
|
645 |
val parentID = Posix.ProcEnv.getppid() |
|
646 |
val newProcList' =checkChildren (newProcList, toParentStr) |
|
647 |
in |
|
648 |
loop (newProcList') |
|
649 |
end |
|
650 |
else (* No new input from Isabelle *) |
|
651 |
let val newProcList = checkChildren ((procList), toParentStr) |
|
652 |
in |
|
653 |
(File.append (File.tmp_path (Path.basic "keep_watch")) "Off to keep watching.2..\n "); |
|
654 |
loop (newProcList) |
|
655 |
end |
|
656 |
end |
|
657 |
in |
|
658 |
loop (procList) |
|
659 |
end |
|
660 |
||
15642 | 661 |
|
17234 | 662 |
in |
663 |
(***************************) |
|
664 |
(*** Sort out pipes ********) |
|
665 |
(***************************) |
|
15642 | 666 |
|
17234 | 667 |
Posix.IO.close (#outfd p1); |
668 |
Posix.IO.close (#infd p2); |
|
669 |
Posix.IO.dup2{old = oldchildin, new = fromParent}; |
|
670 |
Posix.IO.close oldchildin; |
|
671 |
Posix.IO.dup2{old = oldchildout, new = toParent}; |
|
672 |
Posix.IO.close oldchildout; |
|
673 |
||
674 |
(***************************) |
|
675 |
(* start the watcher loop *) |
|
676 |
(***************************) |
|
677 |
keepWatching (toParentStr, fromParentStr, procList); |
|
678 |
(****************************************************************************) |
|
679 |
(* fake return value - actually want the watcher to loop until killed *) |
|
680 |
(****************************************************************************) |
|
681 |
Posix.Process.wordToPid 0w0 |
|
682 |
end); |
|
683 |
(* end case *) |
|
15642 | 684 |
|
685 |
||
16061 | 686 |
val _ = TextIO.flushOut TextIO.stdOut |
15642 | 687 |
|
16061 | 688 |
(*******************************) |
689 |
(*** set watcher going ********) |
|
690 |
(*******************************) |
|
15642 | 691 |
|
16061 | 692 |
val procList = [] |
693 |
val pid = startWatcher (procList) |
|
694 |
(**************************************************) |
|
695 |
(* communication streams to watcher *) |
|
696 |
(**************************************************) |
|
15642 | 697 |
|
16061 | 698 |
val instr = openInFD ("_exec_in", #infd p2) |
699 |
val outstr = openOutFD ("_exec_out", #outfd p1) |
|
700 |
||
701 |
in |
|
702 |
(*******************************) |
|
703 |
(* close the child-side fds *) |
|
704 |
(*******************************) |
|
705 |
Posix.IO.close (#outfd p2); |
|
706 |
Posix.IO.close (#infd p1); |
|
707 |
(* set the fds close on exec *) |
|
708 |
Posix.IO.setfd (#infd p2, Posix.IO.FD.flags [Posix.IO.FD.cloexec]); |
|
709 |
Posix.IO.setfd (#outfd p1, Posix.IO.FD.flags [Posix.IO.FD.cloexec]); |
|
710 |
||
711 |
(*******************************) |
|
712 |
(* return value *) |
|
713 |
(*******************************) |
|
714 |
PROC{pid = pid, |
|
715 |
instr = instr, |
|
716 |
outstr = outstr |
|
717 |
} |
|
718 |
end; |
|
15642 | 719 |
|
720 |
||
721 |
||
722 |
(**********************************************************) |
|
723 |
(* Start a watcher and set up signal handlers *) |
|
724 |
(**********************************************************) |
|
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
725 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
726 |
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
|
727 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
728 |
fun reapWatcher(pid, instr, outstr) = |
17216 | 729 |
let val u = TextIO.closeIn instr; |
730 |
val u = TextIO.closeOut outstr; |
|
731 |
val (_, status) = Posix.Process.waitpid(Posix.Process.W_CHILD pid, []) |
|
732 |
in |
|
733 |
status |
|
16100 | 734 |
end |
15642 | 735 |
|
17216 | 736 |
fun createWatcher (thm,clause_arr, ( num_of_clauses:int)) = |
737 |
let val mychild = childInfo (setupWatcher(thm,clause_arr, num_of_clauses)) |
|
17231 | 738 |
val streams = snd mychild |
17216 | 739 |
val childin = fst streams |
740 |
val childout = snd streams |
|
741 |
val childpid = fst mychild |
|
742 |
val sign = sign_of_thm thm |
|
743 |
val prems = prems_of thm |
|
744 |
val prems_string = Meson.concat_with_and (map (Sign.string_of_term sign) prems) |
|
745 |
val _ = (warning ("subgoals forked to createWatcher: "^prems_string)); |
|
746 |
fun vampire_proofHandler (n) = |
|
747 |
(Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")]))); |
|
748 |
VampComm.getVampInput childin; Pretty.writeln(Pretty.str (oct_char "361"))) |
|
749 |
fun spass_proofHandler (n) = ( |
|
750 |
let val outfile = TextIO.openAppend(File.platform_path(File.tmp_path (Path.basic "foo_signal1"))); |
|
751 |
val _ = TextIO.output (outfile, ("In signal handler now\n")) |
|
752 |
val _ = TextIO.closeOut outfile |
|
753 |
val (reconstr, goalstring, thmstring) = SpassComm.getSpassInput childin |
|
754 |
val outfile = TextIO.openAppend(File.platform_path(File.tmp_path (Path.basic "foo_signal"))); |
|
755 |
||
756 |
val _ = TextIO.output (outfile, ("In signal handler "^reconstr^thmstring^goalstring^"goals_being_watched is: "^(string_of_int (!goals_being_watched)))) |
|
757 |
val _ = TextIO.closeOut outfile |
|
758 |
in (* if a proof has been found and sent back as a reconstruction proof *) |
|
17231 | 759 |
if substring (reconstr, 0,1) = "[" |
17216 | 760 |
then (Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")]))); |
761 |
Recon_Transfer.apply_res_thm reconstr goalstring; |
|
762 |
Pretty.writeln(Pretty.str (oct_char "361")); |
|
763 |
||
764 |
goals_being_watched := ((!goals_being_watched) - 1); |
|
765 |
||
17231 | 766 |
if (!goals_being_watched) = 0 |
17216 | 767 |
then |
17231 | 768 |
let val _ = File.write (File.tmp_path (Path.basic "foo_reap_found")) |
769 |
("Reaping a watcher, goals watched is: "^ |
|
770 |
(string_of_int (!goals_being_watched))^"\n") |
|
17216 | 771 |
in |
772 |
killWatcher (childpid); reapWatcher (childpid,childin, childout); () |
|
17231 | 773 |
end |
17216 | 774 |
else () ) |
775 |
(* if there's no proof, but a message from Spass *) |
|
17231 | 776 |
else if substring (reconstr, 0,5) = "SPASS" |
17216 | 777 |
then (goals_being_watched := (!goals_being_watched) -1; |
778 |
Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")]))); |
|
779 |
Pretty.writeln(Pretty.str ((Recon_Transfer.restore_linebreaks goalstring)^reconstr)); |
|
780 |
Pretty.writeln(Pretty.str (oct_char "361")); |
|
781 |
if (!goals_being_watched = 0) |
|
782 |
then (File.write (File.tmp_path (Path.basic "foo_reap_comp")) |
|
783 |
("Reaping a watcher, goals watched is: " ^ |
|
784 |
(string_of_int (!goals_being_watched))^"\n"); |
|
785 |
killWatcher (childpid); reapWatcher (childpid,childin, childout); ()) |
|
786 |
else () ) |
|
787 |
(* print out a list of rules used from clasimpset*) |
|
17231 | 788 |
else if substring (reconstr, 0,5) = "Rules" |
17216 | 789 |
then (goals_being_watched := (!goals_being_watched) -1; |
790 |
Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")]))); |
|
791 |
Pretty.writeln(Pretty.str (goalstring^reconstr)); |
|
792 |
Pretty.writeln(Pretty.str (oct_char "361")); |
|
793 |
if (!goals_being_watched = 0) |
|
794 |
then (File.write (File.tmp_path (Path.basic "foo_reap_comp")) |
|
795 |
("Reaping a watcher, goals watched is: " ^ |
|
796 |
(string_of_int (!goals_being_watched))^"\n"); |
|
797 |
killWatcher (childpid); reapWatcher (childpid,childin, childout);() |
|
798 |
) |
|
799 |
else () ) |
|
800 |
(* if proof translation failed *) |
|
17231 | 801 |
else if substring (reconstr, 0,5) = "Proof" |
17216 | 802 |
then (goals_being_watched := (!goals_being_watched) -1; |
803 |
Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")]))); |
|
804 |
Pretty.writeln(Pretty.str (goalstring^(Recon_Transfer.restore_linebreaks reconstr))); |
|
805 |
Pretty.writeln(Pretty.str (oct_char "361")); |
|
806 |
if (!goals_being_watched = 0) |
|
807 |
then (File.write (File.tmp_path (Path.basic "foo_reap_comp")) |
|
808 |
("Reaping a watcher, goals watched is: " ^ |
|
809 |
(string_of_int (!goals_being_watched))^"\n"); |
|
810 |
killWatcher (childpid); reapWatcher (childpid,childin, childout);() |
|
811 |
) |
|
812 |
else () ) |
|
15642 | 813 |
|
17231 | 814 |
else if substring (reconstr, 0,1) = "%" |
17216 | 815 |
then (goals_being_watched := (!goals_being_watched) -1; |
816 |
Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")]))); |
|
817 |
Pretty.writeln(Pretty.str (goalstring^(Recon_Transfer.restore_linebreaks reconstr))); |
|
818 |
Pretty.writeln(Pretty.str (oct_char "361")); |
|
819 |
if (!goals_being_watched = 0) |
|
820 |
then (File.write (File.tmp_path (Path.basic "foo_reap_comp")) |
|
821 |
("Reaping a watcher, goals watched is: " ^ |
|
822 |
(string_of_int (!goals_being_watched))^"\n"); |
|
823 |
killWatcher (childpid); reapWatcher (childpid,childin, childout);() |
|
824 |
) |
|
825 |
else () ) |
|
826 |
||
827 |
else (* add something here ?*) |
|
828 |
(goals_being_watched := (!goals_being_watched) -1; |
|
829 |
Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")]))); |
|
17231 | 830 |
Pretty.writeln(Pretty.str ("Ran out of options in handler")); |
831 |
Pretty.writeln(Pretty.str (oct_char "361")); |
|
832 |
if (!goals_being_watched = 0) |
|
833 |
then (File.write (File.tmp_path (Path.basic "foo_reap_comp")) |
|
834 |
("Reaping a watcher, goals watched is: " ^ |
|
835 |
(string_of_int (!goals_being_watched))^"\n"); |
|
836 |
killWatcher (childpid); reapWatcher (childpid,childin, childout);() |
|
837 |
) |
|
838 |
else () ) |
|
17216 | 839 |
end) |
840 |
||
841 |
in IsaSignal.signal (IsaSignal.usr1, IsaSignal.SIG_HANDLE vampire_proofHandler); |
|
842 |
IsaSignal.signal (IsaSignal.usr2, IsaSignal.SIG_HANDLE spass_proofHandler); |
|
843 |
(childin, childout, childpid) |
|
844 |
||
845 |
end |
|
15642 | 846 |
|
847 |
end (* structure Watcher *) |