diff options
Diffstat (limited to 'src/main/scala/scalam/m/interpretation')
4 files changed, 66 insertions, 0 deletions
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 |