Skip to content

Commit 778072d

Browse files
DarkDimiussmarter
authored andcommitted
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 :-)
1 parent 2e72811 commit 778072d

File tree

3 files changed

+43
-10
lines changed

3 files changed

+43
-10
lines changed

bin/dotc

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55

66
# Configuration
7-
SCALA_VERSION=2.11.4
7+
SCALA_VERSION=2.11.5
88
SCALA_BINARY_VERSION=2.11
99
SCALA_COMPILER_VERSION=2.11.5-20141212-151631-beaa78b033
1010
DOTTY_VERSION=0.1
11+
JLINE_VERSION=2.12
1112
bootcp=true
1213
default_java_opts="-Xmx768m -Xms768m"
1314
programName=$(basename "$0")
@@ -21,6 +22,7 @@ unset verbose quiet cygwin toolcp colors saved_stty CDPATH
2122

2223

2324
CompilerMain=dotty.tools.dotc.Main
25+
ReplMain=test.DottyRepl
2426

2527

2628
# Try to autodetect real location of the script
@@ -32,7 +34,7 @@ DOTTY_ROOT="`dirname \"$DOTTY_ROOT\"`"
3234
DOTTY_ROOT="`( cd \"$DOTTY_ROOT\" && pwd )`/.." # absolute
3335
# autodetecting the compiler jar. this is location where sbt 'packages' it
3436
MAIN_JAR=$DOTTY_ROOT/target/scala-$SCALA_BINARY_VERSION/dotty_$SCALA_BINARY_VERSION-$DOTTY_VERSION-SNAPSHOT.jar
35-
37+
TEST_JAR=$DOTTY_ROOT/target/scala-$SCALA_BINARY_VERSION/dotty_$SCALA_BINARY_VERSION-$DOTTY_VERSION-SNAPSHOT-tests.jar
3638
function checkjar {
3739
if [ ! -f "$1" ]
3840
then
@@ -51,6 +53,7 @@ function checkjar {
5153
}
5254

5355
checkjar $MAIN_JAR package
56+
checkjar $TEST_JAR test:package
5457

5558
# Autodetecting the scala-library location, in case it wasn't provided by an environment variable
5659
if [ "$SCALA_LIBRARY_JAR" == "" ]
@@ -68,13 +71,18 @@ then
6871
SCALA_COMPILER_JAR=$HOME/.ivy2/cache/me.d-d/scala-compiler/jars/scala-compiler-$SCALA_COMPILER_VERSION.jar
6972
fi
7073

71-
if [ ! -f "$SCALA_LIBRARY_JAR" -o ! -f "$SCALA_REFLECT_JAR" -o ! -f "$SCALA_COMPILER_JAR" ]
74+
if [ "$JLINE_JAR" == "" ]
75+
then
76+
JLINE_JAR=$HOME/.ivy2//cache/jline/jline/jars/jline-$JLINE_VERSION.jar
77+
fi
78+
79+
if [ ! -f "$SCALA_LIBRARY_JAR" -o ! -f "$SCALA_REFLECT_JAR" -o ! -f "$SCALA_COMPILER_JAR" -o ! -f "$JLINE_JAR" ]
7280
then
7381
echo To use this script please set
7482
echo SCALA_LIBRARY_JAR to point to scala-library-$SCALA_VERSION.jar "(currently $SCALA_LIBRARY_JAR)"
7583
echo SCALA_REFLECT_JAR to point to scala-reflect-$SCALA_VERSION.jar "(currently $SCALA_REFLECT_JAR)"
7684
echo SCALA_COMPILER_JAR to point to scala-compiler-$SCALA_VERSION.jar with bcode patches "(currently $SCALA_COMPILER_JAR)"
77-
85+
echo JLINE_JAR to point to jline-$JLINE_VERSION.jar "(currently $JLINE_JAR)"
7886
fi
7987

8088
ifdebug () {
@@ -163,9 +171,9 @@ trap onExit INT
163171
# to java to suppress "." from materializing.
164172
classpathArgs () {
165173
if [[ -n $bootcp ]]; then
166-
echo "-Xbootclasspath/a:$SCALA_LIBRARY_JAR:$SCALA_REFLECT_JAR:$SCALA_COMPILER_JAR:$MAIN_JAR -classpath $MAIN_JAR"
174+
echo "-Xbootclasspath/a:$SCALA_LIBRARY_JAR:$SCALA_REFLECT_JAR:$SCALA_COMPILER_JAR:$JLINE_JAR:$MAIN_JAR -classpath $MAIN_JAR:$TEST_JAR"
167175
else
168-
echo "-classpath $SCALA_LIBRARY_JAR:$SCALA_REFLECT_JAR:$MAIN_JAR"
176+
echo "-classpath $SCALA_LIBRARY_JAR:$SCALA_REFLECT_JAR:$SCALA_COMPILER_JAR:$JLINE_JAR:$MAIN_JAR:$TEST_JAR"
169177
fi
170178
}
171179

@@ -181,8 +189,7 @@ require_arg () {
181189
}
182190

183191

184-
185-
192+
main_class=$CompilerMain
186193

187194
while [[ $# -gt 0 ]]; do
188195
case "$1" in
@@ -230,7 +237,7 @@ execCommand \
230237
"${java_args[@]}" \
231238
"$(classpathArgs)" \
232239
-Dscala.usejavacp=true \
233-
"${CompilerMain}" \
240+
"${main_class}" \
234241
"${scala_args[@]}" \
235242
"${residual_args[@]}"
236243

project/Build.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ object DottyBuild extends Build {
3131
// get reflect and xml onboard
3232
libraryDependencies ++= Seq("org.scala-lang" % "scala-reflect" % scalaVersion.value,
3333
"org.scala-lang.modules" %% "scala-xml" % "1.0.1",
34-
"me.d-d" % "scala-compiler" % "2.11.5-20141212-151631-beaa78b033"),
34+
"me.d-d" % "scala-compiler" % "2.11.5-20141212-151631-beaa78b033",
35+
"jline" % "jline" % "2.12"),
3536

3637
// get junit onboard
3738
libraryDependencies += "com.novocode" % "junit-interface" % "0.11-RC1" % "test",

test/test/DottyRepl.scala

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package test
2+
import scala.tools.nsc.interpreter._
3+
import scala.tools.nsc.Settings
4+
5+
/**
6+
* Dotty requires a mangled bootclasspath to start. It means that `console` mode of sbt doesn't work for us.
7+
* At least I(Dmitry) wasn't able to make sbt fork in console
8+
*/
9+
object DottyRepl {
10+
def main(args: Array[String]): Unit = {
11+
def repl = new ILoop {}
12+
13+
val settings = new Settings
14+
settings.Yreplsync.value = true
15+
16+
17+
//use when launching normally outside SBT
18+
settings.usejavacp.value = true
19+
20+
//an alternative to 'usejavacp' setting, when launching from within SBT
21+
//settings.embeddedDefaults[Repl.type]
22+
23+
repl.process(settings)
24+
}
25+
}

0 commit comments

Comments
 (0)