Skip to content

Commit

Permalink
1.9.9
Browse files Browse the repository at this point in the history
reshuffle code to make classloading tests pass
  • Loading branch information
lihaoyi committed Dec 26, 2019
1 parent 8d77031 commit 36b41da
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 33 deletions.
27 changes: 3 additions & 24 deletions amm/interp/src/main/scala/ammonite/interp/Interpreter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -183,28 +183,7 @@ class Interpreter(val printer: Printer,
} yield hookResults
}

def parseImportHooks(source: CodeSource, stmts: Seq[String]) = synchronized{
val hookedStmts = mutable.Buffer.empty[String]
val importTrees = mutable.Buffer.empty[ImportTree]
for(stmt <- stmts) {
parse(stmt, Parsers.ImportSplitter(_)) match{
case f: Parsed.Failure => hookedStmts.append(stmt)
case Parsed.Success(parsedTrees, _) =>
var currentStmt = stmt
for(importTree <- parsedTrees){
if (importTree.prefix(0)(0) == '$') {
val length = importTree.end - importTree.start
currentStmt = currentStmt.patch(
importTree.start, (importTree.prefix(0) + ".$").padTo(length, ' '), length
)
importTrees.append(importTree)
}
}
hookedStmts.append(currentStmt)
}
}
(hookedStmts.toSeq, importTrees.toSeq)
}


def resolveImportHooks(importTrees: Seq[ImportTree],
hookedStmts: Seq[String],
Expand Down Expand Up @@ -238,7 +217,7 @@ class Interpreter(val printer: Printer,
Seq(Name("ammonite"), Name("$sess")),
Some(wd/"(console)")
)
val (hookStmts, importTrees) = parseImportHooks(codeSource, stmts)
val (hookStmts, importTrees) = Parsers.parseImportHooks(codeSource, stmts)

for{
_ <- Catching { case ex => Res.Exception(ex, "") }
Expand Down Expand Up @@ -565,7 +544,7 @@ class Interpreter(val printer: Printer,
for{
allSplittedChunks <- splittedScript
(leadingSpaces, stmts) = allSplittedChunks(wrapperIndex - 1)
(hookStmts, importTrees) = parseImportHooks(codeSource, stmts)
(hookStmts, importTrees) = Parsers.parseImportHooks(codeSource, stmts)
hookInfo <- resolveImportHooks(
importTrees, hookStmts, codeSource, scriptCodeWrapper.wrapperPath
)
Expand Down
30 changes: 30 additions & 0 deletions amm/interp/src/main/scala/ammonite/interp/Parsers.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package ammonite.interp

import ammonite.util.ImportTree
import ammonite.util.Util.CodeSource

import scala.collection.mutable

object Parsers {

import fastparse._
Expand Down Expand Up @@ -103,4 +108,29 @@ object Parsers {
case f: Parsed.Failure => stringWrap(s)
}
}
def parseImportHooks(source: CodeSource, stmts: Seq[String]) = synchronized{
val hookedStmts = mutable.Buffer.empty[String]
val importTrees = mutable.Buffer.empty[ImportTree]
for(stmt <- stmts) {
// Call `fastparse.ParserInput.fromString` explicitly, to avoid generating a
// lambda in the class body and making the we-do-not-load-fastparse-on-cached-scripts
// test fail
parse(fastparse.ParserInput.fromString(stmt), Parsers.ImportSplitter(_)) match{
case f: Parsed.Failure => hookedStmts.append(stmt)
case Parsed.Success(parsedTrees, _) =>
var currentStmt = stmt
for(importTree <- parsedTrees){
if (importTree.prefix(0)(0) == '$') {
val length = importTree.end - importTree.start
currentStmt = currentStmt.patch(
importTree.start, (importTree.prefix(0) + ".$").padTo(length, ' '), length
)
importTrees.append(importTree)
}
}
hookedStmts.append(currentStmt)
}
}
(hookedStmts.toSeq, importTrees.toSeq)
}
}
6 changes: 3 additions & 3 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ object amm extends Cross[MainModule](fullCrossScalaVersions:_*){
def moduleDeps = Seq(ops(), amm.util(), interp.api(), amm.repl.api())
def crossFullScalaVersion = true
def ivyDeps = Agg(
ivy"com.lihaoyi::upickle:0.9.3",
ivy"com.lihaoyi::upickle:0.9.5",
ivy"com.lihaoyi::requests:0.4.6"
)
}
Expand All @@ -193,7 +193,7 @@ object amm extends Cross[MainModule](fullCrossScalaVersions:_*){
def ivyDeps = Agg(
ivy"org.scala-lang:scala-compiler:$crossScalaVersion",
ivy"org.scala-lang:scala-reflect:$crossScalaVersion",
ivy"com.lihaoyi::scalaparse:2.2.0",
ivy"com.lihaoyi::scalaparse:2.2.2",
ivy"org.javassist:javassist:3.21.0-GA",
ivy"org.scala-lang.modules::scala-xml:1.2.0"
)
Expand Down Expand Up @@ -418,7 +418,7 @@ class IntegrationModule(val crossScalaVersion: String) extends AmmInternalModule
object test extends Tests {
def forkEnv = super.forkEnv() ++ Seq(
"AMMONITE_SHELL" -> shell().jar().path.toString,
"AMMONITE_ASSEMBLY" -> amm().assembly().path.toString
"AMMONITE_ASSEMBLY" -> amm().launcher().path.toString
)
}
}
Expand Down
9 changes: 3 additions & 6 deletions readme/Footer.scalatex
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,11 @@


@sect{Changelog}
@sect{1.9.8}
@sect{1.9.9}
@ul
@li
Bump PPrint to 0.5.7
@sect{1.9.2}
@ul
@li
Bump FastParse to 2.2.0
Bump PPrint to 0.5.7, FastParse to 2.2.2, uPickle to 0.9.6

@sect{1.9.1}
@ul
@li
Expand Down

0 comments on commit 36b41da

Please sign in to comment.