diff options
author | Jeremy Cloud <jeremycloud@twitter.com> | 2011-04-08 17:11:46 -0400 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2016-11-07 02:08:38 -0500 |
commit | b77f1fb88e162986a33ddc2dbdd07f2eb7431d44 (patch) | |
tree | 170f80f7a92c32f54996f760f0dc52a1a70466cd /libraries | |
parent | bc1d0f0f32d32637d23046872d96492cb385d2dd (diff) | |
download | cbt-b77f1fb88e162986a33ddc2dbdd07f2eb7431d44.tar.gz cbt-b77f1fb88e162986a33ddc2dbdd07f2eb7431d44.tar.bz2 cbt-b77f1fb88e162986a33ddc2dbdd07f2eb7431d44.zip |
[split] deprecated global Eval object in favor or Eval instances which can be GC
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/eval/Eval.scala | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/libraries/eval/Eval.scala b/libraries/eval/Eval.scala index 278933c..cd91d20 100644 --- a/libraries/eval/Eval.scala +++ b/libraries/eval/Eval.scala @@ -33,24 +33,29 @@ import scala.tools.nsc.util.{BatchSourceFile, Position} /** * Evaluate a file or string and return the result. */ -object Eval { - private val compilerPath = try { +@deprecated("use a throw-away instance of Eval instead") +object Eval extends Eval { + private val jvmId = java.lang.Math.abs(new Random().nextInt()) +} + +class Eval { + import Eval.jvmId + + private lazy val compilerPath = try { jarPathOfClass("scala.tools.nsc.Interpreter") } catch { case e => throw new RuntimeException("Unable lo load scala interpreter from classpath (scala-compiler jar is missing?)", e) } - private val libPath = try { + private lazy val libPath = try { jarPathOfClass("scala.ScalaObject") } catch { case e => throw new RuntimeException("Unable to load scala base object from classpath (scala-library jar is missing?)", e) } - private val jvmId = java.lang.Math.abs(new Random().nextInt()) - - val compiler = new StringCompiler(2) + private lazy val compiler = new StringCompiler(2) /** * Eval[Int]("1 + 1") // => 2 @@ -146,7 +151,7 @@ object Eval { * Dynamic scala compiler. Lots of (slow) state is created, so it may be advantageous to keep * around one of these and reuse it. */ - class StringCompiler(lineOffset: Int) { + private class StringCompiler(lineOffset: Int) { val virtualDirectory = new VirtualDirectory("(memory)", None) val cache = new mutable.HashMap[String, Class[_]]() |