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