@@ -10,17 +10,20 @@ import printer._
10
10
11
11
import java .io ._
12
12
13
- abstract class ProcessInterpreter (protected val process : Process , tailPrinter : Boolean ) extends Interpreter {
13
+ abstract class ProcessInterpreter private (override val printer : Printer ,
14
+ override val parser : Parser ,
15
+ protected val process : Process ,
16
+ protected val in : BufferedWriter ,
17
+ protected val out : BufferedReader ) extends Interpreter {
14
18
15
- def this (executable : String , args : Array [String ], tailPrinter : Boolean = false ) = {
16
- this (java.lang.Runtime .getRuntime.exec((executable :: args.toList).mkString(" " )), tailPrinter)
17
- }
18
-
19
- lazy val in = new BufferedWriter (new OutputStreamWriter (process.getOutputStream))
20
- lazy val out = new BufferedReader (new InputStreamReader (process.getInputStream))
19
+ private def this (printer : Printer , otherArgs : (Parser , Process , BufferedWriter , BufferedReader )) =
20
+ this (printer, otherArgs._1, otherArgs._2, otherArgs._3, otherArgs._4)
21
21
22
- lazy val parser : Parser = new Parser (new Lexer (out))
23
- lazy val printer : Printer = if (tailPrinter) TailPrinter else RecursivePrinter
22
+ def this (executable : String ,
23
+ args : Array [String ],
24
+ printer : Printer = RecursivePrinter ,
25
+ parserCtor : BufferedReader => Parser = out => new Parser (new Lexer (out))) =
26
+ this (printer, ProcessInterpreter .ctorHelper(executable, args, parserCtor))
24
27
25
28
def parseResponseOf (cmd : SExpr ): SExpr = cmd match {
26
29
case CheckSat () => parser.parseCheckSatResponse
@@ -98,17 +101,16 @@ abstract class ProcessInterpreter(protected val process: Process, tailPrinter: B
98
101
override def interrupt (): Unit = synchronized {
99
102
kill()
100
103
}
104
+ }
101
105
102
- /*
103
- * Manos, greatest hack:
104
- * Process.destroyForcibly is only available on java8,
105
- * Using the implicit conversion, if compiled with java7
106
- * we will fallback to Process.destroy. If compiled on java8,
107
- * it will ignore the implicit conversion as the method exists,
108
- * and call the native Process.destroyForcibly.
109
- */
110
- private implicit class Java8Process (process : Process ) {
111
- def destroyForcibly () = process.destroy
106
+ object ProcessInterpreter {
107
+ private def ctorHelper (executable : String ,
108
+ args : Array [String ],
109
+ parserCtor : BufferedReader => Parser ): (Parser , Process , BufferedWriter , BufferedReader ) = {
110
+ val process = java.lang.Runtime .getRuntime.exec((executable :: args.toList).mkString(" " ))
111
+ val in = new BufferedWriter (new OutputStreamWriter (process.getOutputStream))
112
+ val out = new BufferedReader (new InputStreamReader (process.getInputStream))
113
+ val parser = parserCtor(out)
114
+ (parser, process, in, out)
112
115
}
113
-
114
- }
116
+ }
0 commit comments