aboutsummaryrefslogtreecommitdiff
path: root/repl
diff options
context:
space:
mode:
authorPrashant Sharma <prashant.s@imaginea.com>2013-04-10 15:08:01 +0530
committerPrashant Sharma <prashant.s@imaginea.com>2013-04-10 15:08:01 +0530
commitf31e41c2709368d1275f23be79231fbc0eb54f57 (patch)
treeefd5daa9b3d092f00b38a9d40c2c29275489197c /repl
parentb67c638b856fcf382777c4af09b48fc538a65e89 (diff)
downloadspark-f31e41c2709368d1275f23be79231fbc0eb54f57.tar.gz
spark-f31e41c2709368d1275f23be79231fbc0eb54f57.tar.bz2
spark-f31e41c2709368d1275f23be79231fbc0eb54f57.zip
Added class wrappers instead of object and incorporated most of matei comments
Diffstat (limited to 'repl')
-rw-r--r--repl/src/main/scala/spark/repl/SparkIMain.scala36
-rw-r--r--repl/src/main/scala/spark/repl/SparkImports.scala23
2 files changed, 39 insertions, 20 deletions
diff --git a/repl/src/main/scala/spark/repl/SparkIMain.scala b/repl/src/main/scala/spark/repl/SparkIMain.scala
index 8453628233..9894429ec1 100644
--- a/repl/src/main/scala/spark/repl/SparkIMain.scala
+++ b/repl/src/main/scala/spark/repl/SparkIMain.scala
@@ -806,10 +806,10 @@ import spark.Logging
* following accessPath into the outer one.
*/
def resolvePathToSymbol(accessPath: String): Symbol = {
- val readRoot = getRequiredModule(readPath) // the outermost wrapper
+ // val readRoot = getRequiredModule(readPath) // the outermost wrapper
// MATEI: Changed this to getClass because the root object is no longer a module (Scala singleton object)
- // PRASHANT: Root object is still an object and experimentations are on.
- //val readRoot = definitions.getClass(newTypeName(readPath)) // the outermost wrapper
+
+ val readRoot = definitions.getClass(newTypeName(readPath)) // the outermost wrapper
(accessPath split '.').foldLeft(readRoot: Symbol) {
case (sym, "") => sym
case (sym, name) => afterTyper(termMember(sym, name))
@@ -887,15 +887,17 @@ import spark.Logging
importsCode(referencedNames.toSet)
/** Code to access a variable with the specified name */
- def fullPath(vname: String) = (
- lineRep.readPath + accessPath + ".`%s`".format(vname)
- )
+ def fullPath(vname: String) = {
+ // lineRep.readPath + accessPath + ".`%s`".format(vname)
+ lineRep.readPath + ".INSTANCE" + accessPath + ".`%s`".format(vname)
+ }
/** Same as fullpath, but after it has been flattened, so:
* $line5.$iw.$iw.$iw.Bippy // fullPath
* $line5.$iw$$iw$$iw$Bippy // fullFlatName
*/
def fullFlatName(name: String) =
- lineRep.readPath + accessPath.replace('.', '$') + nme.NAME_JOIN_STRING + name
+ // lineRep.readPath + accessPath.replace('.', '$') + nme.NAME_JOIN_STRING + name
+ lineRep.readPath + ".INSTANCE" + accessPath.replace('.', '$') + nme.NAME_JOIN_STRING + name
/** The unmangled symbol name, but supplemented with line info. */
def disambiguated(name: Name): String = name + " (in " + lineRep + ")"
@@ -922,24 +924,25 @@ import spark.Logging
"def $trees = if ($req eq null) Nil else $req.trees".format(lineRep.readName, path, reqId)
)
}
- //TODO:FIXME, serialized
- /*
+
val preamble = """
|class %s extends Serializable {
- | %s%s
- """.stripMargin.format(lineRep.readName, importsPreamble, indentCode(toCompute))
+ | %s%s%s
+ """.stripMargin.format(lineRep.readName, envLines.map(" " + _ + ";\n").mkString, importsPreamble, indentCode(toCompute))
val postamble = importsTrailer + "\n}" + "\n" +
"object " + lineRep.readName + " {\n" +
" val INSTANCE = new " + lineRep.readName + "();\n" +
"}\n"
val generate = (m: MemberHandler) => m extraCodeToEvaluate Request.this
- */
+
+ /*
val preamble = """
|object %s extends Serializable {
|%s%s%s
""".stripMargin.format(lineRep.readName, envLines.map(" " + _ + ";\n").mkString, importsPreamble, indentCode(toCompute))
val postamble = importsTrailer + "\n}"
val generate = (m: MemberHandler) => m extraCodeToEvaluate Request.this
+ */
}
@@ -965,9 +968,8 @@ import spark.Logging
| (""
""".stripMargin.format(
lineRep.evalName, evalResult, lineRep.printName,
- executionWrapper, lineRep.readName + accessPath
+ executionWrapper, lineRep.readName + ".INSTANCE" + accessPath
)
-
val postamble = """
| )
| }
@@ -1246,8 +1248,10 @@ object SparkIMain {
// $line3.$read.$iw.$iw.Bippy =
// $line3.$read$$iw$$iw$Bippy@4a6a00ca
private def removeLineWrapper(s: String) = s.replaceAll("""\$line\d+[./]\$(read|eval|print)[$.]""", "")
- private def removeIWPackages(s: String) = s.replaceAll("""\$(iw|read|eval|print)[$.]""", "")
- def stripString(s: String) = removeIWPackages(removeLineWrapper(s))
+ private def removeIWPackages(s: String) = s.replaceAll("""\$(iw|iwC|read|eval|print)[$.]""", "")
+ private def removeSparkVals(s: String) = s.replaceAll("""\$VAL[0-9]+[$.]""", "")
+
+ def stripString(s: String) = removeSparkVals(removeIWPackages(removeLineWrapper(s)))
trait CodeAssembler[T] {
def preamble: String
diff --git a/repl/src/main/scala/spark/repl/SparkImports.scala b/repl/src/main/scala/spark/repl/SparkImports.scala
index ea79eba381..20345aa9ee 100644
--- a/repl/src/main/scala/spark/repl/SparkImports.scala
+++ b/repl/src/main/scala/spark/repl/SparkImports.scala
@@ -147,11 +147,16 @@ trait SparkImports {
// add code for a new object to hold some imports
def addWrapper() {
val impname = nme.INTERPRETER_IMPORT_WRAPPER
- code append "object %s {\n".format(impname)
- trailingBraces append "}\n"
+ code append "class %sC extends Serializable {\n".format(impname)
+ trailingBraces append "}\nval " + impname + " = new " + impname + "C;\n"
accessPath append ("." + impname)
currentImps.clear
+ // code append "object %s {\n".format(impname)
+ // trailingBraces append "}\n"
+ // accessPath append ("." + impname)
+
+ // currentImps.clear
}
addWrapper()
@@ -179,8 +184,11 @@ trait SparkImports {
case x =>
for (imv <- x.definedNames) {
if (currentImps contains imv) addWrapper()
-
- code append ("import " + (req fullPath imv) + "\n")
+ val objName = req.lineRep.readPath
+ val valName = "$VAL" + newValId();
+ code.append("val " + valName + " = " + objName + ".INSTANCE;\n")
+ code.append("import " + valName + req.accessPath + ".`" + imv + "`;\n")
+ // code append ("import " + (req fullPath imv) + "\n")
currentImps += imv
}
}
@@ -196,4 +204,11 @@ trait SparkImports {
private def membersAtPickler(sym: Symbol): List[Symbol] =
beforePickler(sym.info.nonPrivateMembers.toList)
+
+ private var curValId = 0
+
+ private def newValId(): Int = {
+ curValId += 1
+ curValId
+ }
}