Skip to content

Commit

Permalink
Use CodeWrapper from compiler-interface
Browse files Browse the repository at this point in the history
  • Loading branch information
alexarchambault committed Jan 14, 2021
1 parent b9ac9af commit f9fe98c
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ammonite.compiler

import ammonite.compiler.iface.CodeWrapper
import ammonite.util._
import ammonite.util.Util.{CodeSource, newLine, normalizeNewlines}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
package ammonite.compiler

import ammonite.compiler.iface.CodeWrapper
import ammonite.util._
import ammonite.util.Util.{CodeSource, normalizeNewlines}

trait CodeWrapper{
def wrapperPath: Seq[Name] = Nil
def apply(
code: String,
source: CodeSource,
imports: Imports,
printCode: String,
indexedWrapperName: Name,
extraCode: String
): (String, String, Int)
}
object CodeWrapper extends CodeWrapper{

object DefaultCodeWrapper extends CodeWrapper{
private val userCodeNestingLevel = 1
def apply(
code: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ammonite.compiler

import ammonite.compiler.iface.CodeWrapper
import ammonite.util._
import ammonite.util.Util.{CodeSource, newLine}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ammonite.compiler

import ammonite.compiler.iface.CodeWrapper
import ammonite.util._
import ammonite.util.Util.{CodeSource, newLine, normalizeNewlines, windowsPlatform}
import fastparse._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import java.io.{File, OutputStream, PrintStream}
import java.util.regex.Pattern

import ammonite.compiler._
import ammonite.compiler.iface.CodeWrapper
import ammonite.interp.api.{InterpAPI, InterpLoad, LoadJar}

import scala.collection.mutable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import java.util.concurrent.{CompletableFuture, Executors, ThreadFactory}
import java.util.UUID

import ammonite.compiler._
import ammonite.compiler.iface.CodeWrapper
import ammonite.interp.api.InterpAPI
import ammonite.interp.DependencyLoader
import ammonite.runtime.{ImportHook, Storage}
Expand All @@ -25,7 +26,7 @@ class AmmoniteBuildServer(
initialScripts: Seq[os.Path] = Nil,
initialImports: Imports = AmmoniteBuildServer.defaultImports,
defaultRepositories: Seq[Repository] = Repository.defaults().asScala.toList,
codeWrapper: CodeWrapper = CodeWrapper,
codeWrapper: CodeWrapper = DefaultCodeWrapper,
importHooks: Map[Seq[String], ImportHook] = ImportHook.defaults
) extends BuildServer with ScalaBuildServer with DummyBuildServerImplems {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package ammonite.interp.script

import java.util.concurrent.ConcurrentHashMap

import ammonite.compiler.{
CodeWrapper,
Compiler => AmmCompiler
}
import ammonite.compiler.{Compiler => AmmCompiler}
import ammonite.compiler.iface.CodeWrapper
import ammonite.runtime.Storage
import ammonite.util.{Imports, Printer}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package ammonite.interp.script

import java.io.File

import ammonite.compiler.{CodeWrapper, Parsers, Preprocessor}
import ammonite.compiler.{DefaultCodeWrapper, Parsers, Preprocessor}
import ammonite.compiler.iface.CodeWrapper
import ammonite.interp.{DependencyLoader, Interpreter}
import ammonite.runtime.{Frame, ImportHook, Storage}
import ammonite.util.{ImportTree, Name, Util}
Expand All @@ -16,7 +17,7 @@ final case class ScriptProcessor(
defaultRepositories: Seq[Repository],
extraPluginDependencies: Seq[Dependency] = Nil,
wd: os.Path = os.pwd,
codeWrapper: CodeWrapper = CodeWrapper,
codeWrapper: CodeWrapper = DefaultCodeWrapper,
importHooks: Map[Seq[String], ImportHook] = ImportHook.defaults
) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package ammonite.interp.script

import ammonite.compiler.{
CodeWrapper,
Compiler => AmmCompiler,
MakeReporter
}
import ammonite.compiler.iface.CodeWrapper
import ammonite.interp.Interpreter
import ammonite.runtime.{Frame, Storage}
import ammonite.util.{Classpath, Imports, Name, Printer, Res}
Expand Down
3 changes: 2 additions & 1 deletion amm/repl/src/main/scala/ammonite/repl/Repl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import ammonite.runtime._
import ammonite.terminal.Filter
import ammonite.util.Util.{newLine, normalizeNewlines}
import ammonite.util._
import ammonite.compiler.{CodeWrapper, Parsers, Preprocessor}
import ammonite.compiler.{Parsers, Preprocessor}
import ammonite.compiler.iface.CodeWrapper
import ammonite.interp.Interpreter
import coursierapi.Dependency

Expand Down
5 changes: 3 additions & 2 deletions amm/repl/src/test/scala/ammonite/TestRepl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package ammonite

import java.io.PrintStream

import ammonite.compiler.{CodeWrapper, Preprocessor}
import ammonite.compiler.{DefaultCodeWrapper, Preprocessor}
import ammonite.compiler.iface.CodeWrapper
import ammonite.interp.Interpreter
import ammonite.main.Defaults
import ammonite.repl._
Expand All @@ -24,7 +25,7 @@ import ammonite.runtime.ImportHook
class TestRepl {
var allOutput = ""
def predef: (String, Option[os.Path]) = ("", None)
def codeWrapper: CodeWrapper = CodeWrapper
def codeWrapper: CodeWrapper = DefaultCodeWrapper

val tempDir = os.Path(
java.nio.file.Files.createTempDirectory("ammonite-tester")
Expand Down
6 changes: 3 additions & 3 deletions amm/repl/src/test/scala/ammonite/TestUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package ammonite

import java.io.PrintStream

import ammonite.compiler.{CodeWrapper, Preprocessor}
import ammonite.compiler.{DefaultCodeWrapper, Preprocessor}
import ammonite.interp.Interpreter
import ammonite.main.Defaults
import ammonite.runtime.{Frame, Storage}
Expand Down Expand Up @@ -35,8 +35,8 @@ object TestUtils {
getFrame = () => startFrame,
createFrame = () => throw new Exception("unsupported"),
initialClassLoader = initialClassLoader,
replCodeWrapper = CodeWrapper,
scriptCodeWrapper = CodeWrapper,
replCodeWrapper = DefaultCodeWrapper,
scriptCodeWrapper = DefaultCodeWrapper,
alreadyLoadedDependencies = Defaults.alreadyLoadedDependencies("amm-test-dependencies.txt"),
importHooks = ImportHook.defaults,
classPathWhitelist = ammonite.repl.Repl.getClassPathWhitelist(thin = true)
Expand Down
9 changes: 5 additions & 4 deletions amm/src/main/scala/ammonite/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import java.io.{InputStream, OutputStream, PrintStream}
import java.net.URLClassLoader
import java.nio.file.NoSuchFileException

import ammonite.compiler.{CodeClassWrapper, CodeWrapper}
import ammonite.compiler.{CodeClassWrapper, DefaultCodeWrapper}
import ammonite.compiler.iface.CodeWrapper
import ammonite.interp.{Watchable, Interpreter, PredefInitialization}
import ammonite.interp.script.AmmoniteBuildServer
import ammonite.runtime.{Frame, Storage}
Expand Down Expand Up @@ -70,8 +71,8 @@ case class Main(predefCode: String = "",
verboseOutput: Boolean = true,
remoteLogging: Boolean = true,
colors: Colors = Colors.Default,
replCodeWrapper: CodeWrapper = CodeWrapper,
scriptCodeWrapper: CodeWrapper = CodeWrapper,
replCodeWrapper: CodeWrapper = DefaultCodeWrapper,
scriptCodeWrapper: CodeWrapper = DefaultCodeWrapper,
alreadyLoadedDependencies: Seq[Dependency] =
Defaults.alreadyLoadedDependencies(),
importHooks: Map[Seq[String], ImportHook] = ImportHook.defaults,
Expand Down Expand Up @@ -450,7 +451,7 @@ class MainRunner(cliConfig: Config,

val codeWrapper =
if (cliConfig.repl.classBased.value) CodeClassWrapper
else CodeWrapper
else DefaultCodeWrapper

Main(
cliConfig.predef.predefCode,
Expand Down
2 changes: 1 addition & 1 deletion amm/src/main/scala/ammonite/main/Scripts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ object Scripts {
}

scriptMains = interp.scriptCodeWrapper match{
case ammonite.compiler.CodeWrapper =>
case ammonite.compiler.DefaultCodeWrapper =>
Some(
interp
.evalClassloader
Expand Down
2 changes: 1 addition & 1 deletion build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ object amm extends Cross[MainModule](fullCrossScalaVersions:_*){
}
}
class CompilerModule(val crossScalaVersion: String) extends AmmModule{
def moduleDeps = Seq(amm.util(), amm.repl.api())
def moduleDeps = Seq(amm.compiler.interface(), amm.util(), amm.repl.api())
def crossFullScalaVersion = true
def ivyDeps = T {
Agg(
Expand Down

0 comments on commit f9fe98c

Please sign in to comment.