From 5ec341ecb62fbd089fc1498ac136206d8762415f Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Tue, 30 Oct 2012 13:42:38 +0100 Subject: *add kill method to interpreters *refactor methods --- src/main/scala/scalam/m/Interpreter.scala | 8 ++++++-- src/main/scala/scalam/m/MatlabInterpreter.scala | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/main/scala/scalam/m/Interpreter.scala b/src/main/scala/scalam/m/Interpreter.scala index 6c23929..b4be651 100644 --- a/src/main/scala/scalam/m/Interpreter.scala +++ b/src/main/scala/scalam/m/Interpreter.scala @@ -7,7 +7,6 @@ import java.io._ import scala.concurrent._ class Interpreter(command: String, pwd: Path) { - private val inputStream = new SyncVar[OutputStream]; val process = Process(command, pwd.fileOption, "" -> "").run( @@ -17,11 +16,16 @@ class Interpreter(command: String, pwd: Path) { stderr => Source.fromInputStream(stderr).getLines.foreach(println))); def write(s: String): Unit = synchronized { - inputStream.get.write((s + "\n").getBytes) + inputStream.get.write((s).getBytes) inputStream.get.flush() } def close(): Unit = { inputStream.get.close } + + def kill(): Unit = { + close() + process.destroy() + } } \ No newline at end of file diff --git a/src/main/scala/scalam/m/MatlabInterpreter.scala b/src/main/scala/scalam/m/MatlabInterpreter.scala index 94cd148..88667e8 100644 --- a/src/main/scala/scalam/m/MatlabInterpreter.scala +++ b/src/main/scala/scalam/m/MatlabInterpreter.scala @@ -1,9 +1,18 @@ package scalam.m +import ast._ import scalax.file.Path -class MatlabInterpreter(pwd: Path = Path(".")) extends Interpreter("matlab -nosplash -nodesktop", pwd) { - - def evaluate(statement: ast.Statement) = write(statement.m) +class MatlabInterpreter(pwd: Path) extends Interpreter("matlab -nosplash -nodesktop", pwd) { + def evaluate(statement: ast.Statement) = write(statement.m + "\n") + def exit() = { + val cmd = Evaluate(Function(Identifier("exit"))) + evaluate(cmd) + super.close() + } +} + +object MatlabInterpreter { + final val command = "matlab -nosplash -nodesktop" } \ No newline at end of file -- cgit v1.2.3