From d6c3530b20db610894dc7fdbb8fd184165744a3f Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Wed, 18 Nov 2020 15:45:03 +0100 Subject: [PATCH] Get rid of Res in CompilerLifecycleManager A simple Option is enough, and that makes for a cleaner interface for CompilerLifecycleManager later on. --- .../interp/CompilerLifecycleManager.scala | 27 ++++++++----------- .../scala/ammonite/interp/Interpreter.scala | 18 ++++++++----- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/amm/interp/src/main/scala/ammonite/interp/CompilerLifecycleManager.scala b/amm/interp/src/main/scala/ammonite/interp/CompilerLifecycleManager.scala index cbd886691..9983bdaa3 100644 --- a/amm/interp/src/main/scala/ammonite/interp/CompilerLifecycleManager.scala +++ b/amm/interp/src/main/scala/ammonite/interp/CompilerLifecycleManager.scala @@ -2,7 +2,7 @@ package ammonite.interp import ammonite.runtime._ import ammonite.util.Util._ -import ammonite.util._ +import ammonite.util.Printer import java.nio.file.Path @@ -125,7 +125,7 @@ class CompilerLifecycleManager( def compileClass(processed: Preprocessor.Output, printer: Printer, - fileName: String): Res[Compiler.Output] = synchronized{ + fileName: String): Option[Compiler.Output] = synchronized{ // Enforce the invariant that every piece of code Ammonite ever compiles, // gets run within the `ammonite` package. It's further namespaced into // things like `ammonite.$file` or `ammonite.$sess`, but it has to be @@ -133,20 +133,15 @@ class CompilerLifecycleManager( assert(processed.code.trim.startsWith("package ammonite")) init() - for { - compiled <- Res.Success{ - compiler.compile( - processed.code.getBytes(scala.util.Properties.sourceEncoding), - printer, - processed.prefixCharLength, - processed.userCodeNestingLevel, - fileName - ) - } - _ = Internal.compilationCount += 1 - output <- Res(compiled, "Compilation Failed") - } yield output - + val compiled = compiler.compile( + processed.code.getBytes(scala.util.Properties.sourceEncoding), + printer, + processed.prefixCharLength, + processed.userCodeNestingLevel, + fileName + ) + Internal.compilationCount += 1 + compiled } def configureCompiler(callback: scala.tools.nsc.Global => Unit) = synchronized{ diff --git a/amm/interp/src/main/scala/ammonite/interp/Interpreter.scala b/amm/interp/src/main/scala/ammonite/interp/Interpreter.scala index 5297563ec..bcf368063 100644 --- a/amm/interp/src/main/scala/ammonite/interp/Interpreter.scala +++ b/amm/interp/src/main/scala/ammonite/interp/Interpreter.scala @@ -277,10 +277,13 @@ class Interpreter(val printer: Printer, incrementLine: () => Unit): Res[(Evaluated, Tag)] = synchronized{ for{ _ <- Catching{ case e: ThreadDeath => Evaluator.interrupted(e) } - output <- compilerManager.compileClass( - processed, - printer, - fileName + output <- Res( + compilerManager.compileClass( + processed, + printer, + fileName + ), + "Compilation Failed" ) _ = incrementLine() res <- eval.processLine( @@ -313,8 +316,11 @@ class Interpreter(val printer: Printer, for { _ <- Catching{case e: Throwable => e.printStackTrace(); throw e} - output <- compilerManager.compileClass( - processed, printer, codeSource.fileName + output <- Res( + compilerManager.compileClass( + processed, printer, codeSource.fileName + ), + "Compilation Failed" ) cls <- eval.loadClass(fullyQualifiedName, output.classFiles)