diff options
author | Jakob Odersky <jodersky@gmail.com> | 2012-10-30 13:42:38 +0100 |
---|---|---|
committer | Jakob Odersky <jodersky@gmail.com> | 2012-10-30 13:42:38 +0100 |
commit | 5ec341ecb62fbd089fc1498ac136206d8762415f (patch) | |
tree | fd9b4cf95e692fd15b46a1bd875dbe15a43cd9e7 /src/main/scala/scalam/m | |
parent | 32c4cb7b839466214748be076b122b8a9d6e04b4 (diff) | |
download | scalam-5ec341ecb62fbd089fc1498ac136206d8762415f.tar.gz scalam-5ec341ecb62fbd089fc1498ac136206d8762415f.tar.bz2 scalam-5ec341ecb62fbd089fc1498ac136206d8762415f.zip |
*add kill method to interpreters
*refactor methods
Diffstat (limited to 'src/main/scala/scalam/m')
-rw-r--r-- | src/main/scala/scalam/m/Interpreter.scala | 8 | ||||
-rw-r--r-- | src/main/scala/scalam/m/MatlabInterpreter.scala | 15 |
2 files changed, 18 insertions, 5 deletions
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 |