From a93a86db7ad1839605448f9532ac96300785a59e Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Tue, 30 Oct 2012 21:48:46 +0100 Subject: move interpreters to seperate package --- src/main/scala/scalam/m/Interpreter.scala | 31 ---------------------- src/main/scala/scalam/m/MatlabInterpreter.scala | 18 ------------- .../scalam/m/interpretation/Interpreter.scala | 31 ++++++++++++++++++++++ .../scalam/m/interpretation/MInterpreter.scala | 18 +++++++++++++ .../m/interpretation/MatlabInterpreter.scala | 8 ++++++ .../m/interpretation/OctaveInterpreter.scala | 9 +++++++ src/main/scala/scalam/plotting/Plotter.scala | 4 ++- 7 files changed, 69 insertions(+), 50 deletions(-) delete mode 100644 src/main/scala/scalam/m/Interpreter.scala delete mode 100644 src/main/scala/scalam/m/MatlabInterpreter.scala create mode 100644 src/main/scala/scalam/m/interpretation/Interpreter.scala create mode 100644 src/main/scala/scalam/m/interpretation/MInterpreter.scala create mode 100644 src/main/scala/scalam/m/interpretation/MatlabInterpreter.scala create mode 100644 src/main/scala/scalam/m/interpretation/OctaveInterpreter.scala diff --git a/src/main/scala/scalam/m/Interpreter.scala b/src/main/scala/scalam/m/Interpreter.scala deleted file mode 100644 index b4be651..0000000 --- a/src/main/scala/scalam/m/Interpreter.scala +++ /dev/null @@ -1,31 +0,0 @@ -package scalam.m - -import scalax.file.Path -import scala.sys.process._ -import scala.io._ -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( - new ProcessIO( - stdin => inputStream.put(stdin), - stdout => Source.fromInputStream(stdout).getLines.foreach(println), - stderr => Source.fromInputStream(stderr).getLines.foreach(println))); - - def write(s: String): Unit = synchronized { - 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 deleted file mode 100644 index 2b055e2..0000000 --- a/src/main/scala/scalam/m/MatlabInterpreter.scala +++ /dev/null @@ -1,18 +0,0 @@ -package scalam.m - -import ast._ -import scalax.file.Path - -class MatlabInterpreter(pwd: Path) extends Interpreter("matlab -nosplash -nodesktop", pwd) { - def evaluate(root: ast.Root) = write(root.line + "\n") - def exit() = { - val cmd = Function(Identifier("exit")) - evaluate(cmd) - super.close() - } - -} - -object MatlabInterpreter { - final val command = "matlab -nosplash -nodesktop" -} \ No newline at end of file diff --git a/src/main/scala/scalam/m/interpretation/Interpreter.scala b/src/main/scala/scalam/m/interpretation/Interpreter.scala new file mode 100644 index 0000000..93411c3 --- /dev/null +++ b/src/main/scala/scalam/m/interpretation/Interpreter.scala @@ -0,0 +1,31 @@ +package scalam.m.interpretation + +import scalax.file.Path +import scala.sys.process._ +import scala.io._ +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( + new ProcessIO( + stdin => inputStream.put(stdin), + stdout => Source.fromInputStream(stdout).getLines.foreach(println), + stderr => Source.fromInputStream(stderr).getLines.foreach(println))); + + def write(s: String): Unit = synchronized { + 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/interpretation/MInterpreter.scala b/src/main/scala/scalam/m/interpretation/MInterpreter.scala new file mode 100644 index 0000000..b154cd7 --- /dev/null +++ b/src/main/scala/scalam/m/interpretation/MInterpreter.scala @@ -0,0 +1,18 @@ +package scalam +package m +package interpretation + +import ast._ +import scalax.file.Path + +class MInterpreter(command: String, pwd: Path) extends Interpreter(command, pwd){ + + def evaluate(root: ast.Root) = write(root.line + "\n") + + def exit() = { + val cmd = Function(Identifier("exit")) + evaluate(cmd) + super.close() + } + +} \ No newline at end of file diff --git a/src/main/scala/scalam/m/interpretation/MatlabInterpreter.scala b/src/main/scala/scalam/m/interpretation/MatlabInterpreter.scala new file mode 100644 index 0000000..34534e6 --- /dev/null +++ b/src/main/scala/scalam/m/interpretation/MatlabInterpreter.scala @@ -0,0 +1,8 @@ +package scalam +package m +package interpretation + +import ast._ +import scalax.file.Path + +class MatlabInterpreter(pwd: Path) extends MInterpreter("matlab -nosplash -nodesktop", pwd) \ No newline at end of file diff --git a/src/main/scala/scalam/m/interpretation/OctaveInterpreter.scala b/src/main/scala/scalam/m/interpretation/OctaveInterpreter.scala new file mode 100644 index 0000000..c55166b --- /dev/null +++ b/src/main/scala/scalam/m/interpretation/OctaveInterpreter.scala @@ -0,0 +1,9 @@ +package scalam +package m +package interpretation + +import ast._ +import scalax.file.Path + + +class OctaveInterpreter(pwd: Path) extends MInterpreter("octave", pwd) \ No newline at end of file diff --git a/src/main/scala/scalam/plotting/Plotter.scala b/src/main/scala/scalam/plotting/Plotter.scala index 46e579f..341b976 100644 --- a/src/main/scala/scalam/plotting/Plotter.scala +++ b/src/main/scala/scalam/plotting/Plotter.scala @@ -3,13 +3,15 @@ package scalam.plotting import scalam.m._ import scalam.m.ast._ import scalam.plotting.styles._ +import scalam.m.interpretation.MInterpreter +import scalam.m.interpretation.MatlabInterpreter trait Plotter { import Plotter._ val pwd: scalax.file.Path - lazy val interpreter = new MatlabInterpreter(pwd) + lazy val interpreter: MInterpreter = new MatlabInterpreter(pwd) def plot(dataSets: Seq[DataSet], title: String, x: String, y: String, grid: Boolean = true, legend: Boolean = true)(implicit styles: Seq[Style[_]] = defaultStyles, fontSize: FontSize = defaultFontSize) = { val p = new Plot(dataSets, title, x, y, grid, legend, styles = styles, fontSize = fontSize.fontSize) -- cgit v1.2.3