From 778072d5bd7763d7c5181e405db84e341be27ca3 Mon Sep 17 00:00:00 2001 From: Dmitry Petrashko Date: Tue, 14 Oct 2014 14:49:08 +0200 Subject: Add dotty repl & type stealer Dotty requires a mangled bootclasspath to start. It means that `console` mode of sbt doesn't work for us. At least I wasn't able to make sbt fork in console, so instead I've added a Scala-repl into dotty itself :-) It would be good to make it use dotty one day when we have a backend :-) --- bin/dotc | 25 ++++++++++++++++--------- project/Build.scala | 3 ++- test/test/DottyRepl.scala | 25 +++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 test/test/DottyRepl.scala diff --git a/bin/dotc b/bin/dotc index ffe11d070..6d0bf72ce 100755 --- a/bin/dotc +++ b/bin/dotc @@ -4,10 +4,11 @@ # Configuration -SCALA_VERSION=2.11.4 +SCALA_VERSION=2.11.5 SCALA_BINARY_VERSION=2.11 SCALA_COMPILER_VERSION=2.11.5-20141212-151631-beaa78b033 DOTTY_VERSION=0.1 +JLINE_VERSION=2.12 bootcp=true default_java_opts="-Xmx768m -Xms768m" programName=$(basename "$0") @@ -21,6 +22,7 @@ unset verbose quiet cygwin toolcp colors saved_stty CDPATH CompilerMain=dotty.tools.dotc.Main +ReplMain=test.DottyRepl # Try to autodetect real location of the script @@ -32,7 +34,7 @@ DOTTY_ROOT="`dirname \"$DOTTY_ROOT\"`" DOTTY_ROOT="`( cd \"$DOTTY_ROOT\" && pwd )`/.." # absolute # autodetecting the compiler jar. this is location where sbt 'packages' it MAIN_JAR=$DOTTY_ROOT/target/scala-$SCALA_BINARY_VERSION/dotty_$SCALA_BINARY_VERSION-$DOTTY_VERSION-SNAPSHOT.jar - +TEST_JAR=$DOTTY_ROOT/target/scala-$SCALA_BINARY_VERSION/dotty_$SCALA_BINARY_VERSION-$DOTTY_VERSION-SNAPSHOT-tests.jar function checkjar { if [ ! -f "$1" ] then @@ -51,6 +53,7 @@ function checkjar { } checkjar $MAIN_JAR package +checkjar $TEST_JAR test:package # Autodetecting the scala-library location, in case it wasn't provided by an environment variable if [ "$SCALA_LIBRARY_JAR" == "" ] @@ -68,13 +71,18 @@ then SCALA_COMPILER_JAR=$HOME/.ivy2/cache/me.d-d/scala-compiler/jars/scala-compiler-$SCALA_COMPILER_VERSION.jar fi -if [ ! -f "$SCALA_LIBRARY_JAR" -o ! -f "$SCALA_REFLECT_JAR" -o ! -f "$SCALA_COMPILER_JAR" ] +if [ "$JLINE_JAR" == "" ] +then + JLINE_JAR=$HOME/.ivy2//cache/jline/jline/jars/jline-$JLINE_VERSION.jar +fi + +if [ ! -f "$SCALA_LIBRARY_JAR" -o ! -f "$SCALA_REFLECT_JAR" -o ! -f "$SCALA_COMPILER_JAR" -o ! -f "$JLINE_JAR" ] then echo To use this script please set echo SCALA_LIBRARY_JAR to point to scala-library-$SCALA_VERSION.jar "(currently $SCALA_LIBRARY_JAR)" echo SCALA_REFLECT_JAR to point to scala-reflect-$SCALA_VERSION.jar "(currently $SCALA_REFLECT_JAR)" echo SCALA_COMPILER_JAR to point to scala-compiler-$SCALA_VERSION.jar with bcode patches "(currently $SCALA_COMPILER_JAR)" - + echo JLINE_JAR to point to jline-$JLINE_VERSION.jar "(currently $JLINE_JAR)" fi ifdebug () { @@ -163,9 +171,9 @@ trap onExit INT # to java to suppress "." from materializing. classpathArgs () { if [[ -n $bootcp ]]; then -echo "-Xbootclasspath/a:$SCALA_LIBRARY_JAR:$SCALA_REFLECT_JAR:$SCALA_COMPILER_JAR:$MAIN_JAR -classpath $MAIN_JAR" +echo "-Xbootclasspath/a:$SCALA_LIBRARY_JAR:$SCALA_REFLECT_JAR:$SCALA_COMPILER_JAR:$JLINE_JAR:$MAIN_JAR -classpath $MAIN_JAR:$TEST_JAR" else -echo "-classpath $SCALA_LIBRARY_JAR:$SCALA_REFLECT_JAR:$MAIN_JAR" +echo "-classpath $SCALA_LIBRARY_JAR:$SCALA_REFLECT_JAR:$SCALA_COMPILER_JAR:$JLINE_JAR:$MAIN_JAR:$TEST_JAR" fi } @@ -181,8 +189,7 @@ require_arg () { } - - +main_class=$CompilerMain while [[ $# -gt 0 ]]; do case "$1" in @@ -230,7 +237,7 @@ execCommand \ "${java_args[@]}" \ "$(classpathArgs)" \ -Dscala.usejavacp=true \ - "${CompilerMain}" \ + "${main_class}" \ "${scala_args[@]}" \ "${residual_args[@]}" diff --git a/project/Build.scala b/project/Build.scala index f7053573f..e6725bb26 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -31,7 +31,8 @@ object DottyBuild extends Build { // get reflect and xml onboard libraryDependencies ++= Seq("org.scala-lang" % "scala-reflect" % scalaVersion.value, "org.scala-lang.modules" %% "scala-xml" % "1.0.1", - "me.d-d" % "scala-compiler" % "2.11.5-20141212-151631-beaa78b033"), + "me.d-d" % "scala-compiler" % "2.11.5-20141212-151631-beaa78b033", + "jline" % "jline" % "2.12"), // get junit onboard libraryDependencies += "com.novocode" % "junit-interface" % "0.11-RC1" % "test", diff --git a/test/test/DottyRepl.scala b/test/test/DottyRepl.scala new file mode 100644 index 000000000..74f6ee248 --- /dev/null +++ b/test/test/DottyRepl.scala @@ -0,0 +1,25 @@ +package test +import scala.tools.nsc.interpreter._ +import scala.tools.nsc.Settings + +/** + * Dotty requires a mangled bootclasspath to start. It means that `console` mode of sbt doesn't work for us. + * At least I(Dmitry) wasn't able to make sbt fork in console + */ +object DottyRepl { + def main(args: Array[String]): Unit = { + def repl = new ILoop {} + + val settings = new Settings + settings.Yreplsync.value = true + + + //use when launching normally outside SBT + settings.usejavacp.value = true + + //an alternative to 'usejavacp' setting, when launching from within SBT + //settings.embeddedDefaults[Repl.type] + + repl.process(settings) + } +} -- cgit v1.2.3