1
1
package dotty .tools .repl
2
2
3
3
import scala .language .unsafeNulls
4
+
4
5
import java .io .{File => JFile , PrintStream }
5
6
import java .nio .charset .StandardCharsets
7
+
6
8
import dotty .tools .dotc .ast .Trees .*
7
9
import dotty .tools .dotc .ast .{tpd , untpd }
8
10
import dotty .tools .dotc .classpath .ClassPathFactory
@@ -20,6 +22,7 @@ import dotty.tools.dotc.core.NameOps.*
20
22
import dotty .tools .dotc .core .Names .Name
21
23
import dotty .tools .dotc .core .StdNames .*
22
24
import dotty .tools .dotc .core .Symbols .{Symbol , defn }
25
+ import dotty .tools .dotc .core .SymbolLoaders
23
26
import dotty .tools .dotc .interfaces
24
27
import dotty .tools .dotc .interactive .Completion
25
28
import dotty .tools .dotc .printing .SyntaxHighlighting
@@ -70,6 +73,7 @@ case class State(objectIndex: Int,
70
73
quiet : Boolean ,
71
74
context : Context ):
72
75
def validObjectIndexes = (1 to objectIndex).filterNot(invalidObjectIndexes.contains(_))
76
+ // def copy() = this
73
77
74
78
/** Main REPL instance, orchestrating input, compilation and presentation */
75
79
class ReplDriver (settings : Array [String ],
@@ -94,7 +98,7 @@ class ReplDriver(settings: Array[String],
94
98
initCtx.settings.YwithBestEffortTasty .name
95
99
)
96
100
97
- private def setupRootCtx (settings : Array [String ], rootCtx : Context , previousOutputDir : Option [ AbstractFile ] = None ) = {
101
+ private def setupRootCtx (settings : Array [String ], rootCtx : Context ) = {
98
102
val incompatible = settings.intersect(incompatibleOptions)
99
103
val filteredSettings =
100
104
if ! incompatible.isEmpty then
@@ -107,7 +111,7 @@ class ReplDriver(settings: Array[String],
107
111
case Some ((files, ictx)) => inContext(ictx) {
108
112
shouldStart = true
109
113
if files.nonEmpty then out.println(i " Ignoring spurious arguments: $files%, % " )
110
- ictx.base.initialize(previousOutputDir )
114
+ ictx.base.initialize()
111
115
ictx
112
116
}
113
117
case None =>
@@ -540,30 +544,23 @@ class ReplDriver(settings: Array[String],
540
544
if (existingClass.nonEmpty)
541
545
out.println(s " The path ' $path' cannot be loaded, it contains a classfile that already exists on the classpath: ${existingClass.get}" )
542
546
state
543
- else
544
- val prevClassPath = state.context.platform.classPath( using state.context).asClassPathString
545
- val newClassPath = s " $prevClassPath${ JFile .pathSeparator}$path "
547
+ else inContext(state.context) :
548
+ val jarClassPath = ClassPathFactory .newClassPath(jarFile)
549
+ val prevOutputDir = ctx.settings.outputDir.value
546
550
547
551
// add to compiler class path
548
- val prevOutputDir = rootCtx.settings.outputDir.valueIn(rootCtx.settingsState)
549
- val ctxToUse = initCtx.fresh
550
- .setSetting(rootCtx.settings.classpath, newClassPath)
551
- .setSetting(rootCtx.settings.outputDir, prevOutputDir) // reuse virtual output directory
552
- rootCtx = setupRootCtx(
553
- Array (),
554
- ctxToUse,
555
- previousOutputDir = Some (prevOutputDir)
556
- )
557
- val s = state.copy(context = rootCtx)
552
+ ctx.platform.addToClassPath(jarClassPath)
553
+ SymbolLoaders .mergeNewEntries(defn.RootClass , ClassPath .RootPackage , jarClassPath, ctx.platform.classPath)
558
554
559
555
// new class loader with previous output dir and specified jar
560
- val prevClassLoader = rendering.classLoader()( using state.context)
556
+ val prevClassLoader = rendering.classLoader()
561
557
val jarClassLoader = fromURLsParallelCapable(
562
- ClassPathFactory .newClassPath(jarFile)( using rootCtx) .asURLs, prevClassLoader)
558
+ jarClassPath .asURLs, prevClassLoader)
563
559
rendering.myClassLoader = new AbstractFileClassLoader (
564
- rootCtx.settings.outputDir.valueIn(rootCtx.settingsState), jarClassLoader)
560
+ prevOutputDir, jarClassLoader)
561
+
565
562
out.println(s " Added ' $path' to classpath. " )
566
- s
563
+ state
567
564
568
565
case KindOf (expr) =>
569
566
out.println(s """ The :kind command is not currently supported. """ )
0 commit comments