@@ -75,6 +75,7 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
75
75
def history = in.history
76
76
77
77
// classpath entries added via :cp
78
+ @ deprecated(" Use reset, replay or require to update class path" , since = " 2.11" )
78
79
var addedClasspath : String = " "
79
80
80
81
/** A reverse list of commands to replay if the user requests a :replay */
@@ -207,7 +208,6 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
207
208
208
209
/** Standard commands **/
209
210
lazy val standardCommands = List (
210
- cmd(" cp" , " <path>" , " add a jar or directory to the classpath" , addClasspath),
211
211
cmd(" edit" , " <id>|<line>" , " edit history" , editCommand),
212
212
cmd(" help" , " [command]" , " print this summary or command-specific help" , helpCommand),
213
213
historyCommand,
@@ -220,11 +220,12 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
220
220
cmd(" paste" , " [-raw] [path]" , " enter paste mode or paste a file" , pasteCommand),
221
221
nullary(" power" , " enable power user mode" , powerCmd),
222
222
nullary(" quit" , " exit the interpreter" , () => Result (keepRunning = false , None )),
223
- nullary(" replay" , " reset execution and replay all previous commands" , replay),
224
- nullary(" reset" , " reset the repl to its initial state, forgetting all session entries" , resetCommand),
223
+ cmd(" replay" , " [options]" , " reset the repl and replay all previous commands" , replayCommand),
224
+ // cmd("require", "<path>", "add a jar or directory to the classpath", require), // TODO
225
+ cmd(" reset" , " [options]" , " reset the repl to its initial state, forgetting all session entries" , resetCommand),
225
226
cmd(" save" , " <path>" , " save replayable session to a file" , saveCommand),
226
227
shCommand,
227
- cmd(" settings" , " [+|-] <options>" , " +enable/-disable flags, set compiler options " , changeSettings),
228
+ cmd(" settings" , " <options>" , " update compiler options, if possible; see reset " , changeSettings),
228
229
nullary(" silent" , " disable/enable automatic printing of results" , verbosity),
229
230
cmd(" type" , " [-v] <expr>" , " display the type of an expression without evaluating it" , typeCommand),
230
231
cmd(" kind" , " [-v] <expr>" , " display the kind of expression's type" , kindCommand),
@@ -304,57 +305,23 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
304
305
intp.lastWarnings foreach { case (pos, msg) => intp.reporter.warning(pos, msg) }
305
306
}
306
307
307
- private def changeSettings (args : String ): Result = {
308
- def showSettings () = {
309
- for (s <- settings.userSetSettings.toSeq.sorted) echo(s.toString)
310
- }
311
- def updateSettings () = {
312
- // put aside +flag options
313
- val (pluses, rest) = (args split " \\ s+" ).toList partition (_.startsWith(" +" ))
314
- val tmps = new Settings
315
- val (ok, leftover) = tmps.processArguments(rest, processAll = true )
316
- if (! ok) echo(" Bad settings request." )
317
- else if (leftover.nonEmpty) echo(" Unprocessed settings." )
318
- else {
319
- // boolean flags set-by-user on tmp copy should be off, not on
320
- val offs = tmps.userSetSettings filter (_.isInstanceOf [Settings # BooleanSetting ])
321
- val (minuses, nonbools) = rest partition (arg => offs exists (_ respondsTo arg))
322
- // update non-flags
323
- settings.processArguments(nonbools, processAll = true )
324
- // also snag multi-value options for clearing, e.g. -Ylog: and -language:
325
- for {
326
- s <- settings.userSetSettings
327
- if s.isInstanceOf [Settings # MultiStringSetting ] || s.isInstanceOf [Settings # PhasesSetting ]
328
- if nonbools exists (arg => arg.head == '-' && arg.last == ':' && (s respondsTo arg.init))
329
- } s match {
330
- case c : Clearable => c.clear()
331
- case _ =>
332
- }
333
- def update (bs : Seq [String ], name : String => String , setter : Settings # Setting => Unit ) = {
334
- for (b <- bs)
335
- settings.lookupSetting(name(b)) match {
336
- case Some (s) =>
337
- if (s.isInstanceOf [Settings # BooleanSetting ]) setter(s)
338
- else echo(s " Not a boolean flag: $b" )
339
- case _ =>
340
- echo(s " Not an option: $b" )
341
- }
342
- }
343
- update(minuses, identity, _.tryToSetFromPropertyValue(" false" )) // turn off
344
- update(pluses, " -" + _.drop(1 ), _.tryToSet(Nil )) // turn on
345
- }
346
- }
347
- if (args.isEmpty) showSettings() else updateSettings()
308
+ private def changeSettings (line : String ): Result = {
309
+ def showSettings () = for (s <- settings.userSetSettings.toSeq.sorted) echo(s.toString)
310
+ if (line.isEmpty) showSettings() else { updateSettings(line) ; () }
311
+ }
312
+ private def updateSettings (line : String ) = {
313
+ val (ok, rest) = settings.processArguments(words(line), processAll = false )
314
+ ok && rest.isEmpty
348
315
}
349
316
350
317
private def javapCommand (line : String ): Result = {
351
318
if (javap == null )
352
- " :javap unavailable, no tools.jar at %s . Set JDK_HOME." .format(jdkHome)
319
+ s " :javap unavailable, no tools.jar at $jdkHome . Set JDK_HOME. "
353
320
else if (line == " " )
354
321
" :javap [-lcsvp] [path1 path2 ...]"
355
322
else
356
323
javap(words(line)) foreach { res =>
357
- if (res.isError) return " Failed: " + res.value
324
+ if (res.isError) return s " Failed: ${ res.value} "
358
325
else res.show()
359
326
}
360
327
}
@@ -472,8 +439,16 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
472
439
}
473
440
474
441
/** create a new interpreter and replay the given commands */
475
- def replay () {
476
- reset()
442
+ def replayCommand (line : String ): Unit = {
443
+ def run (destructive : Boolean ): Unit = {
444
+ if (destructive) createInterpreter() else reset()
445
+ replay()
446
+ }
447
+ if (line.isEmpty) run(destructive = false )
448
+ else if (updateSettings(line)) run(destructive = true )
449
+ }
450
+ /** Announces as it replays. */
451
+ def replay (): Unit = {
477
452
if (replayCommandStack.isEmpty)
478
453
echo(" Nothing to replay." )
479
454
else for (cmd <- replayCommands) {
@@ -482,21 +457,28 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
482
457
echo(" " )
483
458
}
484
459
}
485
- def resetCommand () {
486
- echo(" Resetting interpreter state." )
487
- if (replayCommandStack.nonEmpty) {
488
- echo(" Forgetting this session history:\n " )
489
- replayCommands foreach echo
490
- echo(" " )
491
- replayCommandStack = Nil
460
+ /** `reset` the interpreter in an attempt to start fresh.
461
+ * Supplying settings creates a new compiler.
462
+ */
463
+ def resetCommand (line : String ): Unit = {
464
+ def run (destructive : Boolean ): Unit = {
465
+ echo(" Resetting interpreter state." )
466
+ if (replayCommandStack.nonEmpty) {
467
+ echo(" Forgetting this session history:\n " )
468
+ replayCommands foreach echo
469
+ echo(" " )
470
+ replayCommandStack = Nil
471
+ }
472
+ if (intp.namedDefinedTerms.nonEmpty)
473
+ echo(" Forgetting all expression results and named terms: " + intp.namedDefinedTerms.mkString(" , " ))
474
+ if (intp.definedTypes.nonEmpty)
475
+ echo(" Forgetting defined types: " + intp.definedTypes.mkString(" , " ))
476
+ if (destructive) createInterpreter() else reset()
492
477
}
493
- if (intp.namedDefinedTerms.nonEmpty)
494
- echo(" Forgetting all expression results and named terms: " + intp.namedDefinedTerms.mkString(" , " ))
495
- if (intp.definedTypes.nonEmpty)
496
- echo(" Forgetting defined types: " + intp.definedTypes.mkString(" , " ))
497
-
498
- reset()
478
+ if (line.isEmpty) run(destructive = false )
479
+ else if (updateSettings(line)) run(destructive = true )
499
480
}
481
+ /** Resets without announcements. */
500
482
def reset () {
501
483
intp.reset()
502
484
unleashAndSetPhase()
@@ -619,6 +601,7 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
619
601
else File (filename).printlnAll(replayCommands : _* )
620
602
)
621
603
604
+ @ deprecated(" Use reset, replay or require to update class path" , since = " 2.11" )
622
605
def addClasspath (arg : String ): Unit = {
623
606
val f = File (arg).normalize
624
607
if (f.exists) {
0 commit comments